One simplification is to use a do concurrent
loop instead of a forall
block. This reduces the number of linked changes required in the code: one need only change the loop specification, not change an end forall
to an end do
.
An approach not to be proud of, using cpp
, and suitable for only simple cases:
#ifdef DEBUG
#define conloop(var, lower, upper) do var=lower, upper
#else
#define conloop(var, lower, upper) do concurrent (var=lower:upper)
#endif
conloop(i,1,n) ! Either a DO or DO CONCURRENT depending on DEBUG
...
end do
end
The above does have the obvious extension to using a forall
construct (with the extra #define
for the ending) if that is really what you want. Alternatively, although more tedious to produce, using such things as
#ifdef DEBUG
do i=1,n
#else
forall (i=1:n)
#endif
...
#ifdef DEBUG
end do
#else
end forall
#end
This is horrible, but I imagine that's true for all pre-processor approaches. It does allow more complicated masks and is more localized.