我需要调试包含forall
块的程序。它们内部是pure
子程序或函数。为了暂时禁用pure
谓词,我使用C预编译器,如下面的问题所示:
Gfortran: Treat pure functions as normal functions for debugging purposes?
现在的问题是,如果forall
块内的子例程或函数不是pure
,我会收到错误编译。是否有可能处理这些错误
Error: Reference to non-PURE function 'pvkp' at (1) inside a FORALL block
仅作为警告或可能很容易使用C预编译器进行转换
forall (i=1:n)
...
end forall
到
do i=1,n
...
end do
感谢任何想法!
答案 0 :(得分:2)
一种简化是使用do concurrent
循环而不是forall
块。这减少了代码中所需的链接更改次数:只需更改循环规范,而不是将end forall
更改为end do
。
一种不引以为豪的方法,使用cpp
,并且只适用于简单的情况:
#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
上面确实有明显的扩展使用forall
构造(结尾有额外的#define
),如果这真的是你想要的。或者,尽管使用诸如
#ifdef DEBUG
do i=1,n
#else
forall (i=1:n)
#endif
...
#ifdef DEBUG
end do
#else
end forall
#end
这太可怕了,但我想这对于所有预处理器方法都是如此。它确实允许更复杂的掩模,并且更加本地化。