2

I read: "This construct (Omp workshare) is used to parallelize array operations by dividing the task into units of work. Each such unit of work is handled only by one of the available threads present in the parallel region." (from 'Ray, S. (2019). Fortran 2018 with Parallel Programming (1st ed.). CRC Press'). So what is it the practical difference between 'omp workshare' and 'omp sections'?

P.S: I'm using gfortran so if you use an example pls use a fortran code.

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
user
  • 309
  • 1
  • 9

1 Answers1

2

OpenMP Workshare is something completely different from sections and even a very brief read in your book should actually reveal the difference.

With sections you are defining different parts of code, that can be done concurrently.

!$omp parallel

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

!$omp end parallel

With workshare you are saying that a Fortran forall or where construct or an array operation can be evaluated by parts by OpenMP threads.

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

...

!$omp parallel

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

!$omp end parallel

The A = B * C array operation will be divided into small parts and each thread will evaluate some of these parts.