53
edits
(Added description of changes to configure Slurm for running batch jobs using the cluster) |
|||
# print task number
print('Hello! I am a task number: ', sys.argv[1])
We will save this python script as hello-parallel.py
=== Create Slurm Script ===
Next, we need to create a Slurm script to run the python program we just created:
#!/bin/bash
# Example of running python script with a job array
#SBATCH -J hello
#SBATCH -p debug
#SBATCH --array=1-10 # how many tasks in the array
#SBATCH -c 1 # one CPU core per task
#SBATCH -t 10:00
#SBATCH -o hello-%j-%a.out
# Run python script with a command line argument
srun python3 hello-parallel.py $SLURM_ARRAY_TASK_ID
We will save this Slurm script as hello-parallel.slurm
The first few lines of this file (with #SBATCH) are used to configure different parameters we want for the execution of the python script on the cluster.
For example, -J specifies job name, -p specifies the partition on which the cluster nodes are (for us the partition is named debug), --array specifies how many tasks we want, -c specifies number of CPU cores per task.
For more details on other command line options for sbatch for configuring the cluster, please visit [https://slurm.schedmd.com/sbatch.html Slurm Sbatch Documentation]
=== Run Script and Check Output ===
Now we are ready to run the script on the cluster, specifically on 10 nodes of the cluster. To run the slurm script, simply give the command:
$ sbatch hello-parallel.slurm
This should run our python script on 10 different nodes and generate output files in the same location. The output files will have an extension .out.
[[File:Slurm op.png|left|frameless|709x709px]]
We can view the output using the less command:
[[File:Slrm.png|left|frameless|447x447px]]
[[File:Slurm output.png|left|frameless]]
|
edits