--- /dev/null
+#!/usr/bin/env python
+
+import subprocess
+import sys
+
+from mpi4py import MPI
+
+REQUEST_TAG = 100
+RESPONSE_TAG = 101
+
+def master(comm):
+ slaves = comm.Get_size() - 1
+ command = sys.argv[1:]
+ for slave in range(1,slaves+1):
+ comm.send(command, dest=slave, tag=REQUEST_TAG)
+ code = execute(command)
+ print "node %d code: %d" % (comm.Get_rank(), code)
+ s = MPI.Status()
+ for slave in range(1,slaves+1):
+ code = comm.recv(source=MPI.ANY_SOURCE, tag=RESPONSE_TAG, status=s)
+ print "node %d code: %d" % (s.Get_source(), code)
+
+def slave(comm):
+ command = comm.recv(source=0, tag=REQUEST_TAG)
+ code = execute(command)
+ comm.send(code, dest=0, tag=RESPONSE_TAG)
+
+def execute(command):
+ return subprocess.call(command)
+
+
+if __name__ == '__main__':
+ comm = MPI.COMM_WORLD
+ rank = comm.Get_rank()
+ if rank == 0:
+ master(comm)
+ else:
+ slave(comm)