Compiling and running using -mp cause segfault

Dear Support,
A very simple question. I have a Fortran routine containing OpenMP pragmas and compiling and running well using pgf90. When I add -mp flag, it crashes in a segfault. SInce I’m not completely familiar with pgf90 what would be the best strategy to address this issue ? Thank you for your answer.
Best regards

Hi Roland,

It’s most likely a stack overflow. Try increasing your stack limit, or set the OpenMP environment variable “OMP_STACKSIZE” to a large value such as “128M”.

  • Mat

When I add -mp flag, it crashes in a segfault.

It’s most likely a stack overflow.

Yes, in my experience having a stack size that is too small causes a segmentation fault.

Along these same lines, it would be nice if some of the error messages were more specific and helpful. If in fact the stack size is too small, is it possible to have the code and exit with a message something like “stack size too small”? Segmentation faults can also occur if a variable of the wrong type is passed into a subroutine and the like. In that case, it would be nice to have a much more specific type of error message instead of just “segmentation fault”.


Hi Jerry,

Add the diagnostic flag “-Mchkstk” to have the compiler check if there is sufficient stack.

  • Mat

Dear Mat and Jerry,
This is also what I suspected. Do pgfortran set a stack limit as some other compilers do ? Besides, using

pgfortran -mp -Mchkstk file.f90 -o file.out

gives me

Error: in routine file there is a
stack overflow: thread 0, max 1793KB, used 553KB, request 2400256B

I’m still wondering how a unique thread can request such a large amount of memory although it seems not in the serial case. Any thoughts ?
Thank you for your help

Hi Roland,

In order to ensure each thread has a private copy, a routine’s local variables that when built without OpenMP support would have been allocated on the heap (such as automatics or sub-arrays passed as arguments) are now allocated on the stack. This increases the amount of stack memory used.

Note that this is common across all compilers which implement OpenMP.

  • Mat