Fortran90 OpenMP 中的重要私有数据

发布于 2024-08-06 16:21:33 字数 947 浏览 6 评论 0原文

我有一个 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 包含分配的空间,用作快速傅立叶变换中的工作数组。

显然,每个线程都需要维护targetspulses的独立副本,并独立维护两者之间的指针。在我看来,这对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温暖的光 2024-08-13 16:21:33

根据我对 OpenMP 2.5 标准的阅读,您不能在 private (或 firstprivatethreadprivate)子句中使用 Fortran 指针的目标,这似乎排除了你的代码。话虽如此,这不是我在 OpenMP 中尝试过的东西,所以如果您奋力前进并取得任何进展,请告诉我们。

如果您的私有变量要在进入并行区域时使用并行区域入口处的同名变量的值进行初始化,则 firstprivate 是正确的。

我想你可能必须实施你的 B 计划。

From my reading of the OpenMP 2.5 standard you can't use the targets of Fortran pointers in private (or firstprivate or threadprivate) 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文