I have a potentially simple question, but looking at SO I couldn't find any questions that asked quite the same thing. My question is: will the collapse clause in the OpenMP code below properly handle both inner loops? Or will it only collapse with the first inner loop?
!$omp parallel do collapse(2) private(iy, ix, iz)
do iy = 1, ny
do ix = 1, nx
! stuff
enddo
do iz = 1, nz
! different stuff
enddo
enddo
!$omp end parallel do
This code compiles for me and obviously shows benefits of parallelization. However, I know that the standard says:
All loops associated with the loop construct must be perfectly nested; that is, there must be no intervening code nor any OpenMP directive between any two loops.
So my gut reaction is that OpenMP is only collapsing the first inner loop (ix). But then how is it handling the second inner loop (iz)?
I am obviously attempting the code to do the following, but it is much uglier and verbose to write the code this way:
!$omp parallel private(iy, ix, iz)
!$omp do collapse(2)
do iy = 1, ny
do ix = 1, nx
! stuff
enddo
enddo
!$omp end do nowait
!$omp do collapse(2)
do iy = 1, ny
do iz = 1, nz
! different stuff
enddo
enddo
!$omp end do nowait
!$omp end parallel do