[Fortran] 纯文本查看 复制代码
module sx_type
type 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, 请问一下这是什么原因??谢谢!!!