my OpenMP program (Fortran, C or C++) segfaults upon or shortly after startup

All static arrays and variables are put on the stack (this ensures thread-safeness if -openmp is used). Hence one of the following needs to be done:

  • Increase the stack limit via e.g., ulimit -s 1000000 (for 1 GB of stack).

  • If you use the Intel compilers and the stack size is already adjusted, perform export OMP_STACKSIZE=32M to adjust the thread individual stack size to a higher value than the default 4 MB (here 32 MB).

  • Use the -heap-arrays option of the ifort compiler
  • Convert large static arrays to allocatable and allocate storage dynamically. For private entities this may not always be feasible, though.

Note that specifying -save (or the SAVE attribute for large arrays) may also be possible in some instances, but you need to check that no problems with thread-safeness ensue since SAVEd storage will be in shared scope by default. Also, there may be additional limits (e.g. within the kernel): do not count on being able to use more than 2 GByte on the stack even if limits are set appropriately on a 64 bit system.

  • No labels