distribute closely nested in teams?

Comments and discussion of the 4.1 OpenMP Draft specifications. Comment period ends September 30, 2015. See http://openmp.org/wp/openmp-specifications/ to download the specifications. (Read Only)
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help: https://stackoverflow.com/questions/tagged/openmp
Locked
fewl9012
Posts: 73
Joined: Mon Jul 27, 2015 4:50 pm

distribute closely nested in teams?

Post by fewl9012 »

One reason for separating the parallel construct from the worksharing construct was to reduce the overhead of creating the teams, of parallelism initiation. The restrictions of the distribute construct reduces this. P111:10, "A distribute construct must be closely nested in a teams region."

Suppose I have two loops:

Code: Select all

do j = 1, m
  do i = 1, n
    a(i,j) = something_really_expensive(i,j)
  enddo
enddo
Suppose I want the outer loop parallelized across teams and the inner loop parallelized across threads within a team. To do this I must write:

Code: Select all

!omp target teams ...
  !omp distribute
  do j = 1, m
    !$omp parallel do
    do i = 1, n
      a(i,j) = something_really_expensive(i,j)
    enddo
  enddo
!$omp end target teams
So the program has to create a new parallel team for each iteration of the outer loop. OK, there are a number of teams, so each team master thread creates 'm/num_teams' teams.

More efficient would seem to be:

Code: Select all

!omp target teams ...
  !$omp parallel
  !omp distribute
  do j = 1, m
    !$omp do
    do i = 1, n
      a(i,j) = something_really_expensive(i,j)
    enddo
  enddo
!$omp end target teams
Here the program creates all the parallelism at the outermost level, then does the loop scheduling within. Since the only distribute schedule is static, this should be feasible.

Locked