HPC2N - Support - The Batch system: Example scripts

Job Script Examples

 

In the examples below, #'s are used as comments. In the case of a command to the batch system (starts with #PBS), one # must always be there, more will comment out the line.

The environment variable PBS_WORKDIR contains the directory you submitted your job script from.

Serial Job Script (akka)

#!/bin/bash
# Project to run under. Change to actual project 
# number delete if not needed 
#PBS -A SNICXXX-YY-ZZ
# Job name - makes it easier to find in the list 
# of running jobs
#PBS -N My_Serial_Job
# name of the output file
#PBS -o myjob.out
# name of the error file
#PBS -e myjob.err
# when to send email
#PBS -m ae

# asking for 1 node, 1 processor (serial job)
#PBS -l nodes=1:ppn=1
# the job can use up to 30 minutes to run
#PBS -l walltime=00:30:00

# change to the directory the job was submitted from
cd $PBS_O_WORKDIR

# run the job
./myjob

In the above script, the memory will be set to the default values, which are pmem=1900mb and pvmem=2000mb. You can ask for more memory, up to the maximim value for a node which is pmem=15800mb and pvmem=16000mb.

Parallel (MPI) job script (akka)

#!/bin/bash
# Project to run under. Change to actual project 
# number delete if not needed 
#PBS -A SNICXXX-YY-ZZ
# Job name - makes it easier to find in the 
# list of running jobs
#PBS -N My_Parallel_Job
# name of the output file
#PBS -o myjob.out
# name of the error file
#PBS -e myjob.err
# when to send email
#PBS -m ae

# asking for 2 nodes, 8 processors on each. 
# Asking for 8 processors assures no other
# job is running at the same node
#PBS -l nodes=2:ppn=8
# the job can use up to 30 minutes to run
#PBS -l walltime=00:30:00

# change to the directory the job was submitted from 
# and load the module for the compilers you wish to 
# use (here PathScale compilers with OpenMPI) 
cd $PBS_O_WORKDIR
module add openmpi/psc

# the program pingpong only works on two nodes or 
# cpus, -pernode makes sure that we only run one 
# pingpong per node

mpiexec -pernode ./pingpong

MPI Job script which also reports various things about the host and nodes it's running on

#!/bin/bash
# Project to run under. Change to actual project 
# number delete if not needed 
#PBS -A SNICXXX-YY-ZZ
# Job name - makes it easier to find in the list 
# of running jobs
#PBS -N My_Parallel_Job
# name of the output file
#PBS -o myjob.out
# name of the error file
#PBS -e myjob.err
# when to send email
#PBS -m ae

# Specify the number of cpus for your job.  
# Here we ask for 4 nodes and 4 processors (16 cpus)
#PBS -l nodes=4:ppn=4 

# the job can use up to 30 minutes to run
#PBS -l walltime=00:30:00

# You need to ask for maximim pmem/pvmem also, if you
# specify ppn, or you will not get all the memory of the node
# pmem should be about max_mem/4 and pvmem about 100mb larger
#PBS -l pmem=3900mb 
#PBS -l pvmem=4000mb

# Switch to the working directory; by default PBS 
# launches processes from your home directory.
# Jobs should only be run from the parallel file 
# system /pfs
echo Working directory is $PBS_O_WORKDIR
cd $PBS_O_WORKDIR 

# Load any needed modules. Here, OpenMPI for PathScale compilers. 
module load openmpi/psc 
 
echo Running on host `hostname`
echo Time is `date`
echo Directory is `pwd`
echo This jobs runs on the following processors:
# lists the allocated procesors 
echo `cat $PBS_NODEFILE`
# Define number of processors
NPROCS=`wc -l < $PBS_NODEFILE`
# And the number or hosts
NHOSTS=`cat $PBS_NODEFILE|uniq|wc -l`
echo This job has allocated $NPROCS cpus
 
mpiexec my_job

First, a few comments about memory for mixed OpenMP/MPI jobs.

The following shows which numbers you can put in your script. 8 is the number of processors on a node on Akka, and 15900 is the amount of pmem available, while 16000 is the maximum value for pvmem (pvmem should be about 100mb larger than pmem):
#PBS -l nodes=x:ppn=y
#PBS -l pmem=(15900/y)m 
#PBS -l pvmem=(16000/y)m
OMP_NUM_THREADS=z where y*z <= 8

If you ask for ppn=8, each process can get at most 2GB memory.

OpenMP job script, akka.

#!/bin/bash
# Project to run under. Change to actual project 
# number delete if not needed 
#PBS -A SNICXXX-YY-ZZ
# Job name - makes it easier to find in the list 
# of running jobs
#PBS -N My_OpenMP_Job 
# name of the output file
#PBS -o myjob.out
# name of the error file
#PBS -e myjob.err
# when to send email
#PBS -m ae

# asking for 1 node (and thus all processors on it)
#PBS -l nodes=1
# the job can run for up to 1 hour
#PBS -l walltime=1:00:00

# memory requirements, physical memory (pmem) 
# >= 1900 mb and <= 15900/(#processors)mb 
# virtual + physical memory  (pvmem) 
# >= 2000 mb and <= 16000/(#processors)mb
# defaults to pmem=1900 and pvmem=2000
#PBS -l pmem=15800mb
#PBS -l pvmem=16000mb

# change to the directory the job was submitted from 
# and load the module for the compilers you wish to 
# use (here PathScale compilers with OpenMPI) 
cd $PBS_O_WORKDIR

# set the number of threads for the OpenMP script and 
# then run the program (set threads to between 1 and 8)
export OMP_NUM_THREADS=4
./myjob 


OpenMP/MPI job script (akka)

#!/bin/bash
# Project to run under. Change to actual project 
# number delete if not needed 
#PBS -A SNICXXX-YY-ZZ
# Job name - makes it easier to find in the 
# list of running jobs
#PBS -N My_OpenMP_MPI_Job
# name of the output file
#PBS -o myjob.out
# name of the error file
#PBS -e myjob.err
# when to send email
#PBS -m ae

# asking for 2 nodes, 4 processors on each. 
#PBS -l nodes=2:ppn=4
# the job can use up to 30 minutes to run
#PBS -l walltime=00:30:00
# memory requirements, physical memory (pmem) 
# >= 1900 mb and <= 15900/(#processors)mb 
# virtual + physical memory  (pvmem) 
# >= 2000 mb and <= 16000/(#processors)mb
# defaults to pmem=1900 and pvmem=2000
#PBS -l pmem=2200mb
#PBS -l pvmem=2900mb

# change to the directory the job was submitted from 
# and load the module for the compilers you wish to 
# use (here PathScale compilers with OpenMPI) 
cd $PBS_O_WORKDIR
module add openmpi/psc

# set the number of threads for the OpenMP script and 
# then run the program 
# OMP_NUM_THREADS can be set to between 
# 1 and 8/(#processors) = 2 here
export OMP_NUM_THREADS=2

# PSC_OMP_AFFINITY should be set to FALSE 
# when mixing OpenMP and MPI, and is 
# only relevant for psc compilers
export PSC_OMP_AFFINITY=FALSE

# mpiexec is used to run your program, since it 
# has MPI commands. NEVER give the flag -np
# to mpiexec 
mpiexec ./myjob