Overcoming race condition

Hi,
I have the following code boiled down to the essential elements. My aim is to parallelize the outer loop using openacc.

pnt(:) = 0
n_points = 0
!$acc data copy(pnt,n_points)
!$acc parallel loop gang vector reduction(+:n_points) private(jmin,jmax,j,k)
DO i=1,n
     jmin = get_lower_limit(i)
     jmax = get_upper_limit(i)
     DO j=jmin,jmax
          k = get_k(j)
          IF (pnt(j)==0) THEN
               pnt(j) = k
               n_points = n_points+1
          END IF
     END DO
END DO
!$acc end parallel
!$acc end data

The IF statement will result in race condition. In openmp, I can parallelize this by putting the IF statement in a CRITICAL region. However, I am out of ideas as to how to accomplish this in openacc.
Cheers,
Jyoti

Is the set of “j” values unique to each “i”? i.e. are each jmin and jmax different ranges and don’t overlap between the “i” values.

If so, then I think you’re ok given the <i,j> pair would be unique to each thread. The inner loop could be parallelized as well.

If there is overlap, then I’m not seeing a way to parallelize this loop.

Hi Mat,
The “j” values are unfortunately not unique to each “i”. That’s where I am stuck. Thanks for your prompt response.
Cheers,
Jyoti

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.