What is the gfortran flag equivalent for intel ifort's
-heap-arrays [size]
On the kinds of programs I run ifort is usually about 30% faster than gfortran.
Intel oneAPI is a cross-platform toolset that covers several programming languages including C, C++, Fortran and Python.
gfortran has many different command line options (also known as flags) that control what the compiler does and how it does it. To use these flags, simply include them on the command line when you run gfortran, e.g. $ gfortran -Wall -Wextra -c mysubroutine.f90 -o mysubroutine.o.
I've found this:
-fmax-stack-var-size=n This option specifies the size in bytes of the largest array that will be put on the stack; if the size is exceeded static memory is used (except in procedures marked as RECURSIVE). Use the option -frecursive to allow for recursive procedures which do not have a RECURSIVE attribute or for parallel programs. Use -fno-automatic to never use the stack. This option currently only affects local arrays declared with constant bounds, and may not apply to all character variables. Future versions of GNU Fortran may improve this behavior.
The default value for n is 32768.
from gfortran's website. I think it'll do the trick.
This is an old question, but the accepted answer is not fully correct and I would like to add context for future users like me who come across the post looking for answers.
I believe both intel's ifort
and gcc's gfortran
have some byte limit where arrays above said limit are not allocated on the stack, but instead are in static memory.
Intel's: -heap-arrays [size]
, will put any array bigger than [size]
kilobytes on the heap, instead of in static memory or on the stack depending on the size.
Gcc does not have this option and instead only has -fmax-stack-var-size=n
, where any variable above n
bytes is not placed on the stack. The documentation (https://gcc.gnu.org/onlinedocs/gfortran/Code-Gen-Options.html) says:
if the size is exceeded static memory is used (except in procedures marked as RECURSIVE).
The key difference here is that these large variables are NOT guaranteed to be placed on the heap.
Therefore the two options from intel and gcc are not identical, and more care needs to be taken to ensure large arrays in gfortran
are not shared in static memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With