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

Bug with host associated array in contained subroutine with openmp

MarkBuehner
Beginner
900 Views

Hello,

First time post here... we seem to have encountered a problem when switching to a newer version of the compiler (ifx (IFX) 2025.1.0 20250317). Now array variables declared in the main program are not correctly seen in contained subroutines. But this only occurs when compiling with openmp. There is no problem for scalar variables. Here is a simple example:

program test

  implicit none
  save
  real(4), save :: arr1(2)
  real(4)       :: arr2(2)
  real(4) :: scalar

  ! Initialize to something obvious
  arr1 = -999.9
  arr2 = -999.9
  scalar = -123.4

  print *, "Before  :", scalar, arr1, arr2, loc(arr1), loc(arr2)
  call foo1()
  print *, "After   :", scalar, arr1, arr2, loc(arr1), loc(arr2)

contains

  subroutine foo1()
    implicit none
    print *, "Inside 1:", scalar, arr1, arr2, loc(arr1), loc(arr2)
  end subroutine foo1

end program

Below is the output when compiled with and without openmp. Sorry it's a bit messy. The important part is that with openmp the values of arr2 are zero inside the subroutine while they should be equal to -999.9.

By adding the "save" attribute with arr1 variable it seems we can trick the compiler into doing things correctly and it does equal -999.9 inside the subroutine.

The "loc()" function shows very different addresses for arr1 and arr2 in the body of the program whereas inside the subroutine loc(arr1) is the same as in the program, but loc(arr2) is completely different than in the program. 

$ ifx -O2 -fiopenmp test.f90 
$ ./a.out 
 Before  :  -123.4000      -999.9000      -999.9000      -999.9000    -999.9000                   4756992       140732410846224
 Inside 1:  -123.4000      -999.9000      -999.9000      0.0000000E+00
  0.0000000E+00               4756992               4757024
 After   :  -123.4000      -999.9000      -999.9000      -999.9000    
  -999.9000                   4756992       140732410846224

$ ifx -O2 test.f90 
$ ./a.out 
 Before  :  -123.4000      -999.9000      -999.9000      -999.9000    
  -999.9000                   4756960               4756928
 Inside 1:  -123.4000      -999.9000      -999.9000      -999.9000    
  -999.9000                   4756960               4756928
 After   :  -123.4000      -999.9000      -999.9000      -999.9000    
  -999.9000                   4756960               4756928

 Has this bug already been identified and corrected in a later version?

Thanks,

Mark

0 Kudos
1 Solution
Mark_Lewy
Valued Contributor I
766 Views

On Linux using IFX 2025.3.2 20260112, it looks like this bug is fixed:

 Before  :  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000                   4756960       140731586795424
 Inside 1:  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000                   4756960       140731586795424
 After   :  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000                   4756960       140731586795424

View solution in original post

4 Replies
andrew_4619
Honored Contributor III
868 Views
C:\temp>ifx /O2 /Qiopenmp testomp.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.3.0 Build 20251010
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.44.35214.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:testomp.exe
-subsystem:console
-defaultlib:libiomp5md.lib
-nodefaultlib:vcomp.lib
-nodefaultlib:vcompd.lib
testomp.obj

C:\temp>testomp
 Before  :  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000           140700539849984          303005957592
 Inside 1:  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000           140700539849984          303005957592
 After   :  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000           140700539849984          303005957592

C:\temp>

Windows + later version seems OK

 

MarkBuehner
Beginner
865 Views

Sorry, I didn't mention that I'm using Linux version. Not sure it makes a difference.

 

0 Kudos
andrew_4619
Honored Contributor III
856 Views
I could see you are using Linux, clearly my test changes more than one thing. You really need a Linux test on the latest version. Maybe if at is not an option for you someone else can test.
0 Kudos
Mark_Lewy
Valued Contributor I
767 Views

On Linux using IFX 2025.3.2 20260112, it looks like this bug is fixed:

 Before  :  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000                   4756960       140731586795424
 Inside 1:  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000                   4756960       140731586795424
 After   :  -123.4000      -999.9000      -999.9000      -999.9000
  -999.9000                   4756960       140731586795424
Reply