Peano
Utilities
  • peano4_utils_Loop_parallel

Loop macros

d-dimensional loops

I wrote Peano to support arbitrary spatial dimensions. By default, I build only 2d and 3d versions of the code/core, but in principle you can write also simulations over 4d or 5d domains, e.g. The choice of a particular dimension d is done at compile time via the flag -DDimension=d. As everything is generic w.r.t. dimensions, I have many places in the code where I need d-dimensional loops.

Peano's utility directory/namespace peano4::utils offers a header Loop which comprises a set of macros that support d-dimensional loops. Details can be found in the source code documentatation within the file or online, but the collection of macros allows you to write code alike

dfor(k,20) { // d-dimensional loop over 20x20x20x... patch
// There is now a d-dimensional vector k over integers which holds the
// loop index. So we can write for example
const tarch::la::Vector<DIMENSIONS,double> somePosition =
offset + k.convertScalar<double>() * h;
[...]
}
offset
Definition: euler.py:45
h
Definition: swe.py:79

There are also macros for loops skipping one dimension, or macros for particular iteration ranges (2,3,4) which are highly optimised through lookup tables. Finally, Loop hosts z-loops, i.e. loops which meander forth and back through an array similar to the Peano curve.

To use the d-dimensional loops, you have to include

      #include "peano4/utils/Loop.h"

For Cartesian meshes, arrays, the file also offers a routine peano4::utils::dLinearised() which converts the d-dimensional loop counter into one integer. Again, I do offer variants of this routine which are optimised to particular choices of d or array ranges.

d-dimensional exclusive loops

There's a variation of the d-dimensional loops which loops over all dimensions except one. I name this loop type dfore. Its usage is straightforward: You again specify a counter name and you pass in the loop range. Let k be the counter name and N the range. You furthermore specify a dimension and you fix the value for this dimension.

The loop will run over a N $\times$ N $\times$ 1 $\times$N range with the 1 being in the specified direction. The loop counter is a vector over integer named k. Its entry along the 1-dimension is fixed to the default value specified in the macro.