<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.snu.edu.in/index.php?action=history&amp;feed=atom&amp;title=Magus02%2FFAQ_Batch_Jobs</id>
	<title>Magus02/FAQ Batch Jobs - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.snu.edu.in/index.php?action=history&amp;feed=atom&amp;title=Magus02%2FFAQ_Batch_Jobs"/>
	<link rel="alternate" type="text/html" href="https://wiki.snu.edu.in/index.php?title=Magus02/FAQ_Batch_Jobs&amp;action=history"/>
	<updated>2026-11-04T19:44:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://wiki.snu.edu.in/index.php?title=Magus02/FAQ_Batch_Jobs&amp;diff=1188&amp;oldid=prev</id>
		<title>Deepak: Created page with &quot;{{DISPLAYTITLE:FAQ: Batch Jobs — Magus02 HPC}} &lt;div style=&quot;background:#0d1b2a;border:1px solid #1e3a5a;border-radius:8px;padding:12px 18px;margin-bottom:20px;font-size:13px;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.snu.edu.in/index.php?title=Magus02/FAQ_Batch_Jobs&amp;diff=1188&amp;oldid=prev"/>
		<updated>2026-04-20T06:46:26Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{DISPLAYTITLE:FAQ: Batch Jobs — Magus02 HPC}} &amp;lt;div style=&amp;quot;background:#0d1b2a;border:1px solid #1e3a5a;border-radius:8px;padding:12px 18px;margin-bottom:20px;font-size:13px;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:FAQ: Batch Jobs — Magus02 HPC}}&lt;br /&gt;
