You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the file solver.f90 at lines 81 and 125 appears this block:
!$OMP PARALLEL DOdo i=1,n; norm=norm+r(i)*r(i); end do
!$OMP END PARALLEL DO
There is a data race here as threads handling different iterations of the reduction loop are trying to update the same variable concurrently. In order to restore correctness, the OpenMP reduction clause can be used, it will ensure that each thread sum its r(i)*r(i) increments into a thread-local temporary variable. At the end of the loop, OpenMP will make those threads sum the final value of their thread-local temporary variable back into the original norm variable, taking care of potential data races in the process. The corrected block would look as follows:
!$OMP PARALLEL DO REDUCTION(+:norm)
do i=1,n; norm=norm+r(i)*r(i); end do
!$OMP END PARALLEL DO
There might be other blocks in a similar situation, for which the same fix applies, such as the one at line 113 in the same file solver.f90:
!$OMP PARALLEL DOdo i=1,n; x(i)=x(i)+alpha*p(i)+omega*ss(i); end do
!$OMP END PARALLEL DO
In the file
solver.f90
at lines 81 and 125 appears this block:There is a data race here as threads handling different iterations of the reduction loop are trying to update the same variable concurrently. In order to restore correctness, the OpenMP
reduction
clause can be used, it will ensure that each thread sum itsr(i)*r(i)
increments into a thread-local temporary variable. At the end of the loop, OpenMP will make those threads sum the final value of their thread-local temporary variable back into the originalnorm
variable, taking care of potential data races in the process. The corrected block would look as follows:There might be other blocks in a similar situation, for which the same fix applies, such as the one at line 113 in the same file
solver.f90
:You can refer to https://rookiehpc.github.io/openmp/docs/reduction/index.html for more information.
The text was updated successfully, but these errors were encountered: