I am learning how to use supercomputers to make the good use of resources. Let's say I have a python script, that will create a text file with given random number.
myfile.py
# Imports
import random,os
outdir = 'outputs'
if not os.path.exists(outdir):
os.makedirs(outdir)
with open (outdir+'/temp.txt','w') as f :
a = random.randint(0,9)
f.write(str(a))
This will create only one text file in the local machine.
Is there any way I can use the multiple instances of this program, use multiple nodes and get multiple outputs?
I got a template for mpiexec in C program which looks like this, but I could not find any template for python program.
#PBS -N my_job
#PBS -l walltime=0:10:00
#PBS -l nodes=4:ppn=12
#PBS -j oe
cd $PBS_O_WORKDIR
mpicc -O2 mpi-hello.c -o mpi-hello
cp $PBS_O_WORKDIR/* $PFSDIR
cd $PFSDIR
mpiexec ./mpi-hello
cp $PFSDIR/* $PBS_O_WORKDIR
Note: On a single node using multiple cores I can write a bash script like this:
for i in `seq 1 10`;
do
python myfile.py && cp temp.txt outputs/out$i.txt &
done
But I want to utilize different nodes.
Required output:
outputs/out1.txt,out2.txt,out3.txt etc
Some related links are following:
https://www.osc.edu/sites/osc.edu/files/documentation/Batch%20Training%20-%2020150312%20-%20OSC.pdf
https://www.osc.edu/~kmanalo/multithreadedsubmission