在OpenMP并行区域中调用Fortran子程序



我正试图在主OpenMP并行区域内调用一个子例程,如:

type(type1) :: A(:)
!$omp parallel private(variable_a, variable_b, ...)
!$do
do i = 1, n, 1
call A(i) % sub(variable_a, variable_b, ...)
end do
$enddo
!$end parallel

在另一个文件中,我定义了Fortran类型type1,其中包含一个名为sub的过程。sub类似于:

subroutine( this, val_a, val_b, ...)
class(type1), intent(inout) :: this
type(anytype), intent(in) :: val_a
type(anytype), intent(in) :: val_b
...
! type_2 is another type defined in another file
type(type2), pointer :: p => null
do i = 1, n, 1
allocate(p)
p => null()
end do
return
end subroutine

然而,我发现p似乎是一个共享变量。为什么会发生这种情况?

遵循OpenMP标准的p应该是共享的,因为它有初始化,并且不是threadprivate指令的一部分。引用OpenMP 5.2标准文件第5.1.2节:

区域中被调用例程中声明的局部变量具有SAVE属性,或已初始化数据的共享除非它们在threadprivate指令中显示为参数。

最新更新