&amp;lt;div style=&amp;quot;background:#0d1b2a;border:1px solid #1e3a5a;border-radius:8px;padding:12px 18px;margin-bottom:20px;font-size:13px;font-family:monospace;color:#5ba3d9;&amp;quot;&amp;gt;&lt;br /&gt;
📍 [[Magus02/Knowledge_Base|Magus02 Knowledge Base]] → HPC User → FAQ: Batch Jobs&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This page covers the most common problems and misunderstandings when submitting jobs to Slurm on Magus02. All examples use Slurm syntax.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Why do I have to specify resource requirements? ==&lt;br /&gt;
&lt;br /&gt;
The Slurm scheduler needs to know at least three things about every job to decide where and when to run it:&lt;br /&gt;
&lt;br /&gt;
* '''Runtime''' — how long the job will run&lt;br /&gt;
* '''CPU cores''' — how many processing units are needed&lt;br /&gt;
* '''Memory''' — how much RAM is required&lt;br /&gt;
&lt;br /&gt;
Without these, Slurm cannot place your job correctly. For example, if you omit &amp;lt;code&amp;gt;--mem&amp;lt;/code&amp;gt;, a job requiring 500 GB of RAM might be scheduled to a node with only 64 GB, causing it to crash immediately.&lt;br /&gt;
&lt;br /&gt;
Think of Slurm as playing '''multidimensional Tetris''' — it needs to know the shape of your job (its resource footprint) to fit it efficiently into the available cluster capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background:#0d1a0d;border-left:4px solid #39d353;border-radius:6px;padding:14px 18px;margin:16px 0;font-size:14px;color:#80b880;&amp;quot;&amp;gt;&lt;br /&gt;
✅ &amp;lt;strong&amp;gt;Minimum required directives for every job:&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;#SBATCH --partition=&amp;lt;/code&amp;gt; (which queue)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;#SBATCH --time=&amp;lt;/code&amp;gt; (wall clock limit)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;#SBATCH --mem=&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--mem-per-cpu=&amp;lt;/code&amp;gt; (memory)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;#SBATCH --ntasks=&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;--nodes=&amp;lt;/code&amp;gt; (compute resources)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== My job starts but exits immediately with no output — what's wrong? ==&lt;br /&gt;
&lt;br /&gt;
'''Most likely cause:''' The output/error directory does not exist.&lt;br /&gt;
&lt;br /&gt;
Slurm writes your &amp;lt;code&amp;gt;stdout&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;stderr&amp;lt;/code&amp;gt; to files before your commands run. If the target directory does not exist, Slurm cannot open the file and immediately kills the job.&lt;br /&gt;
&lt;br /&gt;
Check your directives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#SBATCH --output=/path/to/output/directory/%j.out&lt;br /&gt;
#SBATCH --error=/path/to/error/directory/%j.err&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The directory &amp;lt;code&amp;gt;/path/to/output/directory/&amp;lt;/code&amp;gt; must exist before you submit the job. You '''cannot''' create it inside the jobscript with &amp;lt;code&amp;gt;mkdir&amp;lt;/code&amp;gt; — the directory must exist when Slurm tries to open the output file, which happens before any of your script commands run.&lt;br /&gt;
&lt;br /&gt;
'''Fix:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create the directory before submitting:&lt;br /&gt;
$ mkdir -p /path/to/output/directory/&lt;br /&gt;
$ sbatch myjobscript.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== My job sometimes runs fine, sometimes fails for no apparent reason — why? ==&lt;br /&gt;
&lt;br /&gt;
'''Most likely cause:''' You are relying on modules loaded in your interactive session rather than in the jobscript.&lt;br /&gt;
&lt;br /&gt;
When you load modules on the login node before submitting, those modules may or may not be inherited by the batch job — this is unreliable and system-dependent. Your job's success should never depend on what you happened to have loaded in your terminal.&lt;br /&gt;
&lt;br /&gt;
'''Fix:''' Begin every jobscript with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module purge&lt;br /&gt;
module load &amp;lt;every module your job needs&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures your job always loads exactly the right software, regardless of your interactive session state. It also makes your jobs '''reproducible''' — you can re-submit them months later and get the same result.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== I get &amp;quot;srun: Job step creation temporarily disabled&amp;quot; and my job times out doing nothing — why? ==&lt;br /&gt;
&lt;br /&gt;
'''Cause:''' Nested calls to &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;mpirun&amp;lt;/code&amp;gt; inside the same job.&lt;br /&gt;
&lt;br /&gt;
This happens when your jobscript calls &amp;lt;code&amp;gt;srun ./myprogram&amp;lt;/code&amp;gt;, but &amp;lt;code&amp;gt;myprogram&amp;lt;/code&amp;gt; is itself a script that calls &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;mpirun&amp;lt;/code&amp;gt; again internally. The inner call tries to allocate resources that the outer &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; has already taken — causing a deadlock.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Problematic jobscript:&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH ...&lt;br /&gt;
srun ./run_simulation.sh    # if run_simulation.sh calls mpirun, this deadlocks!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Fix:''' Check whether your program or wrapper script already invokes &amp;lt;code&amp;gt;mpirun&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; internally:&lt;br /&gt;
&lt;br /&gt;
* If it does: remove the outer &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; and call the script directly:&lt;br /&gt;
&amp;lt;pre&amp;gt;./run_simulation.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If your program is a true MPI binary (not a wrapper): keep &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;mpirun&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;mpirun -n $SLURM_NTASKS ./my_mpi_binary&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== My job is reported as COMPLETED but my scientific program actually failed — why? ==&lt;br /&gt;
&lt;br /&gt;
'''Cause:''' Slurm determines job success or failure from the '''exit code of your jobscript''', not from the exit code of programs called within it.&lt;br /&gt;
&lt;br /&gt;
The exit code of the whole script is the exit code of its '''last command'''. If you have commands after your main program (e.g. a file copy), their exit code overwrites your program's.&lt;br /&gt;
&lt;br /&gt;
=== Bad example ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH ...&lt;br /&gt;
./my_scientific_program input.dat    # fails with exit code 1&lt;br /&gt;
cp results.dat $HOME/archive/         # succeeds with exit code 0&lt;br /&gt;
# Slurm sees exit code 0 → marks job as COMPLETED, even though the program failed!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Correct approach: save and re-use the exit code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH ...&lt;br /&gt;
&lt;br /&gt;
./my_scientific_program input.dat&lt;br /&gt;
EXITCODE=$?                           # capture exit code immediately&lt;br /&gt;
&lt;br /&gt;
# Post-processing and cleanup:&lt;br /&gt;
cp results.dat $HOME/archive/&lt;br /&gt;
echo &amp;quot;Job finished at $(date)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
exit $EXITCODE                        # report actual program success/failure to Slurm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now Slurm will correctly show FAILED if your scientific program failed, even if all post-processing steps succeeded.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== My job is stuck in PD (Pending) — when will it run? ==&lt;br /&gt;
&lt;br /&gt;
A job stays Pending for several possible reasons:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width:100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background:#0d1b2a;color:#94a8be;&amp;quot; | Reason Code (squeue -u $USER)&lt;br /&gt;
! style=&amp;quot;background:#0d1b2a;color:#94a8be;&amp;quot; | Meaning&lt;br /&gt;
! style=&amp;quot;background:#0d1b2a;color:#94a8be;&amp;quot; | Action&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Resources&amp;lt;/code&amp;gt; || Waiting for enough nodes/cores to be free || Wait — will run when resources are available&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Priority&amp;lt;/code&amp;gt; || Higher-priority jobs ahead in the queue || Wait — or consider using a lower-priority queue like &amp;lt;code&amp;gt;low/long&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;QOSMaxJobsPerUser&amp;lt;/code&amp;gt; || You have hit the maximum number of running jobs for your queue || Wait for one of your running jobs to finish&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;QOSMaxCpuPerUser&amp;lt;/code&amp;gt; || You have hit the core limit for your user in this partition || Request fewer cores, or wait&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;InvalidQOS&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;PartitionNodeLimit&amp;lt;/code&amp;gt; || You requested more resources than the partition allows || Reduce &amp;lt;code&amp;gt;--nodes&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--ntasks&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;--mem&amp;lt;/code&amp;gt;; check partition limits&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Check why your job is pending:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ squeue -u $USER -o &amp;quot;%.10i %.12j %.8T %.12R&amp;quot;&lt;br /&gt;
# %R shows the reason code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== How do I check how much memory my job actually used? ==&lt;br /&gt;
&lt;br /&gt;
After your job completes, use &amp;lt;code&amp;gt;sacct&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Show memory usage and elapsed time for a completed job:&lt;br /&gt;
$ sacct -j JOB_ID --format=JobID,Elapsed,MaxRSS,MaxVMSize,State,ExitCode&lt;br /&gt;
&lt;br /&gt;
# MaxRSS = peak real memory used (in kilobytes)&lt;br /&gt;
# MaxVMSize = peak virtual memory used&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use this information to tune your &amp;lt;code&amp;gt;--mem&amp;lt;/code&amp;gt; requests for future jobs — requesting too much wastes allocation; requesting too little risks OOM (Out Of Memory) kills.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [[Magus02/Batch_Scheduler|Batch Scheduler — Job Submission Guide]]&lt;br /&gt;
* [[Magus02/Scheduling_Basics|Scheduling Basics]]&lt;br /&gt;
* [[Magus02/Modules|Environment Modules]]&lt;br /&gt;
* [[Magus02|Magus02 Main Page — Queue Structure]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-family:monospace;font-size:11px;color:#484f58;text-align:right;&amp;quot;&amp;gt;&lt;br /&gt;
[[Magus02/Knowledge_Base|↑ Back to Knowledge Base]] · Maintained by HPC Administration · wiki.snu.edu.in&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Deepak</name></author>
	</entry>
</feed>