Stacks are temporary memory address spaces used to hold arguments and automatic variables during an invocation of a subprogram or function. Stack overflow might occur if the size of a thread's stack is too small, causing silent data corruption or segmentation fault.
The executing program maintains a main stack for the initial (or main) thread executing the program. Use the limit C shell command or the ulimit Bourne or Korn shell command to display or set the stack size for the initial (or main) thread.
In addition, each OpenMP helper thread in the program has its own thread stack. This stack mimics the initial (or main) thread stack but is unique to the thread. The thread’s private variables are allocated on the thread stack. The default size of a helper thread stack is 4 Megabytes for 32-bit applications, and 8 Megabytes for 64-bit applications. Use the OMP_STACKSIZE environment variable to set the size of the helper thread stack.
Note that compiling Fortran programs with the -stackvar option forces the allocation of local variables and arrays on the stack as if they were automatic variables. -stackvar is implied with programs compiled with the -xopenmp, -xopenmp=parallel, or -xopenmp=noopt option. This could lead to stack overflow if not enough memory is allocated for the stack. Take extra care to ensure that the stacks are large enough.
Example for C shell:
% limit stacksize 32768 <- Sets the main thread stack size to 32 Megabytes % setenv OMP_STACKSIZE 16384 <- Sets the helper thread stack size to 16 Megabytes
Example for Bourne or Korn shell:
$ ulimit -s 32768 <- Sets the main thread stack size to 32 Megabytes $ OMP_STACKSIZE=16384 <- Sets the helper thread stack size to 16 Megabytes $ export OMP_STACKSIZE
-xcheck=stkovf[:detect | :diagnose]
If -xheck=stkovf:detect is specified, a detected stack overflow error is handled by executing the signal handler normally associated with the error.
If -xcheck=stkovf:diagnose is specified, a detected stack overflow error is handled by catching the associated signal and calling stack_violation(3C) to diagnose the error. If a stack overflow error is diagnosed, an error message is printed to stderr. This is the default behavior if only -xcheck=stkovf is specified.
See the cc(1), CC(1), or f95(1) man pages for more information about the -xcheck=stkovf compiler option.