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?
sliceshould be private, and it is not.slicementioned by Pier, a possible issue might be an unitialized state ofb_vek. @PierUb0_vekandb_vekare different variables, one is private one is used for the reduction ;)slicewill 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.