I want to launch parallel processes from a python script (and, for testing, interactively, but not from ipython), across two different versions of python, and have started out with mpi4py
. The two versions are (for 2 and 8 cores respectively):
Python 2.7.2 |EPD 7.2-2 (64-bit)| (default, Sep 7 2011, 16:31:15)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
and
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
On the first one (to learn the ropes), interactively I get:
from mpi4py import MPI
import sys
size = MPI.COMM_WORLD.Get_size()
print size
1
rank = MPI.COMM_WORLD.Get_rank()
print rank
0
which is not what I want (and doing mpirun
/mpiexec python
just seems to hang/do nothing). But if I do:
mpiexec -n 5 python helloworld.py
on
#!/usr/bin/env python
from mpi4py import MPI
import sys
size = MPI.COMM_WORLD.Get_size()
rank = MPI.COMM_WORLD.Get_rank()
name = MPI.Get_processor_name()
sys.stdout.write(
"Hello, World! I am process %d of %d on %s.\n"
% (rank, size, name))
I get
Hello, World! I am process 0 of 5 on localhost.
Hello, World! I am process 1 of 5 on localhost.
Hello, World! I am process 2 of 5 on localhost.
Hello, World! I am process 3 of 5 on localhost.
Hello, World! I am process 4 of 5 on localhost.
How can I get size
> 0 when launching python interactively?
Incidentally, doing ./helloworld.py
rather than python helloworld.py
doesn't work:
localhost:demo jtlz2$ mpiexec -n 5 ./helloworld.py
--------------------------------------------------------------------------
Failed to find or execute the following executable:
Host: localhost
Executable: ./helloworld.py
Cannot continue.
--------------------------------------------------------------------------
Any ideas why? Thanks!