Skip to content

OMP004 nowait-dependent-read ​

warning opt-in

Data written by a nowait worksharing construct is read before the next barrier.

Why ​

nowait removes the barrier at the end of a worksharing construct: a thread that finished its share goes on while others are still writing. Reading what the construct wrote, before an explicit !$omp barrier or the barrier of a later construct, reads values that may not be written yet. The one exception the standard guarantees is two loops with schedule(static) and the same iteration space, where each thread gets the same iterations: such pairs are not reported.

Reported ​

fortran
!$omp parallel
!$omp do
do i = 1, n
  a(i) = f(i)
end do
!$omp end do nowait
!$omp do
do i = 1, n
  b(i) = a(n - i + 1)    ! another thread may not have written it yet
end do
!$omp end do
!$omp end parallel

Preferred ​

fortran
!$omp end do            ! keep the barrier, or add !$omp barrier before the read

Suppressing ​

For one occurrence, with the reason on the same line (or alone on the line before the statement):

fortran
! fobis: ignore[OMP004] <why this occurrence is fine>

For the whole project, ignore = OMP004 in the fobos [lint] section.

References ​

Sections of the shipped knowledge packs behind this rule:

  • openmp:ch13-work-distribution#anti-patterns (fobis kb show openmp:ch13-work-distribution#anti-patterns)
  • openmp:ch13-work-distribution#key-concepts (fobis kb show openmp:ch13-work-distribution#key-concepts)