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

Getting stack overflow just by enabling openmp

Urbanic__John
Beginner
986 Views

I have a fairly simple code that I was attempting to add some OpenMP directives to. I am an experienced Linux command line OpenMP programmer (and MS VS C programmer), but this is my first experience using VS and Intel Fortran.

The serial code compiles/runs fine. As soon as I activate OpenMP via the Properties|Language|"Process OpenMP" dialog, the code throws stack overflow exceptions upon startup. With no OpenMP directives.

I have tried increasing the stack with "OMP_STACKSIZE=16M" as an environment variable, and I even switched to 64-bit compilation. Same thing.

Disable OpenMP and all is well.

Am I missing a magic configuration setting? Did I neglect to run some installation script? Maybe the default libs are an issue?

Grateful for suggestions in advance,

John

 

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
987 Views

On Windows, the total available stack is a property of the executable, set at link time. The OpenMP stack is taken from the regular stack.

In the project properties, set Fortran > Linker > System > Stack Reserve Size to a higher value (100000000 is a good start.) Don't set this much higher than needed, as it takes away from the 2GB space for code and data (even on x64).

You might also try setting the project property Fortran > Optimization > Heap Arrays to 0. This tells the compiler to use the heap for local and temporary arrays, but it may not help you here.

View solution in original post

3 Replies
Steve_Lionel
Honored Contributor III
988 Views

On Windows, the total available stack is a property of the executable, set at link time. The OpenMP stack is taken from the regular stack.

In the project properties, set Fortran > Linker > System > Stack Reserve Size to a higher value (100000000 is a good start.) Don't set this much higher than needed, as it takes away from the 2GB space for code and data (even on x64).

You might also try setting the project property Fortran > Optimization > Heap Arrays to 0. This tells the compiler to use the heap for local and temporary arrays, but it may not help you here.

Urbanic__John
Beginner
987 Views

Thanks, Steve, that 100MB stack solved the problem. Which is odd given that the total data structures on this test problem are less than 10MB. Maybe I will do some memory profiling later (but probably not since a few GB lost here or there seems to be nothing nowadays).

John

TimP
Honored Contributor III
987 Views

Among the reasons why thread stack size defaults to only 4MB is that each thread will use up that much of the total stack.  Attempting to take advantage of hyperthreads may be unproductive simply on account of the additional data used.  In case you haven't tried, setting OMP_NUM_THREADS to number of cores and OMP_PLACES=cores will enable you to check this.  The scheme to find out the number of cores is a bit more complicated (and not covered in many textbooks).

Building the main program with OpenMP enabled will cause some OpenMP startup to occur before any directives are encountered.  Presumably this helps performance, but immediately consumes stack.

0 Kudos
Reply