Skip to content

FOR001 saved-local-in-parallel-procedure ​

warning enabled by default

A procedure that runs in parallel has a saved local variable (one copy shared by all threads).

Why ​

A local variable with the SAVE attribute exists once, statically, not once per call. When the procedure is called from inside an OpenMP parallel region or an OpenACC compute region, or is a device routine (!$acc routine, !$omp declare target), every thread works on that single copy: writes race, and on a GPU the variable is a global, not a per-thread temporary. SAVE is often implicit: an initialiser in the declaration (real :: d(3) = [h, h, h]) gives it. Declare the variable without initialiser and assign it in the procedure body.

Reported ​

fortran
subroutine kernel_cell(q)
  !$acc routine seq
  real, intent(inout) :: q(:)
  real :: w(3) = [0.25, 0.5, 0.25]   ! implicit save: one copy for all GPU threads

Preferred ​

fortran
subroutine kernel_cell(q)
  !$acc routine seq
  real, intent(inout) :: q(:)
  real :: w(3)
  w = [0.25, 0.5, 0.25]

Suppressing ​

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

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

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

References ​

Sections of the shipped knowledge packs behind this rule:

  • hpc-practice:fortran-practice#implicit-save-trap (fobis kb show hpc-practice:fortran-practice#implicit-save-trap)