OMP005 serialisation-in-innermost-loop
warning enabled by defaultAn OpenMP critical or atomic is inside the innermost loop of a parallel loop.
Why
critical lets one thread at a time through, atomic serialises the threads that update the same location: inside the innermost loop they run once per iteration and the parallel loop runs at the speed of its serial part, or slower. Accumulate in a private variable (or a reduction clause) and combine once per thread, outside the loop.
Reported
fortran
!$omp parallel do
do i = 1, n
!$omp critical
total = total + w(i)
!$omp end critical
end doPreferred
fortran
!$omp parallel do reduction(+:total)
do i = 1, n
total = total + w(i)
end doSuppressing
For one occurrence, with the reason on the same line (or alone on the line before the statement):
fortran
! fobis: ignore[OMP005] <why this occurrence is fine>For the whole project, ignore = OMP005 in the fobos [lint] section.
References
Sections of the shipped knowledge packs behind this rule:
openmp:ch16-synchronization#anti-patterns(fobis kb show openmp:ch16-synchronization#anti-patterns)openmp:cheatsheet#synchronization(fobis kb show openmp:cheatsheet#synchronization)