/var/spool/torque/mom_priv/jobs/775.head.cluster.SC: line 22: 28084 Segmentation fault ./a.out
我是Fortran的新手,这是我第一次使用HPC和OpenMP。 在我的代码中,我有一个应该是并行的循环。我使用了一些动态变量,它们在并行循环中都是虚拟的。
我在并行循环中分配动态变量
!$OMP PARALLEL DO
do 250 iconf = 1,config
allocate(randx(num),randy(num),randz(num),unit_cg(num), &
& x(nfftdim1),y(nfftdim2),z(nfftdim3),fr1(num), &
& fr2(num),fr3(num),theta1(order,num), &
& theta2(order,num),theta3(order,num), &
& Q(nfftdim1,nfftdim2,nfftdim3))
... call some subroutines and do calculations ...
deallocate(randx,randy,randz,unit_cg,fr1,fr2,fr3,theta1,theta2, &
& theta3,x,y,z,Q)
250 continue
!$OMP END PARALLEL DO
我省略了一些不相关的代码部分。执行程序时,会发生此错误:
forrtl: severe (151): allocatable array is already allocated
我将变量分配到并行区域之外,它适用于小数据,但对于大数据,会发生此错误:
/var/spool/torque/mom_priv/jobs/775.head.cluster.SC: line 22: 28084 Segmentation fault ./a.out
我将PRIVATE子句用于动态变量(虚拟变量):
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(randx,randy,randz, &
!$OMP& unit_cg,fr1,fr2,fr3,theta1,theta2,theta3,x,y,z,Q, &
!$OMP& dir_ene,rec_ene,corr_ene,energy_final,plproduct_avg, &
!$OMP& correlation_term)
并在并行循环内分配变量,但是同样的错误, 最后我将代码更改为:
allocate(randx(num),randy(num),randz(num),unit_cg(num), &
& x(nfftdim1),y(nfftdim2),z(nfftdim3),fr1(num), &
& fr2(num),fr3(num),theta1(order,num), &
& theta2(order,num),theta3(order,num), &
& Q(nfftdim1,nfftdim2,nfftdim3))
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(randx,randy,randz, &
!$OMP& unit_cg,fr1,fr2,fr3,theta1,theta2,theta3,x,y,z,Q, &
!$OMP& dir_ene,rec_ene,corr_ene,energy_final,plproduct_avg, &
!$OMP& correlation_term)
do 250 iconf = 1,config
... call some subroutines and do calculations ...
250 continue
!$OMP END PARALLEL DO
deallocate(randx,randy,randz,unit_cg,fr1,fr2,fr3,theta1,theta2, &
& theta3,x,y,z,Q)
它在运行时失败。它启动N(线程数)循环,但无法完成它们,并再次出现此错误:
/var/spool/torque/mom_priv/jobs/775.head.cluster.SC: line 22: 28084 Segmentation fault ./a.out
任何想法?
答案 0 :(得分:2)
我改变了代码,最后它工作了!
指令isSwiping
是两个指令false
和!$OMP PARALLEL DO
的快捷方式。我使用了这两个指令(而不是!$OMP PARALLEL
)并将分配放在并行区域内。我猜(但我不确定),现在编译器知道如何获取私有变量的内存,因为我在分配之前放置了私有子句,因此不会发生!$OMP DO
。
!$OMP PARALLEL DO