HPC/Submitting and Managing Jobs: Difference between revisions

From CNM Wiki
< HPC
Jump to navigation Jump to search
 
(107 intermediate revisions by the same user not shown)
Line 1: Line 1:
== User environment ==
[[Image:HPC job flow.png|right|400px|thumb|Processing flow of a typical job.]]
We use the [http://modules.sourceforge.net/ environment-modules] package to manage user applications.
__TOC__
Learn more at [[HPC/Software/Environment]].
== Introduction ==
To accept and run jobs, Carbon uses the [http://en.wikipedia.org/wiki/TORQUE_Resource_Manager Torque Resource Manager],
which is a variant of [http://en.wikipedia.org/wiki/Portable_Batch_System PBS].
A separate software component called a [http://en.wikipedia.org/wiki/Job_scheduler ''scheduler''] chooses the nodes and the start time for jobs according to the job parameters, resource availability, and configuration. Carbon uses the [http://www.adaptivecomputing.com/resources/docs/mwm/6-1-9/help.htm Moab Workload Manager] as scheduler. The resources used by each job (primarily the CPU time) are tracked and managed by the
[http://www.adaptivecomputing.com/resources/docs/gold/index.php Gold Allocation Manager].


See also: '''[[HPC/Directories|directory configuration]]'''.
=== Job processing ===
A job consists of a [[#Job Script|job script]] and applications called therein. The figure at the top shows schematically how a typical job is processed.
Unless otherwise told, Torque will execute the job script on your behalf on the first node allocated by Moab,
in your <code>$HOME</code> directory, and typically using your login shell. It is the ''script's responsibility'' to:
* Change to a suitable working directory.
* Recognize and use the other nodes of the job.
** This is generally done by directing an [http://en.wikipedia.org/wiki/Message_Passing_Interface MPI] program to start on the nodes listed in the job's <code>$PBS_NODEFILE</code>.
** A job is perfectly free to run more than one program, such as several MPI programs in sequence.
* Set or propagate environment variables as needed to other nodes.


== Submitting jobs to Moab/Torque ==
=== Environment variables ===
[[Image:HPC job flow.png|right|400px|thumb]]
The handling of environment variables across the cores and nodes that a job uses varies with the capabilities and configuration choices of the various MPI implementations.
  qsub [-A accountname] [options] ''jobfile''
<!-- It is recommended not to rely on defaults, but rather to make expectations and requirements explicit. -->
For details on options:
  man qsub
  qsub --help


More details are at the  
* Variables usually are '''propagated core-to-core''' for all processes on the first node.
[http://www.adaptivecomputing.com/resources/docs/torque/ Torque Manual], in particular
* Variables usually are '''not propagated node-to-node.'''
the [http://www.adaptivecomputing.com/resources/docs/torque/commands/qsub.php qsub man page].
; Consequences:
* You must [[HPC/Software/Module Setup | '''configure modules and $PATH''']] in your <code>$HOME/.bashrc</code> file to help mpirun and other mechanisms locate your programs on each compute node. Otherwise mpirun will fail as soon as more than one node is involved, either by not finding the binary itself or some of its required shared libraries, or more insidiously, using different shared libraries.
* Both the variable <code>$PBS_NODEFILE</code> and the file it points to are only available on the first node.
* To propagate (export) environment variables, use mpirun/mpiexec. However, there is no standard or quasi-standard across MPI flavors.
** [http://www.open-mpi.org/doc/v1.4/man1/mpirun.1.php#sect17 OpenMPI's mpirun] selectively exports some variables and supports the <code>-x</code> flag to export additional variables.
** Intel's mpiexec/mpiexec.hydra offer <code>-envlist ''NAME,NAME,...''</code> instead. See Sec. 2.4 in the ''Reference Manual'' at [http://software.intel.com/en-us/articles/intel-mpi-library-documentation/].


The single main queue is <code>batch</code> and need not be specified.  All job routing decisions are handled by the scheduler. In particular, short jobs are accommodated by a daily reserved node and by ''backfill'' scheduling, i.e. "waving forward" while a big job waits for full resources to become available.
See also: [[HPC/Directories|directory layout]].


=== Debug queue ===
== Submitting and managing jobs ==
For testing job processing and your job environment, use <code>qsub -q debug</code> or <code>#PBS -q debug</code>.
=== Job Script ===
The queue accepts jobs under the following conditions
A job is described to Torque by a ''job script,'' which in most cases is a shell script containing directives for Torque.
nodes <= 2
* [[HPC/Submitting and Managing Jobs/Example Job Script | '''Example Job Script''']].
ppn <= 4
walltime <= 1:00:00


== Checking job status ==
=== Submission ===
To submit a job, use Torque's [http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/commands/qsub.htm qsub] command on a login node.
  qsub [-A accountname] [options] ''jobfile''
To review qsub operation and options, consult the following:
  man qsub
  qsub --help


Use the command [http://www.clusterresources.com/torquedocs21/commands/qstat.shtml qstat] (from PBS) or [http://www.clusterresources.com/products/mwm/moabdocs/commands/showq.shtml showq] (from [http://www.clusterresources.com/products/mwm/moabdocs/a.gcommandoverview.shtml Moab]):
; Advanced usage:
* You ''can'' submit follow-up jobs from within a parent job script while it runs on a compute node, but it may be better to leverage [http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/commands/qsub.htm#W job dependencies.]
* [http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/2-jobs/requestingRes.htm Requesting Resources]
* Alternatively, use Moab's [http://www.adaptivecomputing.com/resources/docs/mwm/6-1-9/Content/commands/msub.html msub] command.


; qstat [-u $USER]:
=== Queues ===
; showq [-u $USER]: regular output
See [[HPC/Submitting and Managing Jobs/Queues and Policies | Queues and Policies]].
; qstat -a:
; showq -n: ''alternate'' format (showing job names)


=== Getting extra information ===
=== Checking job status ===
; qstat -n [-1] ''jobnum'': Show nodes where a job runs.
Query your jobs using commands similar to those on other HPC clusters.
; qstat -f [''jobnum''] [-1]: ''Full'' information such as submit arguments and run directories. The "-1" option disables wrapping for long output lines.
You can use either [http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/12-appendices/commandsOverview.htm Torque commands]
; checkjob [-v] ''jobnum'': Get extended jobs status information – useful to diagnose problems with "stuck" jobs.
or [http://www.adaptivecomputing.com/resources/docs/mwm/6-1-9/Content/a.gcommandoverview.html Moab commands].
Both access the same information, but through different routes, and offer different display styles.


== Removing jobs ==
To get the regular output format:
To retract a queued job or terminate an already running job:
[http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/commands/qstat.htm qstat] [-u $USER]
  qdel ''jobnumber''
[http://www.adaptivecomputing.com/resources/docs/mwm/6-1-9/Content/commands/showq.html showq] [-u $USER]
To get an ''alternate'' format (e.g. showing job names):
qstat -a [-u $USER]
showq -n [-u $USER]
You can always use <code>-u $USER</code> to show only your jobs.


== Example job file ==
==== Getting extra information ====
Show the nodes where a job runs:
qstat -n [-1] ''jobnum''
Give ''full'' information such as submit arguments and run directories, and do not wrap long lines ("-1" is the digit "one"):
qstat -f [''jobnum''] [-1]
To diagnose problems with "stuck" jobs, use the <code>-s</code> option, or simply Moab's [http://www.adaptivecomputing.com/resources/docs/mwm/6-1-9/Content/commands/checkjob.html checkjob] command. The last few lines of output give ''past events'' of the job and its current status.
qstat -s ''jobnum''
checkjob -v ''jobnum''
To get estimates on when your job might start:
showstart [-e all] ''jobnum''


* sample job file for Infiniband interconnect (recommended):
==== Peeking at job output files ====
<syntaxhighlight lang="bash">
Each job has associated stdin and stderr streams which are gathered on its first node and are copied back only at job end time, according to the <code>#PBS</code> directives -e, -o, or -j [eo|oe]. If the user does explicitly capture any output in the script (using shell redirections <code>"&gt;"</code>) it can be difficult to assess a job's progress.
#!/bin/bash


##  Basics: Number of nodes, processors per node (ppn), and walltime (hhh:mm:ss)
To inspect these streams ''while the job is running'', and also to review a job's script, use the <code>qpeek</code> command:
#PBS -l nodes=5:ppn=8
qpeek ''jobnum''
#PBS -l walltime=0:10:00
qpeek -eo ''jobnum''
#PBS -N job_name
qpeek -s ''jobnum''
#PBS -A account
Read its manual page for full documentation:
qpeek --man
This command is a Carbon re-implementation of a Torque "contrib" script.


## File names for stdout and stderr.  If not set here, the defaults
To inspect a job's processes running on its compute nodes:
## are <JOBNAME>.o<JOBNUM> and <JOBNAME>.e<JOBNUM>
qpeek -p ''jobnum''
#PBS -o job.out
#PBS -e job.err


## send mail at begin, end, abort, or never (b, e, a, n)
=== Changing jobs after submission ===
#PBS -m ea
Use <code>[http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/commands/qalter.htm qalter]</code> to modify attributes of a job.
Only attributes specified on the command line will be changed.
If any of the specified attributes cannot  be modified for any reason, ''none'' of that job's attributes will be modified.
qalter [-l ''resource''] […] ''jobnumber'' …
qalter -A ''accountspec'' ''jobnumber'' …
* Most attributes can be changed only ''before'' the job starts. Others, notably [http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/commands/qsub.htm#-m mail options] and [http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/commands/qsub.htm#-W job dependencies] can be meaningfully adjusted after start.


# change into the directory where qsub will be executed
; Advanced usage:
cd $PBS_O_WORKDIR
* ''Extending'' the <code>walltime</code> resource of an already running job requires Torque administrator permission. You yourself can extend prior to running, and shorten always.  '''Warning:''' In either case, the new <code>walltime</code> limit will be measured from start, not as remaining time. If a new walltime limit is shorter than the elapsed time, the job will be killed right away.
* You cannot modify the job script itself after submission. You will have to remove and resubmit the job.
Contact me ([[User:Stern|stern]]) to arrange for interventions.


# count allocated cores
=== Removing jobs ===
NPROCS=`wc -l < $PBS_NODEFILE`
To retract a queued job or kill an already running job:
  qdel ''jobnumber''
[http://www.adaptivecomputing.com/resources/docs/torque/4-1-4/Content/topics/12-appendices/prologueAndEpliogueScripts.htm Torque epilogue scripts] will immediately remove remaining user processes and user files from the used compute nodes upon job termination, be it natural or after qdel.


# start MPI job over default interconnect
== Declaring that a job requires licenses ==
mpirun -machinefile $PBS_NODEFILE -np $NPROCS \
A job that is to run software that requires a commercial license must declare such to the job scheduler (software that decides when and on which nodes the job could start).
        programname
The job scheduler monitors known licenses for availability, and so will know which and how many licenses are available at any given time.
</syntaxhighlight>
* If your program reads from files or takes options and/or arguments, use and adjust one of the following forms
<syntaxhighlight lang="bash">
mpirun -machinefile $PBS_NODEFILE -np $NPROCS \
      programname  < run.in
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
mpirun -machinefile $PBS_NODEFILE -np $NPROCS \
      programname  -options arguments < run.in
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
mpirun -machinefile $PBS_NODEFILE -np $NPROCS \
      programname < run.in > run.out 2> run.err
</syntaxhighlight>


:In this form, anything after <code>programname</code> is optional. If you use specific redirections for stdout or stderr as shown (&gt;, 2&gt;), the job-global files <code>job.out, job.err</code> declared earlier will remain empty or only contain output from your shell startup files (which should really be silent), and the rest of your job script.
'''Note:''' License availability checks do not happen instantaneously but rather by polling, roughly once every minute.
* Infiniband (OpenIB) is the default (and fast) interconnect mechanism for MPI jobs. This is configured through the environment variable <code>$OMPI_MCA_btl</code>.
: This means that if you or another user happen to start a license-consuming application after the last check but before the relevant newly started job tries to access the same license, that job will terminate with a license failure.
* To select ethernet transport (e.g. for ''embarrasingly parallel'' jobs), specify an <code>-mca</code> option:
<syntaxhighlight lang="bash">
mpirun -machinefile $PBS_NODEFILE -np $NPROCS \
-mca btl self,tcp \
        programname
</syntaxhighlight>


=== The ''account'' parameter ===
=== One license type ===
The parameter for option <code>-A account</code> is in most cases the CNM proposal, specified as follows:
To request a single license token of a single type, use a <code>gres</code> ("general resource") directive:
; <code>cnm123</code>: (3 digits) for proposals below 1000
#PBS -l '''gres'''=''license_name''
; <code>cnm01234</code>: (5 digits, 0-padded) for proposals from 1000 onwards.
To request several tokens of a type, place either a <code>:</code> or <code>+</code> as separator, followed by the number of tokens required:
; <code>user</code>: (the actual string "user", ''not'' your user name) for a limited personal startup allocation
#PBS -l '''gres'''=''license_name:count''
; <code>staff</code>: for discretionary access by staff.


You can check your account balance in hours as follows:
For compatibility, the resource type <code>software</code> is accepted, but ''not for multiple types'' of licenses.
<syntaxhighlight lang="bash">
#PBS -l '''software'''=''license_name''
mybalance -h
#or
gbalance -u $USER -h
#PBS -l '''software'''=''license_name:count''
</syntaxhighlight>


== Node Types ==
=== Several license types ===
To request several different licenses, use <code>gres</code> with list of license tokens and their optional counts separated by <code><font color="#1A1">'''%'''</font></code>:
#PBS -l gres=''license1_name''<font color="#1A1">'''%'''</font>''license2_name''
#PBS -l gres=''license1_name:count1''<font color="#1A1">'''%'''</font>''license2_name''


=== Hardware ===
The <code>software</code> resource ''cannot'' request multiple license types.
(If several <code>software</code> resources are requested, only the ''last one'' would be active.)


Carbon has two major [[HPC/Hardware Details | node types]], called '''gen1''' and '''gen2''', and gen2 is further differentiated by the amount of memory.
== Interactive node access ==
There are two ways to interactively access nodes:
* Requesting an interactive job
  qsub -I [-l nodes=…]
: This is a special Torque job submission that will wait for the requested nodes to become available, and then you will be dropped into a login shell on the first core of the first node. $PBS_NODEFILE is set as in regular (non-interactive) jobs.
* Side-access a node that already runs a job, such as to debug or inspect running processes or node-local files.
: You can use <code>ssh</code> to interactively access any compute node on which a job of yours is running (use <code>qsub -n ''jobnum''</code> to find out the node names). As soon as a node no longer runs at least ''one'' of your jobs, your ssh session to that node will be terminated. You may find the following commands helpful:
/usr/sbin/lsof -u $USER
/usr/sbin/lsof -c ''command_name''
/usr/sbin/lsof -p ''pid''
: - '''l'''i'''s'''t '''o'''pen '''f'''iles; [http://linux.die.net/man/8/lsof man page.]
ps -fu $USER
: - list your own processes.
psuser
: - a Carbon-specific wrapper for [http://linux.die.net/man/1/ps ps] to list user-only processes (yours and other regular users', excluding system processes).


{{Template:Table of node types}}
== Job notification mails ==
You can request a notification message to be sent to you when a job begins, ends, or aborts. The message is rather terse and looks like this:
'''Subject:''' PBS Job 281399.sched1.carboncluster
PBS Job Id: 281399.sched1.carboncluster
Job Name:  test.job
Exec host:  n103/0
Execution terminated
Exit_status=0
resources_used.cput=00:03:00
resources_used.mem=123kb
resources_used.vmem=240kb
resources_used.walltime=00:03:04


Benchmarks show that gen2 nodes are about twice as fast as gen1 nodes for memory-intensive applications. (The X5300 series is hampered by a memory bandwidth bottleneck when all 8 cores are active and frequently access memory.)  Thus, gen1 nodes are charged at a discounted rate of 50% of the walltime actually used.
In the above, Exit_status=0 reflects the shell exit status, where 0 means success.


=== Selecting node types for jobs ===
The following means your job was terminated because it ran beyond its allocated walltime:
Exit_status=271
: The shell exit status is this number mod 256, in this case <code>271 % 256 = 15</code>, corresonding to <code>SIGTERM</code>.


Jobs are directed automatically onto either gen1 or gen2 nodes, with preference for gen2 if both are available. Unless specifically requested, jobs will never mix generations. This will avoid disparate CPU speeds and MPI communication setup in a job.  You ''can'' force jobs onto either node set in the job script after <code>#PBS</code> or on the <code>qsub</code> command line by suffixing the <code>nodes=</code> specifier with a ''property'' such as <code>:gen1</code> or <code>:gen2</code>.  For example, to run on 2 nodes with 8 cores each:
== Recording where a job ran ==
The [[#Job notification mails]] explained above do not include $PBS_O_WORKDIR. You will have to arrange for yourself to record that information.
One way to do that would be to simply record all job numbers and their working directories at the beginning of each job:
<source lang="bash">
#!/bin/bash
#PBS -l nodes=
#PBS -l walltime=…
#PBS -m bea


<syntaxhighlight lang="bash">
cd $PBS_O_WORKDIR
qsub -l nodes=2:ppn=8:gen1  foo.job # not recommended for VASP
echo $PBS_JOBID $PWD >> $HOME/jobdirs
qsub -l nodes=2:ppn=8:gen2  foo.job
</syntaxhighlight>
 
The following are (as of now) equivalent, since "bigmem" currently implies "gen2":
 
<syntaxhighlight lang="bash">
qsub -l nodes=2:ppn=8:gen2:bigmem  foo.job
qsub -l nodes=2:ppn=8:bigmem      foo.job
</syntaxhighlight>
 
See also:
http://www.clusterresources.com/torquedocs21/2.1jobsubmission.shtml#resources
 
* [[HPC/Software/Catalog/vasp | '''Special note for VASP''']]
 
== PPN Tricks ==
Each ''Carbon'' node has 8 cores, and for many jobs users indeed request entire nodes by specififying <code>ppn=8</code> in the job submission.
However, you may need to request fewer cores, e.g. for the following reasons:
* your application is not parallelized,
* your application has limited hardcoded parallelization, e.g. for 2 or 4 cores only,
* your application runs multi-threaded but uses <code>$PBS_NODEFILE</code> to infer the number of processes to start,
* your application runs busy service processes or service threads (e.g. NWChem),
* your application saturates a resource, e.g. memory bandwidth (some large VASP calculations),
* the node's memory is exhausted by fewer application processeses than there are cores available.
Depending on the reason, the node either may be or must ''not'' be used by other jobs.
In the past, the only way to achieve exclusive but undersubscribed node access was to request <code>ppn=8</code> and then to ''thin out'' a copy of the nodefile before passing it to the application.
To eliminate the need to edit the nodefile, use the <code>-l naccesspolicy=…</code> flag to differentiate between resources ''requested from Moab'' from those ''passed to the application'' (in $PBS_NODEFILE).
<!--
You can control the following aspects of your job:
; Resources requested from Moab:
: <code>-l nodes=''nnn'':ppn=''m''<nowiki>[</nowiki>:''feature''<nowiki>[</nowiki>:''feature''<nowiki>]]</nowiki></code>
: <code>-l naccesspolicy=''value''</code>
; Resources passed to the application:
:* <code>$PBS_NODEFILE</code> – for MPI
:* <code>$OMP_NUM_THREADS</code> – for OpenMP multithreading


As part of the job startup procedure PBS will generate a <code>$PBS_NODEFILE</code> containing the name of each allocated node exactly ''ppn'' times, e.g. for a job with
#PBS -l nodes=2:ppn=4
</source>
PBS will produce a nodefile like this:
To query a job's directory, run:
  n011
  grep ''jobnumber'' ~/jobdirs
n011
n011
n011
n037
n037
n037
n037
-->


Select an option from the following scenarios.
== Sending mail while a job is running ==
=== Shared vs. Exclusive Node Access ===
It may be useful to have a job automatically "phone home" sometime after it started.
; Permit other users and jobs:
This can be accomplished at job submission time by arranging a mail to be sent, using a few added commands in the job script.
: When a job requires only a few cores and a commensurate fraction of other resources, simply specify <code>ppn</code> as needed:
#PBS -l nodes=''nnn'':ppn=4
: In this case, the remaining cores may be allocated to other jobs, which is the ''default'' policy:
#PBS -l '''[http://www.adaptivecomputing.com/resources/docs/mwm/5.3nodeaccess.php naccesspolicy]=SHARED'''
; Permit only your own jobs:
#PBS -l nodes=''nnn'':ppn=2
#PBS -l '''naccesspolicy=SINGLEUSER'''
; Permit only ''one'' job per node, no sharing:
: When your job requires only a few cores but a disproportionate fraction of another resource on a node (such as most of its memory or a lot of I/O bandwidth), claim the entire node:
#PBS -l nodes=''nnn'':ppn=4
#PBS '''-l naccesspolicy=SINGLEJOB'''
: PBS will reserve the entire node(s), but place each node name only <code>ppn</code> times in the <code>$PBS_NODEFILE</code>. This is also useful for MPI+OpenMP ("hybrid") programming, see below.
; Permit only one of ''your'' jobs, and permit other user's jobs:
#PBS -l nodes=''nnn'':ppn=4
#PBS '''-l naccesspolicy=UNIQUEUSER'''
: The node is shared, but limited to one job for any given user.


=== Different PPN by node ===
: When your first MPI process (the "master" process) requires more memory than your other "worker" processes, give several <code>nodes</code> specifications, separated by a <code>"+"</code> character (which is unusal and born of historical necessity):
#PBS -l nodes=1:ppn=1+2:ppn=4
#PBS -l naccesspolicy=SINGLEJOB
: For clarity, the <code>nodes</code> specification in this example reads as follows:
<font color="#888">nodes = ( 1:ppn=1 ) + ( 2:ppn=4 )</font>
: This will request 3 node exclusively, but the first node will occur only ''once'' in the <code>$PBS_NODEFILE</code>, e.g.
n011
n012
n012
n012
n012
n034
n034
n034
n034
In all of the preceding scenarios the following applies:
* The <code>$PBS_NODEFILE</code> seen by the job script will always match <code>ppn</code>.
* For accounting, the job will be ''billed'' by the number of cores blocked from use by other users, i.e., <code>ncores=ppn</code> for shared nodes, and <code>ncores=8</code> otherwise.
== Multithreading (OpenMP) ==
When you wish to use multithreading, you must ensure that the total number of "busy" user threads and processes corresponds to the number of cores requested from PBS. Today, multithreading in applications and libraries is typically programmed using the [http://en.wikipedia.org/wiki/OpenMP OpenMP interface] and the number of threads is controlled by the environment variable <code>$OMP_NUM_THREADS</code>.
Select from the following scenarios.
; Pure OpenMP, single entire node:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
#PBS -l nodes=1:ppn=8
#!/bin/bash
#PBS


cd $PBS_O_WORKDIR
cd $PBS_O_WORKDIR
export OMP_NUM_THREADS=8
...
</syntaxhighlight>
; Pure OpenMP, single node, possibly shared:
: choose the number of cores <code>''n''</code> such that <code>1 ≤ ''n'' ≤ 8</code>:
<syntaxhighlight lang="bash">
#PBS -l nodes=1:ppn=''n''
...
cd $PBS_O_WORKDIR
export OMP_NUM_THREADS=`uniq -c $PBS_NODEFILE | awk '{print $1; exit}'`
...
</syntaxhighlight>
: Here, the default policy "SHARED" is in effect, and OMP_NUM_THREADS is set automatically by counting the number of times that the first node occurs in <code>$PBS_NODEFILE</code>. This will allow you to vary or override the ''nodes'' setting using "qsub -l nodes=…" without having to edit it twice in the job file.
; [http://www.google.com/search?hl=en&rls=en-us&q=MPI+OpenMP OpenMP/MPI hybrid]:
: Making efficient use of multithreading on multiple nodes which communicate over MPI is fairly involved and is subject to ongoing research. Since <code>OMP_NUM_THREADS</code> is set to 1 by default on MPI satellite nodes, you must export this variable after you altered it in the job file.
<syntaxhighlight lang="bash">
#!/bin/bash
#PBS -l nodes=''nnn'':ppn=4
#PBS -l naccesspolicy=SINGLEJOB


# Calculate number of threads available per MPI process
# arrange notification mail
ppn_mpi=$( uniq -c $PBS_NODEFILE | awk '{print $1; exit}' )
(
ppn_phys=$( grep -c ^processor /proc/cpuinfo )
    sleep 600 # time offset parameter, in seconds
OMP_NUM_THREADS=$(( ppn_phys / ppn_mpi ))
    tail -20 somefile.out | mailx -s "$PBS_JOBID: partial log" $USER
) &


mpirun -x OMP_NUM_THREADS \
# main work here
    -machinefile  $PBS_NODEFILE \
    -np $(wc -l < $PBS_NODEFILE) \
   
</syntaxhighlight>
</syntaxhighlight>
The <code>-x</code> option is specific to OpenMPI; please consult the documentation to achieve the same behavior in other MPI implementations.


The last example will ensure:
Explanation:  
* you get allocated entire nodes (SINGLEJOB policy)
* The commands inside <code>( ) &</code> run in a background track aside the main work.
* you do not oversubscribe cores (OMP_NUM_THREADS is calculated from ppn)
* The first command, <code>sleep</code>, delays further action (in this track only) by the specified time in seconds.
* you only have one place to adjust (ppn), and can do so in the command line, or even post submission
** To emphasize minutes, write <code>sleep $(( 10 * 60 ))</code> .
 
** To set the time relative to the walltime limit, leverage the <code>$PBS_WALLTIME</code> variable, e.g. as in <code>sleep $(( PBS_WALLTIME - ( ''minutes'' * 60 ) )).</code>
It is assumed:
* The <code>tail</code> command is a stand-in for any inspection command you might want to run. An even simpler command could be <code>ls -lt</code>. You could also use several commands enclosed by parentheses, <code>( cmd1; cmd2; ... )</code>, to construct a more elaborate mail body.
* The number of cores on the first node (running the job script) is the same as on the other nodes.
* The <code>mailx</code> command, following the pipe symbol <code>|</code>, reads the output of your inspection command and sends you a mail with the subject specified by the <code>-s</code> option.
 
* If the main part of the job finishes before the pre-mail sleep is over no mail will be sent.
== Interactive node access ==


* You can use <code>ssh</code> to interactively access any compute node on which a job of yours is running. As soon as a node no longer runs at least one of your jobs, your ssh session to that node will be terminated.
Note: The Moab scheduler also supports [http://www.adaptivecomputing.com/resources/docs/mwm/6-1-9/Content/topics/triggers/triggersIndex.html triggers], but they run in a different environment, not on an allocated node.


[[Category:HPC|Getting Started]]
[[Category:HPC|Getting Started]]

Latest revision as of 21:10, May 12, 2023

Processing flow of a typical job.

Introduction

To accept and run jobs, Carbon uses the Torque Resource Manager, which is a variant of PBS. A separate software component called a scheduler chooses the nodes and the start time for jobs according to the job parameters, resource availability, and configuration. Carbon uses the Moab Workload Manager as scheduler. The resources used by each job (primarily the CPU time) are tracked and managed by the Gold Allocation Manager.

Job processing

A job consists of a job script and applications called therein. The figure at the top shows schematically how a typical job is processed. Unless otherwise told, Torque will execute the job script on your behalf on the first node allocated by Moab, in your $HOME directory, and typically using your login shell. It is the script's responsibility to:

  • Change to a suitable working directory.
  • Recognize and use the other nodes of the job.
    • This is generally done by directing an MPI program to start on the nodes listed in the job's $PBS_NODEFILE.
    • A job is perfectly free to run more than one program, such as several MPI programs in sequence.
  • Set or propagate environment variables as needed to other nodes.

Environment variables

The handling of environment variables across the cores and nodes that a job uses varies with the capabilities and configuration choices of the various MPI implementations.

  • Variables usually are propagated core-to-core for all processes on the first node.
  • Variables usually are not propagated node-to-node.
Consequences
  • You must configure modules and $PATH in your $HOME/.bashrc file to help mpirun and other mechanisms locate your programs on each compute node. Otherwise mpirun will fail as soon as more than one node is involved, either by not finding the binary itself or some of its required shared libraries, or more insidiously, using different shared libraries.
  • Both the variable $PBS_NODEFILE and the file it points to are only available on the first node.
  • To propagate (export) environment variables, use mpirun/mpiexec. However, there is no standard or quasi-standard across MPI flavors.
    • OpenMPI's mpirun selectively exports some variables and supports the -x flag to export additional variables.
    • Intel's mpiexec/mpiexec.hydra offer -envlist NAME,NAME,... instead. See Sec. 2.4 in the Reference Manual at [1].

See also: directory layout.

Submitting and managing jobs

Job Script

A job is described to Torque by a job script, which in most cases is a shell script containing directives for Torque.

Submission

To submit a job, use Torque's qsub command on a login node.

 qsub [-A accountname] [options] jobfile

To review qsub operation and options, consult the following:

 man qsub
 qsub --help
Advanced usage
  • You can submit follow-up jobs from within a parent job script while it runs on a compute node, but it may be better to leverage job dependencies.
  • Requesting Resources
  • Alternatively, use Moab's msub command.

Queues

See Queues and Policies.

Checking job status

Query your jobs using commands similar to those on other HPC clusters. You can use either Torque commands or Moab commands. Both access the same information, but through different routes, and offer different display styles.

To get the regular output format:

qstat [-u $USER]
showq [-u $USER]

To get an alternate format (e.g. showing job names):

qstat -a [-u $USER]
showq -n [-u $USER]

You can always use -u $USER to show only your jobs.

Getting extra information

Show the nodes where a job runs:

qstat -n [-1] jobnum

Give full information such as submit arguments and run directories, and do not wrap long lines ("-1" is the digit "one"):

qstat -f [jobnum] [-1]

To diagnose problems with "stuck" jobs, use the -s option, or simply Moab's checkjob command. The last few lines of output give past events of the job and its current status.

qstat -s jobnum
checkjob -v jobnum

To get estimates on when your job might start:

showstart [-e all] jobnum

Peeking at job output files

Each job has associated stdin and stderr streams which are gathered on its first node and are copied back only at job end time, according to the #PBS directives -e, -o, or -j [eo|oe]. If the user does explicitly capture any output in the script (using shell redirections ">") it can be difficult to assess a job's progress.

To inspect these streams while the job is running, and also to review a job's script, use the qpeek command:

qpeek jobnum
qpeek -eo jobnum
qpeek -s jobnum

Read its manual page for full documentation:

qpeek --man

This command is a Carbon re-implementation of a Torque "contrib" script.

To inspect a job's processes running on its compute nodes:

qpeek -p jobnum

Changing jobs after submission

Use qalter to modify attributes of a job. Only attributes specified on the command line will be changed. If any of the specified attributes cannot be modified for any reason, none of that job's attributes will be modified.

qalter [-l resource] […] jobnumber …
qalter -A accountspec jobnumber
  • Most attributes can be changed only before the job starts. Others, notably mail options and job dependencies can be meaningfully adjusted after start.
Advanced usage
  • Extending the walltime resource of an already running job requires Torque administrator permission. You yourself can extend prior to running, and shorten always. Warning: In either case, the new walltime limit will be measured from start, not as remaining time. If a new walltime limit is shorter than the elapsed time, the job will be killed right away.
  • You cannot modify the job script itself after submission. You will have to remove and resubmit the job.

Contact me (stern) to arrange for interventions.

Removing jobs

To retract a queued job or kill an already running job:

 qdel jobnumber

Torque epilogue scripts will immediately remove remaining user processes and user files from the used compute nodes upon job termination, be it natural or after qdel.

Declaring that a job requires licenses

A job that is to run software that requires a commercial license must declare such to the job scheduler (software that decides when and on which nodes the job could start). The job scheduler monitors known licenses for availability, and so will know which and how many licenses are available at any given time.

Note: License availability checks do not happen instantaneously but rather by polling, roughly once every minute.

This means that if you or another user happen to start a license-consuming application after the last check but before the relevant newly started job tries to access the same license, that job will terminate with a license failure.

One license type

To request a single license token of a single type, use a gres ("general resource") directive:

#PBS -l gres=license_name

To request several tokens of a type, place either a : or + as separator, followed by the number of tokens required:

#PBS -l gres=license_name:count

For compatibility, the resource type software is accepted, but not for multiple types of licenses.

#PBS -l software=license_name
#or
#PBS -l software=license_name:count

Several license types

To request several different licenses, use gres with list of license tokens and their optional counts separated by %:

#PBS -l gres=license1_name%license2_name
#PBS -l gres=license1_name:count1%license2_name

The software resource cannot request multiple license types. (If several software resources are requested, only the last one would be active.)

Interactive node access

There are two ways to interactively access nodes:

  • Requesting an interactive job
qsub -I [-l nodes=…]
This is a special Torque job submission that will wait for the requested nodes to become available, and then you will be dropped into a login shell on the first core of the first node. $PBS_NODEFILE is set as in regular (non-interactive) jobs.
  • Side-access a node that already runs a job, such as to debug or inspect running processes or node-local files.
You can use ssh to interactively access any compute node on which a job of yours is running (use qsub -n jobnum to find out the node names). As soon as a node no longer runs at least one of your jobs, your ssh session to that node will be terminated. You may find the following commands helpful:
/usr/sbin/lsof -u $USER
/usr/sbin/lsof -c command_name
/usr/sbin/lsof -p pid
- list open files; man page.
ps -fu $USER
- list your own processes.
psuser
- a Carbon-specific wrapper for ps to list user-only processes (yours and other regular users', excluding system processes).

Job notification mails

You can request a notification message to be sent to you when a job begins, ends, or aborts. The message is rather terse and looks like this:

Subject: PBS Job 281399.sched1.carboncluster

PBS Job Id: 281399.sched1.carboncluster
Job Name:   test.job
Exec host:  n103/0
Execution terminated
Exit_status=0
resources_used.cput=00:03:00
resources_used.mem=123kb
resources_used.vmem=240kb
resources_used.walltime=00:03:04

In the above, Exit_status=0 reflects the shell exit status, where 0 means success.

The following means your job was terminated because it ran beyond its allocated walltime:

Exit_status=271
The shell exit status is this number mod 256, in this case 271 % 256 = 15, corresonding to SIGTERM.

Recording where a job ran

The #Job notification mails explained above do not include $PBS_O_WORKDIR. You will have to arrange for yourself to record that information. One way to do that would be to simply record all job numbers and their working directories at the beginning of each job:

#!/bin/bash
#PBS -l nodes=…
#PBS -l walltime=…
#PBS -m bea

cd $PBS_O_WORKDIR
echo $PBS_JOBID $PWD >> $HOME/jobdirs

…

To query a job's directory, run:

grep jobnumber ~/jobdirs

Sending mail while a job is running

It may be useful to have a job automatically "phone home" sometime after it started. This can be accomplished at job submission time by arranging a mail to be sent, using a few added commands in the job script.

#!/bin/bash
#PBS …

cd $PBS_O_WORKDIR

# arrange notification mail
(
    sleep 600	# time offset parameter, in seconds
    tail -20 somefile.out | mailx -s "$PBS_JOBID: partial log" $USER
) &

# main work here

Explanation:

  • The commands inside ( … ) & run in a background track aside the main work.
  • The first command, sleep, delays further action (in this track only) by the specified time in seconds.
    • To emphasize minutes, write sleep $(( 10 * 60 )) .
    • To set the time relative to the walltime limit, leverage the $PBS_WALLTIME variable, e.g. as in sleep $(( PBS_WALLTIME - ( minutes * 60 ) )).
  • The tail command is a stand-in for any inspection command you might want to run. An even simpler command could be ls -lt. You could also use several commands enclosed by parentheses, ( cmd1; cmd2; ... ), to construct a more elaborate mail body.
  • The mailx command, following the pipe symbol |, reads the output of your inspection command and sends you a mail with the subject specified by the -s option.
  • If the main part of the job finishes before the pre-mail sleep is over no mail will be sent.

Note: The Moab scheduler also supports triggers, but they run in a different environment, not on an allocated node.