与 OpenMP 一起分配数组作为派生数据类型的一部分
Allocation of an array as part of an derived data type in conjunction with OpenMP
在下面的示例中,我在并行块内部和外部分配了一个数组(作为派生数据类型的一部分)。由于使用了这个数组private
,两种方式都应该根据 OpenMP 3.0 规范工作(我使用 gcc-4.6.3 编译)
在当前变体中,allocate
应该是线程安全的。但是在运行时我得到了保留一个已经保留的变量的错误。
module Example_mod
contains
subroutine unter(n1,n2)
implicit none
type daten
real, allocatable, dimension(:,:)::x
integer::n1,n2
end type daten
integer, intent (in)::n1,n2
integer l
real,dimension(4)::ausgabe
type(daten)::xs
! initializing xs:
! xs%n1 = n1
! xs%n2 = n2
! allocate(xs%x(n1,n2))
! xs%x = 1.1
!$omp parallel private(xs)
xs%n1 = n1
xs%n2 = n2
allocate(xs%x(n1,n2))
xs%x = 1.1
!$OMP DO
do l = 1, 4
xs%x = l**2
ausgabe(l) = sum(xs%x)
enddo
!$omp end DO
deallocate(xs%x)
!$OMP end parallel
! deallocate(xs%x)
write(*,*) ausgabe
end subroutine unter
end module Example_mod
program main
use Example_mod
call unter(10,12)
end program main
在另一个变体中(取消注释 ! initializing xs:
之后的 4 行并在 PARALLEL
块中注释这些行),xs
副本的维度和分配状态到每个thread应该继承了原来的xs
。但是在运行时,根据 gdb
在进入 PARALLEL
部分时,我遇到了分段错误。
我用gfortran -g -fopenmp <filename>
编译。省略 -fopenmp
会显示所需的行为。
与此同时,我发现 bug report 正是关于这种行为的。事实证明,即使 OpenMP 4.0 也不支持可分配组件的 Fortran2003 功能。
This OpenMP API specification refers to ISO/IEC 1539-1:2004 as Fortran 2003. The following features are not supported:
• IEEE Arithmetic issues covered in Fortran 2003 Section 14
• Allocatable enhancement
我希望这对其他人有帮助。
在下面的示例中,我在并行块内部和外部分配了一个数组(作为派生数据类型的一部分)。由于使用了这个数组private
,两种方式都应该根据 OpenMP 3.0 规范工作(我使用 gcc-4.6.3 编译)
在当前变体中,allocate
应该是线程安全的。但是在运行时我得到了保留一个已经保留的变量的错误。
module Example_mod
contains
subroutine unter(n1,n2)
implicit none
type daten
real, allocatable, dimension(:,:)::x
integer::n1,n2
end type daten
integer, intent (in)::n1,n2
integer l
real,dimension(4)::ausgabe
type(daten)::xs
! initializing xs:
! xs%n1 = n1
! xs%n2 = n2
! allocate(xs%x(n1,n2))
! xs%x = 1.1
!$omp parallel private(xs)
xs%n1 = n1
xs%n2 = n2
allocate(xs%x(n1,n2))
xs%x = 1.1
!$OMP DO
do l = 1, 4
xs%x = l**2
ausgabe(l) = sum(xs%x)
enddo
!$omp end DO
deallocate(xs%x)
!$OMP end parallel
! deallocate(xs%x)
write(*,*) ausgabe
end subroutine unter
end module Example_mod
program main
use Example_mod
call unter(10,12)
end program main
在另一个变体中(取消注释 ! initializing xs:
之后的 4 行并在 PARALLEL
块中注释这些行),xs
副本的维度和分配状态到每个thread应该继承了原来的xs
。但是在运行时,根据 gdb
在进入 PARALLEL
部分时,我遇到了分段错误。
我用gfortran -g -fopenmp <filename>
编译。省略 -fopenmp
会显示所需的行为。
与此同时,我发现 bug report 正是关于这种行为的。事实证明,即使 OpenMP 4.0 也不支持可分配组件的 Fortran2003 功能。
This OpenMP API specification refers to ISO/IEC 1539-1:2004 as Fortran 2003. The following features are not supported:
• IEEE Arithmetic issues covered in Fortran 2003 Section 14
• Allocatable enhancement
我希望这对其他人有帮助。