0

I've got the following problem, trying to parallelize my code. The simplified code looks like this:

   !$omp parallel do private(e, b0_vek) reduction(+:b_vek) schedule(static, chunk_elem)
   do e = 1, n_elem
      call AddSource(elem(e), b0_vek)
      slice=elem(e)%node(1:6) !vector with indices in the global node list
      b_vek(slice)=b_vek(slice)+b0_vek(1:6)
   end do  ! e = 1, n_elem

The summation is over all elements, each of which is defined by 6 nodes. In AddSource subroutine the vector b0_vek(1:6) is calculated for each element. It should be added to the certain part (slice) of the b_vek, however, the slices can be crossing for some elements, as elements can be neighbors and thus, can contain several same nodes.

The reduction operation doesn’t work properly here, is there any other possibility to do it with openMP?

6
  • I'm struggling to understand this a little bit. Does it work on a single thread? If it does how do the answers differ on multiple threads? How is elem scoped, public? The interface to AddSource might be useful as well, but best would be a Minimal, Reproducible example including exactly how you compile it. Commented Oct 22, 2024 at 10:40
  • slice should be private, and it is not. Commented Oct 22, 2024 at 12:01
  • btw, you don't need to declare the reduced variables as private, they implicitly are. Commented Oct 22, 2024 at 12:03
  • In addition to the shared slice mentioned by Pier, a possible issue might be an unitialized state of b_vek. @PierU b0_vek and b_vek are different variables, one is private one is used for the reduction ;) Commented Oct 22, 2024 at 14:17
  • The shared access to slice will result in a data race. You can use ThreadSanitizer to find such races. If you have access to the latest ifx compiler, I would recommend using that for detecting races in Fortran code: ifx -fopenmp -fsanitize=thread app.f. Commented Oct 22, 2024 at 14:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.