Fixing an OpenMP race condition

If you can do with $omp atomic it is much better than critical! Also, your reduction with an array is extremely memory consuming, basically allocating fp * (omp_num_threads + 1), I wouldn’t go there.
Instead you could use the sink method, so something like this:

!$omp parallel do ordered(2) private(l,j,i) reduction(+:norm2) schedule(static,1)
      do l = 1,nx
        do j = 1,ny
!$omp ordered depend(sink:l-1,j) depend(sink:l,j-1)

this is an easy way to use openmp threading for gauss-seidel methods, as you have here.

:wink:

2 Likes