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

Calling a function from a parallelized do concurrent loop

Eugene_S_1
Beginner
297 Views

Trying to compile my program in the release mode with parallelization, I've encountered a problem with calling a function, defined in a module. Here is the sample program to reproduce the problem:

program test
use test_mod
implicit none

integer, parameter :: N = 10
integer :: i
real :: a(N)

do concurrent (i = 1:N)
	a(i) = func(real(i))
end do

print *, a

end program

and the module:

module test_mod
implicit none

contains

pure function func(x)
	real, intent(in) :: x
	real :: func
	
	func = 1/x
end function

end module

When I compile it in the debug mode, the output is:

  1.000000      0.5000000      0.3333333      0.2500000      0.2000000
 0.1666667      0.1428571      0.1250000      0.1111111      0.1000000

but when I switch to the release mode, the output is just random garbage like this:

       Infinity       Infinity  8.3329765E-29  8.3329765E-29  5.9022872E+37
       Infinity  1.0935606E-33  1.1641040E-10  8.3330276E-29  8.3329765E-29

The command lines for release compilation are:

Compiling with Intel(R) Visual Fortran Compiler XE 14.0.1.139 [IA-32]...
ifort /nologo /O2 /Qparallel /module:"Release\\" /object:"Release\\" /libs:dll /threads /c /Qvc12 /Qlocation,link,"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\\bin" "d:\Projects\ParTest\ParTest\mmod.f90"
ifort /nologo /O2 /Qparallel /module:"Release\\" /object:"Release\\" /libs:dll /threads /c /Qvc12 /Qlocation,link,"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\\bin" "d:\Projects\ParTest\ParTest\main.f90"

What am I doing wrong? Thank you.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
297 Views

It works for me in 15.0.3. Please try a newer compiler. I don't see that you are doing anything wrong.

0 Kudos
Eugene_S_1
Beginner
297 Views

Thank you for the reply.

I have tried a newer compiler, and with 15.0.3.208 the problem is still there.

If I disable optimization (/Od /Qparallel) or add !dec$ noparallel before do concurrent, it works fine. With both options /O2 and /Qparallel it doesn't work. I'm puzzled...

0 Kudos
Steven_L_Intel1
Employee
297 Views

Ah, I see. It works ok if the function is in the same source file, but not if it's separate. Looks like an optimization bug - I will report this to the developers. Thanks for the nice test case. Issue ID is DPD200371514.

0 Kudos
Eugene_S_1
Beginner
297 Views

Thank you very much for help.

0 Kudos
Reply