Skip to content

ACC002 atomic-in-compute-region ​

warning enabled by default

An !$acc atomic inside an OpenACC compute region or device routine.

Why ​

Atomics serialise the threads that hit the same address and are a frequent sign of a parallelisation that does not match the data flow (a scatter where a gather would do, a missing reduction). They are correct, but on a GPU they can cost more than the whole kernel. Treat each one as a red flag: restructure as a gather or a reduction clause when possible, keep it only where the scatter is inherent.

Reported ​

fortran
!$acc parallel loop
do e = 1, nedges
  !$acc atomic update
  flux(node(e)) = flux(node(e)) + f(e)
end do

Preferred ​

fortran
!$acc parallel loop
do n = 1, nnodes            ! gather over the edges of each node
  flux(n) = sum(f(edges_of(:, n)))
end do

Suppressing ​

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

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

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

References ​

Sections of the shipped knowledge packs behind this rule:

  • hpc-practice:gpu-practice#atomic-operations-red-flag (fobis kb show hpc-practice:gpu-practice#atomic-operations-red-flag)