llvm / llvm/llvm-project

[Flang][OpenMP] Combination of linear and schedule(dynamic) clauses causes incorrect behavior

Open
#211,439 1 comment 0 reactions 0 assignees View on GitHub
openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

This issue is similar to #61230. (As I am not an expert in OpenMP implementation, I cannot determine if this is an issue with libomp.)
When both `linear` and `schedule(dynamic)` clauses are specified for a worksharing-loop construct, the execution result is sometimes incorrect. I could not find any documented restrictions regarding this.

### Reproducer

* test.f90

```fortran
program main
implicit none
integer :: i,k
integer,parameter :: K_INCR = 2

k = 0
!$omp parallel do linear(k:K_INCR) schedule(dynamic)
do i = 1,100
k = k+K_INCR
end do
!$omp end parallel do

if (k/=200) print *,'Error :',k
print *,'pass'

end program main
```

* commands

```console
$ flang --version
flang version 24.0.0git (https://github.com/llvm/llvm-project.git ba9d799b1bf2433bf960a08ff995497f5b6d2feb)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp
$ ./a.out
pass
$ ./a.out
Error : 0
pass
$ ./a.out
Error : 1968281472
pass
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Disabling OpenMP.
* Replacing `schedule(dynamic)` with `schedule(static)` or `schedule(auto)`.
* Removing `schedule(dynamic)`.

## Other Compilers

* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gfortran test.f90 -fopenmp
$ ./a.out
pass
$ ./a.out
pass
$ ./a.out
pass
```

* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.

$ ifx -O0 test.f90 -qopenmp
$ ./a.out
pass
$ ./a.out
pass
$ ./a.out
pass
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling and repeatedly running the supplied test.f90 reproducer with flang -fopenmp, confirming the failure depends on linear with schedule(dynamic). Trace the Flang OpenMP handling for this worksharing-loop combination and compare the static and auto cases. Done means the reproducer consistently reports 200 without incorrect results, with coverage for the regression.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.