Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29612 Discussions

Issue with array allocation in C++ (ISO_Fortran_binding.h)

Diehl__Martin
Novice
45 Views

Minimal reproducer for an Intel oneAPI Fortran (ifx) bug observed in DAMASK (https://github.com/eisenforschung/DAMASK). In discretization_grid.f90 the line

materialAt_global = materialAt_global + 1

corrupted the material-ID array when compiled with oneAPI, while the array-section form materialAt_global(:) = materialAt_global(:) + 1 worked.

Pattern

  1. A BIND(C) subroutine declared as integer(C_INT), allocatable, intent(out) :: data(:) is called from Fortran.
  2. C allocates the array via CFI_allocate and fills it (fill.c).
  3. Fortran performs a whole-array assignment to the returned allocatable: a = a + 1.
  4. The whole unit is compiled with -fiopenmp.

With -fiopenmp, values in the LHS array are silently corrupted for arrays above a certain size (seen from ~4000 elements up; the failure is not monotonic in size — n=8000 passed in one run while n=4000 failed). Elements are overwritten with garbage. Without -fiopenmp, or with the array-section form, the result is correct.

Which (:) matters

Only the combination where both sides are whole-array triggers the bug; (:) on either side alone is sufficient to avoid it:

Form mismatches at n=29760

a = a + 1 (both whole)29712 BROKEN
a = a(:) + 1 (LHS whole)0 OK
a(:) = a + 1 (RHS whole)0 OK
a(:) = a(:) + 1 (both sect)0 OK

Reproduce

source /path/to/oneapi/setvars.sh
make run              # BROKEN: whole-array assignment with -fiopenmp
make run-workaround   # OK:     array-section assignment
make run-noopenmp     # OK:     whole-array assignment without -fiopenmp
make run-small        # OK:     small array (n=1000)
make run-variants     # LHS/RHS section combination matrix (n=29760)

Environment

  • ifx 2026.1.0 (20260617), icx 2026.1.0 (20260617)
  • oneAPI HPC toolkit 2026.1, Linux x86_64
  • Trigger flag: -fiopenmp (any -O level reproduces)
0 Kudos
0 Replies
Reply