使用编译器注释可检查自动作用域结果,并确定是否因自动作用域失败而对并行区域进行了序列化。
使用 -g 调试选项编译时,编译器将生成行内注释。可以使用 er_src 命令查看这个生成的注释,如下所示。(er_src 命令作为 Solaris Studio 软件的一部分提供;有关更多信息,请参见 er_src(1) 手册页或《Solaris Studio 性能分析器》手册)。
使用 -xvpara 选项进行编译是一个良好的开端。使用 -xvpara 进行编译可大体确定针对特定构造的自动作用域是否成功。以下是一个示例:
示例 6-1 使用 -vpara 自动确定作用域
%cat source1.f
INTEGER X(100), Y(100), I, T
C$OMP PARALLEL DO DEFAULT(__AUTO)
DO I=1, 100
T = Y(I)
X(I) = T*T
END DO
C$OMP END PARALLEL DO
END
%f95 -xopenmp -xO3 -vpara -c -g source1.f
"source1.f", line 2: Autoscoping for OpenMP construct succeeded.
Check er_src for details
如果针对特定构造的自动作用域失败,将发出本示例中所示的警告消息(使用 -xvpara):
示例 6-2 使用 -vpara 自动确定作用域失败
%cat source2.f
INTEGER X(100), Y(100), I, T
C$OMP PARALLEL DO DEFAULT(__AUTO)
DO I=1, 100
T = Y(I)
CALL FOO(X)
X(I) = T*T
END DO
C$OMP END PARALLEL DO
END
%f95 -xopenmp -xO3 -vpara -c -g source2.f
"source2.f", line 2: Warning: Autoscoping for OpenMP construct failed.
Check er-src for details. Parallel region will be executed by
a single thread.
er_src 所显示的编译器注释中显示了更详细的信息:
% er_src source2.o
Source file: source2.f
Object file: source2.o
Load Object: source2.o
1. INTEGER X(100), Y(100), I, T
Source OpenMP region below has tag R1
Variables autoscoped as SHARED in R1: y
Variables autoscoped as PRIVATE in R1: t, i
Variables treated as shared because they cannot be autoscoped in R1: x
R1 will be executed by a single thread because autoscoping for some variable s was not successful
Private variables in R1: i, t
Shared variables in R1: y, x
2. C$OMP PARALLEL DO DEFAULT(__AUTO)
Source loop below has tag L1
L1 parallelized by explicit user directive
L1 autoparallelized
L1 parallel loop-body code placed in function _$d1A2.MAIN_ along with 0 inne r loops
L1 could not be pipelined because it contains calls
3. DO I=1, 100
4. T = Y(I)
5. CALL FOO(X)
6. X(I) = T*T
7. END DO
8. C$OMP END PARALLEL DO
9. END
10.