How do I set a fixed number of processes in mpi4py? In other languages` mpi implementations it is passed in init(args) as argument. The documentation does not seem to mention this. Does anyone know how to do this? The program will be launched on regular dual core laptop and 24 nodes (96 cores) cluster and I would like to emulate the cluster on the laptop.
PS. Sorry if it actually is in the documentation - it is quite cryptic to someone new to mpi.
Easiest is just to use mpiexec (or mpirun) to launch the program, specifying the number of MPI tasks you want:
$ cat foo.py
from mpi4py import MPI
comm = MPI.COMM_WORLD
nprocs = comm.Get_size()
rank = comm.Get_rank()
if rank == 0:
data = 'Hello!'
comm.send(data, dest=nprocs-1, tag=1)
elif rank == nprocs-1:
data = comm.recv(source=0, tag=1)
print 'Rank ', rank, ' received ', data
$ mpiexec -np 4 python foo.py
Rank 3 received Hello!
Note, though, that running with 96 tasks on your laptop is probably not going to be especially useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With