I am trying to vectorize a nested loop using the OpenMP 4.0 function simd, but I am afraid that I am doing it wrong. My loops look like this:
do iy = iyfirst, iylast
do ix = ixfirst, ixlast
!$omp simd
do iz = izfirst, izlast
dudx(iz,ix,iy) = ax(1)*( u(iz,ix,iy) - u(iz,ix-1,iy) )
do ishift = 2, ophalf
dudx(iz,ix,iy) = dudx(iz,ix,iy) + ax(ishift)*( u(iz,ix+ishift-1,iy) - u(iz,ix-ishift,iy) )
enddo
dudx(iz,ix,iy) = dudx(iz,ix,iy)*buoy_x(iz,ix,iy)
enddo
!$omp end simd
enddo
enddo
Note that ophalfthis is a small integer, usually 2 or 4, so it makes sense to vectorize a loop izrather than an inner loop.
My question is: Should I mark ishiftas a private variable?
In standard OpenMP loops, parallel doyou will probably need private(ishift)to prevent other threads from stomping on top of each other. However, when I instead rewrite the first line as !$omp simd private(ishift), I get an ifort compilation error:
# 8592: SIMD DO- PRIVATE SIMD. [ISHIFT]
, . , ishift , . ?
: , omp parallel do iy, private(ishift) omp parallel do, omp simd , ?
.