Fortran90 OpenMP 中的重要私有数据
我有一个 Fortran90 程序的一部分,应该与 OpenMP 并行化。
!$omp parallel num_threads(8) &
!$omp private(j, s, prop_states) &
!$omp firstprivate(targets, pulses)
! ... modify something in pulses. targets(s)%ham contains pointers to
! elements of pulses ...
do s = 1, n_systems
prop_states(s) = targets(s)%psi_i
call prop(prop_states(s), targets(s)%grid, targets(s)%ham, &
& targets(s)%work, para)
end do
!$omp end parallel
我不确定复杂的数据结构是否可以对每个线程私有(以及应该如何完成 - firstprivate
正确吗?)。在上面的示例代码中,targets
是一种有些复杂的用户定义类型,具有同样复杂的子字段。例如,targets(s)%ham%op(1)%pulse
是指向数组 pulses
某个元素的指针。此外,targets(s)%work
包含分配的空间,用作快速傅立叶变换中的工作数组。
显然,每个线程都需要维护targets
和pulses
的独立副本,并独立维护两者之间的指针。在我看来,这对 OpenMP 自动内存管理的要求可能有点过高。这是正确的,还是应该开箱即用?
当然,另一种选择是在每个线程中创建原始数据的副本(存储在数组中),并在对 prop
的调用中使用此私有复制数据。
I have a section of a Fortran90 program that should be parallelized with OpenMP.
!$omp parallel num_threads(8) &
!$omp private(j, s, prop_states) &
!$omp firstprivate(targets, pulses)
! ... modify something in pulses. targets(s)%ham contains pointers to
! elements of pulses ...
do s = 1, n_systems
prop_states(s) = targets(s)%psi_i
call prop(prop_states(s), targets(s)%grid, targets(s)%ham, &
& targets(s)%work, para)
end do
!$omp end parallel
What I'm unsure about is whether complex data structures can be private to each thread (and how this should be done -- is firstprivate
correct?). In the example code above, targets
is of a somewhat complicated user-defined type, with equally complex sub-fields. For example, targets(s)%ham%op(1)%pulse
is a pointer to some element of an array pulses
. Also, targets(s)%work
contains allocated space to be used as work arrays in Fast-Fourier-Transforms.
Obviously, every thread needs to maintain an independent copy both of targets
and of pulses
, and maintain the pointers between the two independently. It seems to me that this might be asking a little bit too much from the automatic memory management of OpenMP. Is this correct, or should this work out of the box?
The alternative of course is to create copies of the original data within each thread (stored in an array), and use this private copied data in the call to prop
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我对 OpenMP 2.5 标准的阅读,您不能在
private
(或firstprivate
或threadprivate
)子句中使用 Fortran 指针的目标,这似乎排除了你的代码。话虽如此,这不是我在 OpenMP 中尝试过的东西,所以如果您奋力前进并取得任何进展,请告诉我们。如果您的私有变量要在进入并行区域时使用并行区域入口处的同名变量的值进行初始化,则
firstprivate
是正确的。我想你可能必须实施你的 B 计划。
From my reading of the OpenMP 2.5 standard you can't use the targets of Fortran pointers in
private
(orfirstprivate
orthreadprivate
) clauses, which seems to rule out your code. Having said that, it's not something I've ever tried in OpenMP so if you bash ahead and get anywhere, do let us know.And
firstprivate
is correct if your private variables are to be initialised, on entry into the parallel region, with the value of the variables of the same name at the entry to the parallel region.I guess you will probably have to implement your plan B.