|
Setting the Stack Size
09-May-2008
Introduction
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:
username@hostname:~> ulimit -a
core file size
(blocks, -c) 0
data seg
size
(kbytes, -d) unlimited
file
size
(blocks, -f) unlimited
pending
signals
(-i) 1024
max locked memory (kbytes, -l) 128
max memory size
(kbytes, -m) unlimited
open
files
(-n) 1024
pipe
size
(512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size
(kbytes, -s) 10240
cpu
time
(seconds, -t) unlimited
max user
processes
(-u) 16305
virtual memory
(kbytes, -v) unlimited
file
locks
(-x) unlimited
username@hostname:~>
ulimit -s 20480
|
For tcsh shell users, use the limit command as follows:
username@hostname:~> limit
cputime unlimited
filesize unlimited
datasize unlimited
stacksize 10240 kbytes
coredumpsize 0 kbytes
memoryuse unlimited
vmemoryuse unlimited
descriptors 1024
memorylocked 128 kbytes
maxproc 16305
username@hostname:~>
limit stacksize 20480
|
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 PBS Job
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:
#!/bin/bash
ulimit -s 20480
cd
some_dir
./my_exec
|
In the PBS script, use mpiexec to launch myjob.sh.
This will work even with MPI executables.
#!/bin/bash
#PBS -N Test
#PBS -l nodes=1:ppn=2
#PBS -M emailaddress@rice.edu
#PBS -V
#PBS -m abe
#PBS -o /home/username/directory
#PBS -e /home/username/directory
#
echo "I ran on:"
cat $PBS_NODEFILE
#
cd /home/username/directory
mpiexec ./myjob.sh
|
|