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

ifort implicit do loop limit ?

KurtS
Beginner
322 Views

Hello,

I have implicit "do loops" in my source code that sometimes lead to:

> forrtl: severe (174): SIGSEGV, segmentation fault occurred
depending on the size of the loop - see following Fortran source:


program badalloc
integer, dimension ( : ), allocatable :: kixx
integer, dimension ( : ), allocatable :: kixy
ix = 2000000
iy = 2200000
allocate ( kixx(1:ix) )
allocate ( kixy(1:iy) )
print*,"done allocation"
kixx = (/ (i,i=1,ix) /)
print*,"done init kixx"
kixy = (/ (i,i=1,iy) /)
print*,"done init kixy"
end

Result when compiling and running with gfortran is OK:

> done allocation
> done init kixx
> done init kixy

 

when compiling with Ifort I get the following output :

> done allocation
> done init kixx
> forrtl: severe (174): SIGSEGV, segmentation fault occurred


Implicit loop runs fine for 2.000.000 but fails with higher values.

Is there some limitation for implicit loops in Ifort?
Or some compiler option to bypass such a limit?
Or some error in my source code?

Thanks

KurtS

Labels (2)
0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
276 Views

You're running out of stack to create the temporary for the array constructors. Add -heap-arrays (here it is on Windows.)

D:\Projects>ifx bad_alloc.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

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

-out:bad_alloc.exe
-subsystem:console
bad_alloc.obj
D:\Projects>bad_alloc.exe
forrtl: severe (170): Program Exception - stack overflow
Image              PC                Routine            Line        Source
bad_alloc.exe      00007FF6006B9897  Unknown               Unknown  Unknown
bad_alloc.exe      00007FF600681010  Unknown               Unknown  Unknown
bad_alloc.exe      00007FF600687DCB  Unknown               Unknown  Unknown
bad_alloc.exe      00007FF6006B9AA0  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFA4AA5E8D7  Unknown               Unknown  Unknown
ntdll.dll          00007FFA4BADBF6C  Unknown               Unknown  Unknown

D:\Projects>ifx /heap-arrays bad_alloc.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

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

-out:bad_alloc.exe
-subsystem:console
bad_alloc.obj

D:\Projects>bad_alloc.exe
 done allocation
 done init kixx
 done init kixy

D:\Projects>

 

View solution in original post

2 Replies
Steve_Lionel
Honored Contributor III
277 Views

You're running out of stack to create the temporary for the array constructors. Add -heap-arrays (here it is on Windows.)

D:\Projects>ifx bad_alloc.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

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

-out:bad_alloc.exe
-subsystem:console
bad_alloc.obj
D:\Projects>bad_alloc.exe
forrtl: severe (170): Program Exception - stack overflow
Image              PC                Routine            Line        Source
bad_alloc.exe      00007FF6006B9897  Unknown               Unknown  Unknown
bad_alloc.exe      00007FF600681010  Unknown               Unknown  Unknown
bad_alloc.exe      00007FF600687DCB  Unknown               Unknown  Unknown
bad_alloc.exe      00007FF6006B9AA0  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFA4AA5E8D7  Unknown               Unknown  Unknown
ntdll.dll          00007FFA4BADBF6C  Unknown               Unknown  Unknown

D:\Projects>ifx /heap-arrays bad_alloc.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

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

-out:bad_alloc.exe
-subsystem:console
bad_alloc.obj

D:\Projects>bad_alloc.exe
 done allocation
 done init kixx
 done init kixy

D:\Projects>

 

KurtS
Beginner
202 Views

Thanks - ifort /ifx compiler option "-heap-arrays" solve the problem on Linux too !

Reply