forrtl:严重(151):可分配数组已分配- [英] forrtl: severe (151): allocatable array is already allocated-

查看:568
本文介绍了forrtl:严重(151):可分配数组已分配-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/var/spool/torque/mom_priv/jobs/775.head.cluster.SC: line 22: 28084 Segmentation fault      ./a.out


我是Fortran的新手,这是我第一次使用HPC和OpenMP. 在我的代码中,我有一个应该并行的循环.我使用了一些动态变量,它们在并行循环中都是虚拟的.


I am new in Fortran and this is the first time I work with HPC and OpenMP. In my code, I have a loop that should be parallel. I use some dynamic variables that all of them are dummy in the parallel loop.

我在并行循环中分配动态变量

I allocate the dynamic variables in parallel loop

  !$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

我省略了一些不相关的代码部分.执行程序时,会发生此错误:

I omited some irrelevant part of code. When the program is executed, this error occurs:

forrtl: severe (151): allocatable array is already allocated

我在并行区域之外分配了变量,它适用于较小的数据,但对于较大的数据,会发生此错误:

I allocated the variables outside the parallel region, it works for small data, but for large data this error occurs:

/var/spool/torque/mom_priv/jobs/775.head.cluster.SC: line 22: 28084 Segmentation fault      ./a.out

我将PRIVATE子句用于动态变量(虚拟变量):

I used PRIVATE clause for dynamic variables (dummy variables):

!$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)

并在并行循环内分配了变量,但存在相同的错误, 最后,我将代码更改为:

and allocated variables inside parallel loop, but the same error, at last I changed the code to:

  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个(线程数)循环,但无法完成循环,再次出现此错误:

it fails at run-time. it starts N (number of thread) loops, but can not complete them, and again this error:

    /var/spool/torque/mom_priv/jobs/775.head.cluster.SC: line 22: 28084 Segmentation fault      ./a.out

有什么主意吗?

推荐答案

我更改了代码,终于成功了! 指令!$OMP PARALLEL DO是两个指令!$OMP PARALLEL!$OMP DO的快捷方式.我使用了这两个指令(而不是!$OMP PARALLEL DO)并将分配放在并行区域内.我猜(但是我不确定),现在编译器知道如何获取私有变量的内存,因为我在分配之前将private子句放在了前面,所以不会出现segmentation fault的情况.

I changed the code and finally it WORKS! The directive !$OMP PARALLEL DO is the shortcut of two directives !$OMP PARALLEL and !$OMP DO. I used these two directives (instead of !$OMP PARALLEL DO) and put allocation inside parallel region. I guess (but I'm not sure), now the compiler knows how to get memories for private variables, because I put private clause before allocation and so the segmentation fault dose not occur.

!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(iconf,d,randx,                   &
!$OMP& randy,randz,unit_cg,theta1,theta2,theta3,fr1,fr2,fr3,Q,          &
!$OMP& plproduct_avg) 

      allocate(randx(num),randy(num),randz(num),unit_cg(num),           &
     &         fr1(num),fr2(num),fr3(num),theta1(order,num),            &
     &         theta2(order,num),theta3(order,num),                     &
     &         Q(nfftdim1,nfftdim2,nfftdim3))

!$OMP DO 
  do 250 iconf = 1,config
... call some subroutines and do calculations ...
  250   continue
!$OMP END DO

  deallocate(randx,randy,randz,unit_cg,fr1,fr2,fr3,theta1,theta2,   &
 &           theta3,Q)

!$OMP END PARALLEL

这篇关于forrtl:严重(151):可分配数组已分配-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