openmp中动态分配问题
module sx_typetype Mdata
integer :: nx(3)
real,allocatable :: sx(:)
end type
contains
subroutine deall(tmp)
type(Mdata) :: tmp
if(allocated(tmp%sx)) deallocate(tmp%sx)
end subroutine deall
end module
!----------------program-----------
program testopenmp
use sx_type
use omp_lib
implicit none
integer ix,iz
type(Mdata) :: test
call omp_set_num_threads(2)
test%nx(1)=4
test%nx(2)=5
test%nx(3)=6
!$omp parallel do private(test,ix,iz)
do ix=1,3
allocate(test%sx(test%nx(ix))) ! allocate test->sx on threads
test%sx=2.0
do iz=1,4
test%sx(iz)=iz+omp_get_thread_num()
print *,'thread ',omp_get_thread_num(),'sx=',test%sx(iz)
end do
call deall(test) !deallocate test
end do
!$omp end parallel do
end program我希望在openmp中进行数组分配,在一个程序中遇到这个问题,因为源程序就是采用这样的分配方式,编译没错,但是运行时出现错误:forrtl: severe (151): allocatable array is already allocated, 请问一下这是什么原因??谢谢!!!
改成
!$omp parallel do private(test,iz)
试试
本帖最后由 1014511134 于 2018-7-31 19:56 编辑
kyra 发表于 2018-7-31 17:17
改成
!$omp parallel do private(test,iz)
试试测试了还是不行,按理说省去ix,循环变量openmp默认的是private的。 64-bit Win7 OS下MSYS2 + Gfortran 7.3.0
测试一切正常 1014511134 发表于 2018-7-31 19:46
测试了还是不行,按理说省去ix,循环变量openmp默认的是private的。
用的什么操作系统和编译器? kyra 发表于 2018-8-1 07:52
用的什么操作系统和编译器?
centos6.9 Linux 工作站 ivf 2013 pasuka 发表于 2018-7-31 21:38
64-bit Win7 OS下MSYS2 + Gfortran 7.3.0
测试一切正常
难道是编译器的问题?我再测试测试!谢谢! 1014511134 发表于 2018-8-1 12:08
centos6.9 Linux 工作站 ivf 2013
没用过ifort for linux
在ivf for windows 和 gfortran/linux 上试过没问题。 kyra 发表于 2018-8-1 13:41
没用过ifort for linux
在ivf for windows 和 gfortran/linux 上试过没问题。
好的,非常谢谢!!
页:
[1]