1

I want to run a python function,say my_fun(x1,x2), on different nodes of cluster with SGE (QSUB). I created a script my_script.py which takes in the numeric arguments from the command line, so when running locally, I'd call it as

python my_script.py x1 x2

Now I want to submit this script to the cluster in a loop with different values of x1 and x2. Also, for the node to have access to python & the installed modules, I need to run module load Python/2.7 on the node before calling the python script through QSUB.

This seems like a pretty simple and typical use-case, but I can't find any straightforward way to do this from Python. Going back and forth between BASH and Python seems a bit clunky.

1
  • please, have a look at array jobs Commented Jun 6, 2016 at 6:04

2 Answers 2

1

I suggest you divide the job into multiple independent jobs depending on the number of nodes you have.

For each node/core, create a folder with a file containing the a list of the parameters this subjob should treat. Then in python, write a script which reads the file and calls your script (maybe using the multiprocessing module for multi-core support).

EDIT:

If you want to pass additional parameters through qsub, you can call qsub with arguments which can be passed to your script:

qsub -F "myarg1 myarg2 myarg3=myarg3value" myscript.sh

You can find this documentation here

Sign up to request clarification or add additional context in comments.

5 Comments

That's horribly inefficient for the number of jobs I need to submit. I think there are ways to do this without requiring writing files to disk.
where do your x1 x2 values come from? because qsub is also inefficient for calling small scripts
Another suggestion if you are looking for a way to farm out your jobs would be to use ipython/jupyter which allows you to start up a bunch of workers, submit calculations and collect the results.
That would have been my preferred way actually, but unfortunately, the ipengines kept crashing on importing one module (sklearn.svm). Doing the import through QSUB seems to be fine. I have no idea why. Here's my post on that issue : stackoverflow.com/questions/37531089/…
That is weird. Sorry I can't help you there.
0

This more or less does what I'm looking for:

https://gist.github.com/timflutre/a9085660271bd059f71c

import sys
import subprocess

job_param1 = 12.5
job_param2 = 5.0
jobName = "python my_script.py %f %f" % (job_param1,job_param2)
cmd = "module load Python/2.7; sleep 0.2; %s" % jobName
echoArgs = ["echo", "-e", "'%s'" % cmd]
print(" ".join(echoArgs))
qsubArgs = ["qsub","-cwd"]
print(" ".join(qsubArgs))

wholeCmd = " ".join(echoArgs) + " | " + " ".join(qsubArgs)
out = subprocess.Popen(wholeCmd, shell=True, stdout=subprocess.PIPE)
out = out.communicate()[0]

jobId = out.split()[2]
print jobId

1 Comment

Of course, I'll be running the body inside a (python) FOR loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.