Check out The Schwimmbad instead.
A Python MPI Pool
See code in examples/mpipool-demo.py:
# mpipool-demo.py# Standard libraryimportsysimportnumpyasnpfrommpipoolimportMPIPooldefworker(task):
x,y=taskreturn5*x+y**2defmain():
# Initialize the MPI poolpool=MPIPool()
# Make sure only we run map() on the master processifnotpool.is_master():
pool.wait()
sys.exit(0)
# create some random input datax=np.random.uniform(size=10000)
y=np.random.uniform(size=10000)
tasks=np.vstack((x,y)).Tvals=pool.map(worker, tasks)
pool.close()
if__name__=="__main__":
main()Execute the script using mpiexec or your computer/cluster's MPI execute script, e.g., here we
will use 8 cores: mpiexec -n 8 python mpipool-demo.py