Observed issues › gcc/gcc-loop-bind-default-none-rejected
gfortran: loop bind(thread) or bind(teams) inside parallel or teams with default(none) is rejected ("'i' not specified in enclosing 'parallel'")
Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked
In a parallel (or teams) region with default(none), GCC 16.2's Fortran front end rejects a loop construct because its own loop variable is not listed ("'i' not specified in enclosing 'parallel'"). OpenMP 5.2 predetermines that variable (lastprivate for the loop construct, private in the enclosing parallel or teams region in Fortran), so default(none) does not require it. GCC's documentation lists the loop construct as supported.
Affected variants
| Compiler | MI300A gfx942 unified memory (XNACK 1) | MI300A gfx942 copy (XNACK 0) | MI250X gfx90a copy (XNACK 0) | MI300X gfx942 copy (XNACK 0) | MI350X gfx950 copy (XNACK 0) | A100 sm_80 separate memory | A100 sm_80 managed memory |
|---|---|---|---|---|---|---|---|
| AFAR 24.3.0 | fails another way | fails another way | unknown not run | fails another way | fails another way | n/a | n/a |
| CCE 19.0.0 | fails another way | fails another way | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | fails another way | fails another way | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | fails another way | fails another way | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | fails another way | fails another way | unknown not run | unknown not run | unknown not run | n/a | n/a |
| NVHPC 25.11 | n/a | n/a | n/a | n/a | n/a | correct | correct |
| NVHPC 26.9 | n/a | n/a | n/a | n/a | n/a | correct | correct |
| GCC 16.2.0 | not supported | not supported | not supported | not supported | not supported | not supported | n/a |
"behaves incorrectly" / "not supported": this issue, confirmed in up to four environments (another build directory, another node, a repeat). "fails another way": a different failure, not counted as this issue. "unknown": not run there, or the runs disagree.
Messages
| Result | Compiler and GPU | Message |
|---|---|---|
| not supported | GCC 16.2.0, MI300A unified GCC 16.2.0, MI300A copy GCC 16.2.0, MI250X GCC 16.2.0, MI300X GCC 16.2.0, MI350X GCC 16.2.0, A100 separate | showsite-gcc--gcc-loop-bind-default-none-rejected.f90:68:29:
68 | !$omp loop bind(thread)
| ^
Error: ‘i’ not specified in enclosing ‘parallel’
site-gcc--gcc-loop-bind-default-none-rejected.f90:65:69:
65 | !$omp parallel default(none) private(tid) shared(a, b, hit, nthr)
| ^
note: enclosing ‘parallel’ |
| fails another way | AFAR 24.3.0, MI300A unified AFAR 24.3.0, MI300A copy AFAR 24.3.0, MI300X AFAR 24.3.0, MI350X CCE 19.0.0, MI300A unified CCE 19.0.0, MI300A copy CCE 20.0.2, MI300A unified CCE 20.0.2, MI300A copy CCE 21.0.3, MI300A unified CCE 21.0.3, MI300A copy CCE 21.0.4, MI300A unified CCE 21.0.4, MI300A copy | showRESULT ran_on_host=0 check=fail |
Reproduce
GCC 16.2.0, MI300A unified
export LD_LIBRARY_PATH=$GCC_16_2/lib64:/opt/rocm-7.2.1/lib $GCC_16_2/bin/gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
GCC 16.2.0, A100 separate
export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=$GCC_16_2/lib64 $GCC_16_2/bin/gfortran -fopenmp -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 repro.f90 -o repro OMP_TARGET_OFFLOAD=mandatory ./repro
NVHPC 25.11, A100 separate (runs correctly)
export LD_LIBRARY_PATH=$NVHPC_25_11/compilers/lib nvfortran -mp=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.f90 -o repro OMP_TARGET_OFFLOAD=mandatory ./repro
Program (85 lines)
! # Finding (GCC 16.2): a loop construct in a parallel or teams region with default(none) is rejected for its own loop variable; the
! reproducer is the catalog program omp52-clause-bind-thread
!
! - toolchains: gcc_g90 (GCC 16.2.0, AMD Instinct MI250X gfx90a, Tioga) and gcc_sm80 (GCC 16.2.0,
! NVIDIA A100 sm_80, wingtip); separate memory only; -O2; OMP_TARGET_OFFLOAD=mandatory
! - build: gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx90a -O2 (gcc_g90);
! -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 (gcc_sm80)
! - failure: rejected: not specified in enclosing
! - observed: `Error: 'i' not specified in enclosing 'parallel'` (`... enclosing 'teams'` for bind(teams) in a teams region with
! default(none)), on both GPUs.
! - expected: compiles; `RESULT ran_on_host=0 check=pass`
! - rule: i is the loop iteration variable of the loop construct's associated loop, so it has a predetermined attribute and
! default(none) does not apply to it: "The loop iteration variable in any associated loop of a loop construct is lastprivate" (5.2
! §5.1.1 p.97 l.18), and in Fortran "Loop iteration variables inside parallel, teams, or task generating constructs are private in
! the innermost such construct that encloses the loop" (5.2 §5.1.1 p.97 l.22-23). The loop construct and its bind clause: 5.2
! §11.7 p.257, §11.7.1 p.258.
! - GCC 16.2 documentation (libgomp.texi of the GCC 16.2.0 release tarball, "OpenMP Implementation Status"): "loop construct": Y
! (OpenMP 5.0 table). The rejection is not documented.
! - other families: NVHPC 25.11/26.9 compile and run omp52-clause-bind-thread correctly; AFAR and CCE compile it and fail at run
! time (fortran-loop-bind-thread-in-parallel.f90). CCE compiles and runs the bind(teams) program; AFAR and NVHPC reject it.
! - gate and confirmer: 12 cells (6 gcc_g90, 6 gcc_sm80), each confirmed in the gate's four environments (a-d;
! results/gcc/gate-tioga/ and gate-wingtip/ verdicts.jsonl); confirmer verdicts (results/gcc/confirm/batch.gcc_*.jsonl):
! compiler_bug (R11-compile-rejection) 8, unsupported (R11a-newer-form-unclaimed) 4
! - catalog programs (6): omp50-clause-bind, omp50-clause-bind-thread, omp52-clause-bind, omp52-clause-bind-thread,
! omp60-clause-bind, omp60-clause-bind-thread
! - legality: the catalog programs are legal by construction (offload.engine.gen, c_gen and acc_gen
! check every program against the catalog rules and the offload scope as it is built; no
! compiler). GCC is a compiler under test only: never a legality witness, here or for another
! family's case (catalog/machines.yaml under_test_only).
! Generated by compliance.gen (OpenMP 5.2, free-form Fortran). Do not edit.
! id: omp52-clause-bind-thread
! primary atom: omp.clause.bind.thread
! legal: yes
! observable: yes
! ran_on_host: inside the target region of interest
! evidence: construct
! needs: none
! std: f2008
! derivation (check=pass): loop bind(thread) in a parallel region: the binding thread set is the encountering thread, and each
! logical iteration is executed once per loop region by exactly one thread of that set (5.2 §11.7 p.257 and §11.7.1 p.258), so every
! thread runs all 64 iterations and writes hit(i, tid + 1) once each (distinct elements, so the concurrent iterations do not race):
! tot(t) = 64 for every thread; the team size is implementation defined and only threads 0 .. 1023 record (hit has 1024 columns), so
! all(tot(1:min(nthr, 1024)) == n) holds for any team size, and nthr >= 1; thread 0 writes b = ref; the check accepts
program gen_prog
use omp_lib, only: omp_get_num_threads, omp_get_thread_num, omp_is_initial_device
implicit none
integer, parameter :: n = 64
integer, allocatable, target :: a(:), b(:)
integer :: ref(n)
integer :: i, host_flag
logical :: ok
integer :: hit(n, 1024), tot(1024), k
integer :: tid, nthr
allocate(a(n), b(n))
do i = 1, n
a(i) = i
b(i) = 0
ref(i) = 2*i + 1
end do
host_flag = 1
hit = 0
nthr = -1
!$omp target map(to: a) map(from: b) map(tofrom: hit, nthr) map(tofrom: host_flag)
host_flag = merge(1, 0, omp_is_initial_device())
!$omp parallel default(none) private(tid) shared(a, b, hit, nthr)
tid = omp_get_thread_num()
if (tid == 0) nthr = omp_get_num_threads()
!$omp loop bind(thread)
do i = 1, n
if (tid == 0) b(i) = 2*a(i) + 1
if (tid < 1024) hit(i, tid + 1) = hit(i, tid + 1) + 1
end do
!$omp end loop
!$omp end parallel
!$omp end target
do k = 1, 1024
tot(k) = 0
do i = 1, n
tot(k) = tot(k) + hit(i, k)
end do
end do
ok = all(b == ref) .and. (nthr >= 1) .and. all(tot(1:min(nthr, 1024)) == n)
print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
deallocate(a, b)
end program gen_prog
Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page
Expected and observed
Expected
check=pass
Observed where it behaves incorrectly
site-gcc--gcc-loop-bind-default-none-rejected.f90:68:29:
68 | !$omp loop bind(thread)
| ^
Error: ‘i’ not specified in enclosing ‘parallel’
site-gcc--gcc-loop-bind-default-none-rejected.f90:65:69:
65 | !$omp parallel default(none) private(tid) shared(a, b, hit, nthr)
| ^
note: enclosing ‘parallel’What the specification requires
The specification text this program relies on and the compiler is expected to support.
OpenMP 5.2 §5.1.1 p.97 l.18
The loop iteration variable in any associated loop of a loop construct is lastprivate
OpenMP 5.2 §5.1.1 p.97 l.22-23
Loop iteration variables inside parallel, teams, or task generating constructs are private in the innermost such construct that encloses the loop
OpenMP 5.2 §11.7 p.257
OpenMP 5.2 §11.7.1 p.258
OpenMP 5.2 §11.7 p.257
OpenMP 5.2 §11.7.1 p.258
Evidence
Other compilers run it correctly
NVHPC 25.11, NVHPC 26.9