Skip to content

Getting Started

Exercises

  1. Write and submit a simple job script

Create a file called first_job.sh that prints the hostname, the current date, and your username. Include #SBATCH directives for job name, output file, time limit (5 minutes), 1 task, and 1G of memory. Submit it with sbatch.

Hint / Solution
cat > first_job.sh << 'EOF'
#!/bin/bash
#SBATCH --job-name=first_job
#SBATCH --output=first_job_%j.out
#SBATCH --time=00:05:00
#SBATCH --ntasks=1
#SBATCH --mem=1G

echo "Hostname: $(hostname)"
echo "Date: $(date)"
echo "User: $USER"
EOF

sbatch first_job.sh
  1. Check your job status

After submitting the job above, use squeue to check whether your job is pending or running. Note the job ID, state, and which node it was assigned to.

Hint / Solution
squeue --me
  1. Find and read the output file

Once the job completes (it should finish quickly), find the output file and display its contents. The filename pattern includes the job ID.

Hint / Solution
# List matching output files
ls first_job_*.out

# Read the most recent one
cat first_job_<jobid>.out
  1. Check job accounting after completion

Use sacct to look up your completed job. Display the job ID, job name, elapsed time, state, and exit code.

Hint / Solution
sacct -j <jobid> --format=JobID,JobName,Elapsed,State,ExitCode
  1. Explore the cluster

Use sinfo to determine how many partitions are available, which partition is the default, and what the maximum time limit is for each partition.

Hint / Solution
sinfo
The default partition is marked with `*` in the PARTITION column. The TIMELIMIT column shows the maximum walltime for each partition.

References