OMP002 accumulation-without-reduction
warning enabled by defaultA shared scalar is accumulated inside an OpenMP parallel region without reduction.
Why
s = s + x(i) in a parallel loop reads and writes the shared s from every thread: updates are lost and the result changes from run to run. A reduction(+:s) clause gives each thread a private partial sum and combines them at the end of the region; atomic is correct but serialises every update.
Reported
fortran
!$omp parallel do
do i = 1, n
s = s + x(i)
end doPreferred
fortran
!$omp parallel do reduction(+:s)
do i = 1, n
s = s + x(i)
end doSuppressing
For one occurrence, with the reason on the same line (or alone on the line before the statement):
fortran
! fobis: ignore[OMP002] <why this occurrence is fine>For the whole project, ignore = OMP002 in the fobos [lint] section.
References
Sections of the shipped knowledge packs behind this rule:
openmp:ch07-data-environment#frameworks-introduced(fobis kb show openmp:ch07-data-environment#frameworks-introduced)