Execute a Job: Python Example
The tutorial assumes you have already worked through the Execute a Job Tutorial. Therefore, the instructions here are abbreviated but will follow the same format so you may easily consult the extended tutorial.
Table of Contents
- Execute a Job: Python Example
- Step 1: Access Your Allocation
- Step 2: Create a PBS Script
- Step 3: Create a Python Program
- Step 4: Run the Job
📝 Note: Do not execute jobs on the login nodes; only use the login nodes to access your compute nodes. Processor-intensive, memory-intensive, or otherwise disruptive processes running on login nodes will be killed without warning.
Step 1: Access Your Allocation
If you need to request an allocation, see instructions here.
- Open a Bash terminal (or PuTTY for Windows users).
- Execute
ssh username@or-condo-login.ornl.gov
. - Replace "username" with your XCAMS or UCAMS ID.
- When prompted, enter your XCAMS or UCAMS password.
Step 2: Create a PBS Script
Example PBS Script
Here is an example PBS script for running a batch job on a SHPC Condo allocation.
#!/bin/bash
#PBS -N mpi_hello_world_py
#PBS -M your_email@ornl.gov
#PBS -l nodes=1:ppn=16
#PBS -l walltime=0:00:6:0
#PBS -W group_list=cades-birthright
#PBS -A birthright
#PBS -l qos=burst
#PBS -V
module purge
module load python/3.6.1
module list
cd $PBS_O_WORKDIR
pwd
mpirun python hello_world.py
PBS Procedure
- From the login node, change your working directory to the desired file system. We are going to use our Lustre allocation for this example. If Lustre storage is not available, you may complete this tutorial from within your home directory on NFS.
cd /lustre/or-scratch/cades-birthright/username
Replace "username" with your UCAMS/XCAMS user ID.
- Use Vi to create and edit your PBS script.
vi hello_world_py.pbs
- Create your PBS script within Vi or paste the contents of your PBS script into Vi.
- Save your file and return to the Bash shell.
Step 3: Create a Python Program
MPI Hello World Code
#!/usr/bin/env python
import sys
from mpi4py import MPI
size = MPI.COMM_WORLD.Get_size()
rank = MPI.COMM_WORLD.Get_rank()
name = MPI.Get_processor_name()
print("Hello, World! I am process ",rank," of ",size," on ",name)
Python Procedure
- Ensure that you are still in your working directory (
/lustre/or-scratch/cades-birthright/username
) usingpwd
. - Use Vi (
vi
) to create your C++ source file within your working directory.
vi hello_world.py
- Paste the hello world C++ code into Vi.
- Save your file and return to the Bash shell.
Python does not need to be compiled.
Step 4: Run the Job
-
Before proceeding, ensure that you are still in your working directory (using
pwd
) and that you still have the python/3.6.1 module loaded (usingmodule list
). -
We need to be in the same path/directory as our PBS script and our Python script. Use
ls -al
to confirm their presence. -
Use
qsub
to schedule your batch job in the queue.
qsub hello_world_py.pbs
This command will automatically queue your job using Torque and produce a six-digit job number (shown below).
143295.or-condo-pbs01
You can check the status of your job at any time with the checkjob
command.
checkjob 143295
You can also stop your job at any time with the qdel
command.
qdel 143295
- View your results.
You can view the contents of these files using themore
command followed by the file name.
more mpi_hello_world_py.o143295
Your output should look something like this (the output is truncated.):
Hello, World! I am process 11 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 13 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 12 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 0 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 15 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 19 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 7 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 16 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 3 of 20 on or-condo-c190.ornl.gov
Hello, World! I am process 9 of 20 on or-condo-c190.ornl.gov
.
.
.
- Download your results (using the
scp
command or an SFTP client) or move them to persistent storage. See our moving data section for help.