Stacks are regions of memory where a data for a process is stored, such as process arguments and variables. When a function executes, it adds state data to the stack and removes it when the function terminates. Recursive function calls will continue to add data to the stack in a Last-In First-Out manner until the recursion ends and the functions terminate. If the stack allocated to your process is too small, your process will crash. Therefore it may be necessary to increase the size of the stack.
Increasing the Stack Size
For bash shell users, use the ulimit command to view or set the stack size as follows:
For tcsh shell users, use the limit command as follows:
These examples show the stack size as 10MB (10240 kbytes) and show it being set to a new size of 20MB (20480 kbytes). Some systems support setting the value to "unlimited" but this practice is not encouraged.
Setting the Stack Size in a SLURM Job Script
In order to set the stack size such that all of the compute nodes used in your job will see the new setting, follow the example below.
Create a shell script such as myjob.sh:
In the SLURM script, use srun to launch myjob.sh. This will work even with MPI executables.