Writing Batch Scripts
Categories: Running Jobs
Print this article
Batch scripts, or job submission scripts, are the mechanism by which a user submits and configures a job for eventual execution. A batch script is simply a shell script which contains:
- Commands that can be interpreted by batch scheduling software (e.g. PBS)
- Commands that can be interpreted by a shell
The batch script is submitted to the batch scheduler where it is parsed. Based on the parsed data, the batch scheduler places the script in the scheduler queue as a batch job. Once the batch job makes its way through the queue, the script will be executed on a service node within the set of allocated computational resources.
Sections of a Batch Script
Batch scripts are parsed into the following three sections:
- The Interpreter Line
The first line of a script can be used to specify the script’s interpreter. This line is optional. If not used, the submitter’s default shell will be used. The line uses the “hash-bang-shell” syntax:
- The Scheduler Options Section
The batch scheduler options are preceded by
#PBS, making them appear as comments to a shell. PBS will look for
#PBSoptions in a batch script from the script’s first line through the first non-comment line. A comment line begins with
#PBSoptions entered after the first non-comment line will not be read by PBS.Note: All batch scheduler options must appear at the beginning of the batch script.
- The Executable Commands Section
The shell commands follow the last
#PBSoption and represent the main content of the batch job. If any
#PBSlines follow executable statements, they will be ignored as comments.
The execution section of a script will be interpreted by a shell and can contain multiple lines of executable invocations, shell commands, and comments. When the job’s queue wait time is finished, commands within this section will be executed on a service node (sometimes called a “head node”) from the set of the job’s allocated resources. Under normal circumstances, the batch job will exit the queue after the last line of the script is executed.
An Example Batch Script
1: #!/bin/bash 2: # Begin PBS directives 3: #PBS -A pjt000 4: #PBS -N test 5: #PBS -j oe 6: #PBS -l walltime=1:00:00,nodes=1500 7: #PBS -l gres=atlas1%atlas2 8: # End PBS directives and begin shell commands 9: cd $MEMBERWORK/pjt000 10: date 11: aprun -n 24000 ./a.out
The lines of this batch script do the following:
|1||Optional||Specifies that the script should be interpreted by the bash shell.|
|2||Optional||Comments do nothing.|
|3||Required||The job will be charged to the “pjt000” project.|
|4||Optional||The job will be named “test”.|
|5||Optional||The job’s standard output and error will be combined.|
|6||Required||The job will request 1,500 compute nodes for 1 hour.|
|7||Optional||The job will require both the atlas1 and atlas2 Lustre® filesystems to be online.|
|8||Optional||Comments do nothing.|
|9||—||This shell command will the change to the user’s $MEMBERWORK/pjt000 directory.|
|10||—||This shell command will run the
|11||—||This invocation will run 24,000 MPI instances of the executable
Additional Example Batch Scripts
For more batch script examples, please see the Batch Script Examples page.
A node’s cores cannot be allocated to multiple jobs. Because the OLCF charges based upon the computational resources a job makes unavailable to others, a job is charged for an entire node even if the job uses only one processor core. To simplify the process, users are required to request an entire node through PBS.