Question

I need to debug a program that includes forall blocks. Inside of them are pure subroutines or functions. In order to temporarily disable the pure predicate I use the C precompiler as in the following question posed by me:

Gfortran: Treat pure functions as normal functions for debugging purposes?

The problem now is, that if the subroutines or functions inside the forall block are not pure I get an error compiling. Is there a possibility to treat these errors

Error: Reference to non-PURE function 'pvkp' at (1) inside a FORALL block

only as warnings or is there maybe an easy possibility to use the C precompiler for turning

forall (i=1:n)
   ...
end forall

into

do i=1,n
   ...
end do 

Any ideas are appreciated!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top