title: how can i keep variables private in subroutines which are called in a parallel section of openmp?
body: <p>i am calling a nested for loop as follows:</p>
  
  <pre><code>do ir = 1,Nr
      do iom = iom1, iom2
         xyz(1) = xo(1) + xom(iom)*r
         xyz(2) = xo(2) + yom(iom)*r
         xyz(3) = xo(3) + zom(iom)*r
         call FUNSUB(xyz,Nprop,PropXYZ)
      enddo
  enddo
  </code></pre>
  
  <p>where <code>FUNSUB</code> evaluates a property in the following manner:</p>
  
  <pre><code>id = 1
  do l=0,lmax
      do m=-l,l
          id = id + 1
          Prop(id) = RHO * Ylm(l,m,xl(1),xl(2),xl(3))
      enddo
  enddo
  </code></pre>
  
  <p>now i am trying to parallelize this with something of the form</p>
  
  <pre><code>!$OMP parallel do reduction(+:Prop) private(ir, l, m, j, iom, r, wrad, xyz, PropOm, PropOm1, PropXYZ)
  </code></pre>
  
  <p>where some of the other private variables seen here are left out of my example code for brevity. i am intentionally trying to make <code>l</code> and <code>m</code> private so that inside the <code>FUNSUB</code> loops, the properties are evaluated independently. i find, however, that they are shared between threads. i have put in some debugging options and found that <code>id</code> continually goes above the bounds of <code>Prop</code> and have found that <code>l</code> also goes about <code>lmax</code> as well as <code>m</code> being outside the bounds of <code>(-l,l)</code>.</p>
  
  <p>my question is: how do i go about making sure that <code>l</code> and <code>m</code> are kept private and NOT shared from the main routine? it seems that the problem is that it is an entirely different subroutine which holds these values and that, somehow these private declarations of variables do not carry over</p>