Parallel Programming in Python

Now that we have MPI installed and working we can start using it with real programming languages, and first language of choice for the Pi is ofcourse Python.

Following on with the instructions from Southampton Uni there is some information at the bottom about the use of mpi4py one of a number of Python libraries for MPI.

MPI4PY can be installed through apt-get

sudo apt-get install python-mpi4py

Once installed we can pull down some demo code

mkdir mpi4py
cd mpi4py
wget http://mpi4py.googlecode.com/files/mpi4py-1.3.tar.gz
tar xfz mpi4py-1.3.tar.gz
cd mpi4py-1.3/demo

And once its installed we can check it works by running one of the basic examples

mpirun.openmpi -np 2 -machinefile /home/pi/mpi_testing/machinefile python helloworld.py

This produces the following output if running on one node, in this instance pislave1

Hello, World! I am process 0 of 2 on pislave1.
Hello, World! I am process 1 of 2 on pislave2.

The above instructions can now be repeated on pimaster, and pislaves2, 3 and 4

Your email address will not be published. Required fields are marked *