sbatch, squeue, scancel, sacct, and sinfo) that you’ll use throughout the rest of the tutorial series to run real training workloads on SUNK.
Prepare the job script
The most common approach to running jobs on Slurm is to submit job scripts to Slurm. Scripts typically consist of three sections:- Directives: Slurm directives begin with
#SBATCH. These directives specify which resources and settings Slurm uses to run the script. - Environment variables: Environment variables are the variables your application requires to run. In this section, load modules and set up environment variables such as
$PATHand$LD_LIBRARY_PATH. - Code: The actual code that runs your application.
Sbatch directives
Use#SBATCH directives to configure the job submission. Each directive specifies a different aspect of the job, such as its name, output files, time limits, and resource requirements. The following table summarizes some common directives:
| Directive | Description |
|---|---|
#SBATCH --job-name= | Sets the name of the job. Useful for locating it in status reports later |
#SBATCH --output= | Specifies the output file for standard output. You can use a full path, or one relative to the submission directory |
#SBATCH --error= | Specifies the output file for standard error |
#SBATCH --time= | Sets the time limit for the job. In the preceding example, 1 hour. If the job is still running after the specified duration, the job is stopped |
#SBATCH --nodes= | How many nodes the job should request. In the preceding example, 1 node |
#SBATCH --ntasks-per-node= | How many tasks per node this job should request. In the preceding example, 1 task per node |
#SBATCH --gres=gpu: | How many GPUs this task should request. In the preceding example, 1 GPU |
Submit the job
With the job script prepared, you’re ready to hand it off to the Slurm scheduler so it can be queued and run on the cluster. Submit your job to the Slurm queue by running the script usingsbatch. This command submits the my_job_script.sh script to the Slurm scheduler, and Slurm allocates resources to run your job based on the sbatch directives in the script. If resources matching these directives are available, the job may start immediately. Otherwise, it waits in a queue until other jobs finish.
Example command
371. Keep this job ID. You’ll use it to check status, cancel the job, or look up results later.
Example output
Check the job status
Once a job is submitted, you’ll want to know whether it’s still queued, running, or already finished. Slurm exposes that information through thesqueue command.
To check the status of your job, use the squeue command. The squeue command shows the status of all jobs in the cluster. To see a specific job, target the job ID from the submission command. In this example, where the job ID is 371, locate the job by running squeue 371.
You can also target jobs by the person who submitted them, identified by username, by running squeue -u myname.
Running squeue without any arguments shows all jobs in the queue, including their status, time running, and the nodes they are running on.
| Job state | Explanation |
|---|---|
PD | Job is pending. The Nodelist(reason) column details why. |
R | Job is running. The Nodelist(reason) column shows which nodes the job uses. |
CG/CD | Job has completed or is completing. |
F | The job has failed. |
TO | Because of a time out, Slurm terminated the job. The time limit is usually specified in the job script or partition configuration. |
For more detailed metrics on your job, view your job in the Slurm / Job Metrics Grafana Dashboard.
Cancel the job
If you submit a job in error or no longer need its results, you can stop it from running (or remove it from the queue) so it doesn’t consume cluster resources. To cancel your job, use thescancel command.
View job output
After your job finishes, you’ll typically want to inspect what it produced and check for any errors. Slurm collects standard output and error output in the files specified by the sbatch directives in the job script. After your job completes, you can view the output in these files.View cluster information
Before submitting more jobs, it’s often useful to understand what nodes and partitions are available, and which are already busy. To view more details about your cluster, use thesinfo command.
Example command
Example output
Node states
| Status | Description |
|---|---|
idle | Nodes are idle |
alloc | Nodes are fully allocated to jobs |
mix | Nodes are running jobs, but still have some available space |
View completed job history
Becausesqueue only shows recent jobs, you’ll need a different command to look up history for jobs that have already completed or failed.
The squeue command only shows job status while jobs are in a pending or running state, and for a few hours after completion. To see the status of a completed or failed job, use the sacct command instead.
Example command
Example output
- The line with a
JobIDof371and aJobNameofmy_jobdisplays the state of the entire job. - The line prefaced with a
JobIDof371.batchand aJobNameofbatchdisplays the state of the submitted script. - The final line, with a
JobIDof371.0and aJobNameofall_reduc+, displays the status of one of the tests CoreWeave runs after each job to confirm the cluster performs correctly. The test typically takes a few seconds to run.