Oracle® Solaris Studio 12.4: OpenMP API User's Guide

Exit Print View

Updated: December 2014
 
 

2.3 Stacks and Stack Sizes

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