Openmp parallelization help

Hi,

I am trying to modify loop in a program using Openmp syntax. The problem I am facing is using Openmp syntax gives core dump and the print statement are not consistent in run. Sometimes the loop doesn’t start at all.

I am also setting “ulimit -s unlimited” as suggested in some searches. This program is a modified version of open source program, just trying to make it more advance.

Also, if some one can point out private and shared variables I have used are correct or not.

Thanks

Apurva

Following is the loop

!$OMP PARALLEL DO shared(r,ro,vx,vr,rovt,vt,rovx,rovr,rorvt) private(i,j,k,rrnow,recip) collapse(3) num_threads(4) schedule(static)

DO k=1,km
print *,“k”,k

DO j=2,jm
print *,“j”,j
rrnow = 1/r(j,k)

   DO  i=1,im
       print \*,“i”,i
      !$OMP CRITICAL
     recip       = 1.0/ro(i,j,k)
     vx(i,j,k)   = rovx(i,j,k)\*recip
     vr(i,j,k)   = rovr(i,j,k)\*recip
     rovt(i,j,k) = rorvt(i,j,k)\*rrnow
     vt(i,j,k)   = rovt(i,j,k)\*recip
    !$OMP END CRITICAL


END DO

END DO

END DO
!$OMP END PARALLEL DO

I doubt this code compile at all, as the COLLAPSE clause works only if the loops are strictly nested, i.e. there shall be no statement between two DO or two END DO

1 Like

Can you indicate the values of im,jm,km as to the reason for collapse ?
Why is CRITICAL being used, as there is no apparent race condition in the critical region ?
(I presume the use of "\*" is a text error ?)

This code appears to be an example of insufficient computation to justify using !$OMP, but could be useful as a demonstration of using OpenMP

You may benefit from using the following to identify the thread allocation to itterations
id = omp_get_thread_num()
print *, i,j,k,id