Not entering Loop when running in parallel

General OpenMP discussion

Not entering Loop when running in parallel

Postby lstagner » Mon Feb 17, 2014 8:25 pm

Hi all

So I have a piece of Monte Carlo code that looks something like this
Code: Select all
   
    !$OMP PARALLEL DO private(i,j,k,ii,jj,other variables)
    loop_along_z: do k = 1, Nz
       loop_along_y: do j = 1, Ny
          loop_along_x: do i = 1, Nx
             !! ------------- loop over the particles ---------------------- !!
             repeat_loop: do ii=1, Nr
                loop_over_particles: do jj=1,int(nlaunch(i,j,k))
                .
                .
                .
                enddo loop_over_particles
             enddo repeat_loop
          enddo loop_along_x
       enddo loop_along_y
    enddo loop_along_z
    !$OMP END PARALLEL DO

which works. The issue I noticed is that for quite a few of the cells (i,j,k) nlaunch is zero which means most of the time the threads were doing useless work. To fix that I found which cells have nlaunch > 0 and then loop over those cells so that each thread is only doing useful work. The code now looks something like this
Code: Select all
    !$OMP PARALLEL DO private(c,i,j,k,ii,jj,other variables)
    loop_along_good_cells: do c = 1, Ncells
      i=cell(1,c)
      j=cell(2,c)
      k=cell(3,c)
      print*,i,j,k
      !! ------------- loop over the particles ---------------------- !!
      repeat_loop: do ii=1, Nr
        loop_over_particles: do jj=1,int(nlaunch(i,j,k))
                .
                .
                .
        enddo loop_over_particles
      enddo repeat_loop
    enddo loop_along_good_cells
    !$OMP END PARALLEL DO


So this code compiles and works when run serially but when i run it in parallel it never enters the loop_along_good_cells loop since it never prints out the indices.
If you can tell me what I am doing wrong I would very much appreciate it.
For clarity I am using the intel fortran compiler (v11) with the following flags (-O2 -openmp -openmp-report -parallel)
lstagner
 
Posts: 5
Joined: Mon Feb 17, 2014 7:04 pm

Re: Not entering Loop when running in parallel

Postby lstagner » Mon Feb 17, 2014 10:00 pm

I have figured it out. I was unaware that setting a variable that was previously set outside the parallel region unsets it if put in the private clause.
lstagner
 
Posts: 5
Joined: Mon Feb 17, 2014 7:04 pm

Re: Not entering Loop when running in parallel

Postby MarkB » Tue Feb 18, 2014 6:25 am

lstagner wrote:I have figured it out. I was unaware that setting a variable that was previously set outside the parallel region unsets it if put in the private clause.


Yes, private copies of variables are uninitialised on entry to the parallel region, unless declared firstprivate!
MarkB
 
Posts: 447
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 8 guests