# Openmp parallelization help

**URL:** <https://fortran-lang.discourse.group/t/openmp-parallelization-help/10461>\
**Category:** Help\
**Created:** [October 27, 2025, 2:09pm UTC](https://fortran-lang.discourse.group/t/openmp-parallelization-help/10461 "2025-10-27T14:09:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoorv01](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@apoorv01](https://fortran-lang.discourse.group/u/apoorv01)\
**Post date:** [October 27, 2025, 2:09pm UTC](https://fortran-lang.discourse.group/t/openmp-parallelization-help/10461/1 "2025-10-27T14:09:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [October 27, 2025, 2:39pm UTC](https://fortran-lang.discourse.group/t/openmp-parallelization-help/10461/2 "2025-10-27T14:39:23Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![JohnCampbell](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JohnCampbell](https://fortran-lang.discourse.group/u/JohnCampbell)\
**Post date:** [October 27, 2025, 11:46pm UTC](https://fortran-lang.discourse.group/t/openmp-parallelization-help/10461/3 "2025-10-27T23:46:05Z")

</div>

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
