wiki.ifm.liu.se

Documenting the world as we know IT

User Tools

Site Tools


mml:scripthelp

Wiki Example Scripts

Example scripts on this wiki follow a certain standard format, so that they are kept consistent and easy to adapt to running in different environments. The main idea is that at the top of the script, a few standard bash variables and functions are defined for the things that are done differently at different supercomputer centers.

Standard Script Functions / Variables

The submit_job bash function

This is a bash function meant to declared at the top of the example script which takes a single parameter, <job_name>, which is the name of the job to be queued on the cluster. The script writes a cluster submit script as “<job_name>.q” and fills it with instructions read on stdin.

Run parameters, like max running time, number of CPUs or similar are configured by editing the contents of this function.

Inside the script, this function is typically used like this:

submit_job mytestjob <<EOF
echo "test job starts"
$RUN_VASP5
echo "test job ends"
EOF

The standard implementation which works on NSC is this:

function submit_job {
cat > "${1-job}.q" <<EOF
#!/bin/bash
#SBATCH -A liu1
#SBATCH -p green
#SBATCH -t 23:59:59
#SBATCH -N 2
#SBATCH -J ${1-job}

echo "RUN STARTS: \$(date)"
$(cat -)
echo "RUN ENDS: \$(date)"
EOF
sbatch "${1-job}.q"
}

but you need to replace it with one that works on the cluster you are using.

Multiple submit_job for different types of jobs

Sometimes a script needs to submit more than one type of job. In that case there may be multiple submit_job functions named slightly different, e.g.,

  1. submit_job_single: submit on only one node
  2. submit_job_short: submit with a shorter time limit
  3. submit_job_long: submit with a longer time limit

Variables defining how to run codes

At the top of the script there will also be a declaration of bash variables specifying precisely how to run some specific code. For example:

RUN_VASP5="mpirun /path/to/vasp.5.2.12"

You may need to configure this to fit the cluster/environment on which you are trying to run the script.

Simple Example Script

This is the most basic example script you can do. It simply runs vasp5 once.

#!/bin/bash

function submit_job {
cat > "${1-job}.q" <<EOF
#!/bin/bash
#SBATCH -A liu1
#SBATCH -p green
#SBATCH -N 2
#SBATCH -t 23:59:59
#SBATCH -J ${1-job}

echo "RUN STARTS: \$(date)"
$(cat -)
echo "RUN ENDS: \$(date)"
EOF
sbatch "${1-job}.q"
}

RUN_VASP5="mpirun ~/bin/pvasp.5.2.12.vdw.wannier.mkl"

submit_job testjob <<EOF
echo "test job starts"
$RUN_VASP5
echo "test job ends"
EOF
mml/scripthelp.txt · Last modified: 2012-12-07 15:04 by rar