Omp 部分与 Omp 工作共享

Omp sections vs Omp workshare

我读到:“此构造 (Omp workshare) 用于通过将任务划分为工作单元来并行化数组操作。每个这样的工作单元仅由并行区域中存在的可用线程之一处理。 “ (来自 'Ray, S. (2019). Fortran 2018 with Parallel Programming (1st ed.). CRC Press')。那么 'omp workshare' 和 'omp sections' 之间的实际区别是什么?

P.S:我使用的是 gfortran,因此如果您使用示例,请使用 fortran 代码。

OpenMP Workshare 与部分内容完全不同,即使是非常简短地阅读您的书也应该真正揭示其中的区别。

使用节定义代码的不同部分,可以同时完成。

!$omp parallel

!$omp sections
!$omp section
  some commands
!$omp sections
  some different independent commands
!$omp end sections

!$omp end parallel

对于 workshare,您是说 Fortran forallwhere 构造或数组操作可以由 OpenMP 线程按部分计算。

real, dimension(:,:,:) :: A, B, C

...

!$omp parallel

!$omp workshare
A = B * C
!$omp end workshare

!$omp end parallel

A = B * C数组操作将被分成小部分,每个线程将评估其中的一些部分。