Observed issues › fortran-schedule-static-in-target
Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open
Schedule(static, 4) and schedule(static) on a parallel do in a target region deal iterations out one at a time
Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked
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 | behaves incorrectly | behaves incorrectly | behaves incorrectly | behaves incorrectly | behaves incorrectly | n/a | n/a |
| CCE 19.0.0 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | behaves incorrectly | behaves incorrectly | behaves incorrectly | 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 | correct | correct | correct | correct | correct | correct | 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 |
|---|---|---|
| behaves incorrectly | AFAR 24.3.0, MI300A unified AFAR 24.3.0, MI300A copy AFAR 24.3.0, MI250X AFAR 24.3.0, MI300X AFAR 24.3.0, MI350X CCE 19.0.0, MI300A unified CCE 19.0.0, MI300A copy CCE 19.0.0, MI250X CCE 20.0.2, MI300A unified CCE 20.0.2, MI300A copy CCE 20.0.2, MI250X CCE 21.0.3, MI300A unified CCE 21.0.3, MI300A copy CCE 21.0.3, MI250X CCE 21.0.4, MI300A unified CCE 21.0.4, MI300A copy CCE 21.0.4, MI250X | showthreads=256 static,4 tid(1:12)= 0 1 2 3 4 5 6 7 8 9 10 11 static tid(1:12)= 0 1 2 3 4 5 6 7 8 9 10 11 static,4 iterations on the wrong thread: 997 of 1000 (expected 0) static: iterations starting a second chunk of a thread: 744 (expected 0) |
Reproduce
AFAR 24.3.0, MI300A unified
$AFAR/bin/amdflang -fopenmp --offload-arch=gfx942 -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
CCE 19.0.0, MI300A unified
module load cce/19.0.0 craype-accel-amd-gfx942 rocm/6.4.3 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
CCE 20.0.2, MI300A unified
module load cce/20.0.2 craype-accel-amd-gfx942 rocm/6.4.3 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
CCE 21.0.3, MI300A unified
module load cce/21.0.3 craype-accel-amd-gfx942 rocm/7.2.0 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
CCE 21.0.4, MI300A unified
module load cce/21.0.4 craype-accel-amd-gfx942 rocm/7.2.0 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 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 (48 lines)
! Schedule(static, 4) on a parallel do in a target region:
! "iterations are divided into chunks of size chunk_size, and the chunks
! are assigned to the threads in the team in a round-robin fashion in the
! order of the thread number" (5.2 §11.5.3 p.252), so iteration i runs on
! thread mod((i - 1)/4, T). schedule(static) without a chunk size: "at
! most one chunk is distributed to each thread" (same page), so each
! thread's iterations are contiguous.
! Expected: 0 wrong, 0 second chunks. Observed (MI300A, HSA_XNACK 0 and 1,
! 3 runs each): AFAR flang, CCE 19, 20 and 21 ftn: 256 threads,
! tid(1:12) = 0 1 2 ... 11 for both loops (one iteration at a time,
! round-robin), 997 of 1000 iterations on the wrong thread, 744 second
! chunks. The C form (sched_repro.c in results/t27a/diag/d2, AMD clang)
! is correct: tid = 0 0 0 0 1 1 1 1 ...
program sched_repro
use omp_lib
implicit none
integer, parameter :: m = 1000
integer :: tid(m), tid2(m), nthr, i, bad, bad2
tid = -1
tid2 = -1
nthr = -1
!$omp target map(from: tid, tid2, nthr)
!$omp parallel do schedule(static, 4)
do i = 1, m
if (i == 1) nthr = omp_get_num_threads()
tid(i) = omp_get_thread_num()
end do
!$omp end parallel do
!$omp parallel do schedule(static)
do i = 1, m
tid2(i) = omp_get_thread_num()
end do
!$omp end parallel do
!$omp end target
bad = 0
do i = 1, m
if (tid(i) /= mod((i - 1)/4, nthr)) bad = bad + 1
end do
! static without chunk: at most one chunk (contiguous) per thread
bad2 = 0
do i = 2, m
if (tid2(i) /= tid2(i - 1) .and. any(tid2(1:i - 1) == tid2(i))) bad2 = bad2 + 1
end do
print '(a,i0,a,12(1x,i0))', 'threads=', nthr, ' static,4 tid(1:12)=', tid(1:12)
print '(a,12(1x,i0))', 'static tid(1:12)=', tid2(1:12)
print '(a,i0,a,i0,a)', 'static,4 iterations on the wrong thread: ', bad, ' of ', m, ' (expected 0)'
print '(a,i0,a)', 'static: iterations starting a second chunk of a thread: ', bad2, ' (expected 0)'
end program sched_repro
Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page
Expected and observed
Observed where it behaves incorrectly
threads=256 static,4 tid(1:12)= 0 1 2 3 4 5 6 7 8 9 10 11 static tid(1:12)= 0 1 2 3 4 5 6 7 8 9 10 11 static,4 iterations on the wrong thread: 997 of 1000 (expected 0) static: iterations starting a second chunk of a thread: 744 (expected 0)
What the specification requires
The specification text this program relies on and the compiler is expected to support.
OpenMP 5.2 §11.5.3 p.252
iterations are divided into chunks of size chunk_size, and the chunks are assigned to the threads in the team in a round-robin fashion in the order of the thread number
Evidence
Same compiler, one change
- schedule(static, 1) and its check (iteration i on thread mod(i - 1, T)) instead of schedule(static, 4): AFAR 24.3.0: correct; CCE 19.0.0: correct; CCE 20.0.2: correct; CCE 21.0.3: correct; CCE 21.0.4: correct
Control program
program sched_repro use omp_lib implicit none integer, parameter :: m = 1000 integer :: tid(m), tid2(m), nthr, i, bad, bad2 tid = -1 tid2 = -1 nthr = -1 !$omp target map(from: tid, tid2, nthr) !$omp parallel do schedule(static, 1) do i = 1, m if (i == 1) nthr = omp_get_num_threads() tid(i) = omp_get_thread_num() end do !$omp end parallel do !$omp parallel do schedule(static) do i = 1, m tid2(i) = omp_get_thread_num() end do !$omp end parallel do !$omp end target bad = 0 do i = 1, m if (tid(i) /= mod((i - 1)/1, nthr)) bad = bad + 1 end do bad2 = 0 do i = 2, m if (tid2(i) /= tid2(i - 1) .and. any(tid2(1:i - 1) == tid2(i))) bad2 = bad2 + 1 end do print '(a,i0,a,12(1x,i0))', 'threads=', nthr, ' static,4 tid(1:12)=', tid(1:12) print '(a,12(1x,i0))', 'static tid(1:12)=', tid2(1:12) print '(a,i0,a,i0,a)', 'static,4 iterations on the wrong thread: ', bad, ' of ', m, ' (expected 0)' print '(a,i0,a)', 'static: iterations starting a second chunk of a thread: ', bad2, ' (expected 0)' end program sched_repro
Other compilers run it correctly
NVHPC 25.11, NVHPC 26.9, GCC 16.2.0