Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
26 Views

Getting stack overflow just by enabling openmp

Jump to solution

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

Accepted Solutions
Highlighted
Black Belt Retired Employee
26 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

0 Kudos
3 Replies
Highlighted
Black Belt Retired Employee
27 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

0 Kudos
Highlighted
Beginner
26 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

0 Kudos
Highlighted
Black Belt
26 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