Segment fault and Stacksize issue¶
If you get the runtime error message
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
It is likely that it is a stacksize issue.
From a discussion forum on the web
The most probable cause for this behaviour is that your stack size limit is too small (for whatever reason). Since variables are private to each OpenMP thread, one copy per thread is allocated on the thread stack (even if you have specified -heap-arrays!). 202000 elements of REAL(KIND=8) take 1616 kB (or 1579 KiB).
The stack size limit can be controlled by several mechanisms:
On standard Unix system shells the amount of stack size is controlled by ulimit -s
OpenMP supports control over the stack size limit of all additional threads via the environment variable OMP_STACKSIZE. Its value is a number with an optional suffix k/K for KiB, m/M ffor MiB, or g/G for GiB. This value does not affect the stack size of the main thread.
The GNU OpenMP run-time (libgomp) recognises the non-standard environment variable GOMP_STACKSIZE. If set it overrides the value of OMP_STACKSIZE.
The Intel OpenMP run-time recognises the non-standard environment variable KMP_STACKSIZE. If set it overrides the value of OMP_STACKSIZE and also overrides the value of GOMP_STACKSIZE if the compatibility OpenMP run-time is used (which is the default as currently the only available Intel OpenMP run-time library is the compat one).
If none of the *_STACKSIZE variables are set, the default for Intel OpenMP run-time is 2m on 32-bit architectures and 4m on 64-bit ones.
Note that thread stacks are actually allocated with the size set by _STACKSIZE (or to the default value), unlike the stack of the main thread, which starts small and then grows on demand up to the set limit. So don't set _STACKSIZE to an arbitrary large value otherwise you may hit the process virtual memory size limit.
addition Peter Woitke: on LinuX, under cshell, I am using
setenv GOMP_STACKSIZE 4G
limit stacksize unlimited
in my .cshrc. After going as high as 4GB for the openmp-memory, my problems with bus errors and segmentation faults disappeared.
on bash:
export GOMP_STACKSIZE=4G
ulimit -s unlimited
Your system administrator may have set a hard limit on the stack memory you can have.
Summary of stack management commands¶
| bash | csh/tcsh | |
|---|---|---|
| View soft limits | ulimit -S -a | limit |
| View hard limits | ulimit -H -a | limit -h |
| Set stack size to 128 MB | ulimit -S -s 131072 | limit stacksize 128m |
| Set stack to the maximum | ulimit -S -s unlimited | limit stacksize unlimited |
On a Mac, the OS sets a hard limit to 64MB and the soft limit is 8MB. The default limit on a linux system is 8MB.