Skip to content

ACC004 reduction-into-device-module-variable ​

error enabled by default

An OpenACC reduction targets a module allocatable declared !$acc declare create.

Why ​

A reduction whose target is a module allocatable made device-resident by !$acc declare create fails with nvfortran (the kernel does not launch or the result is wrong), while the same code works with a local variable. Reduce into a local scalar and assign it to the module variable afterwards.

Reported ​

fortran
module state
  real, allocatable :: total
  !$acc declare create(total)
...
!$acc parallel loop reduction(+:total)

Preferred ​

fortran
real :: partial
partial = 0.0
!$acc parallel loop reduction(+:partial)
...
total = partial

Suppressing ​

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

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

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

References ​

Sections of the shipped knowledge packs behind this rule:

  • hpc-practice:gpu-practice#nvfortran-bug-openacc-reduction-into-a-declare-create-module (fobis kb show hpc-practice:gpu-practice#nvfortran-bug-openacc-reduction-into-a-declare-create-module)