Skip to content

Slurm - Job Script Example 04 Python

An example for running a Python script as a job.

Code

Python script

The Python script is a file named myscript.py:

#!/usr/bin/env python3
import sys
import os

print("hello, world")

Then, make it executable:

[juser@picotte001]$ chmod +x myscript.py

Job script

The job script is a file named example04.sh, in the same directory as myscript.py:

#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem=128G
#SBATCH --account=something
#SBATCH --time=12:00:00

### Use the appropriate modulefile for your Python.
### If you have your own Anaconda installation, execute the
### conda environment script rather than loading the modulefile
module load python/gcc/3.9.1

./myscript.py

Job submission

Submit the job script:

[juser@picotte001 ~]$ sbatch example04.sh