Using conditional, Python, statements alongside MPI commands example

Marrying the power of MPI with the logic of Python

Since MPI is run on every node, and since we're using Python, we can mix the two for some neat outcomes. The first one that we'll show is conditional statements, based on comm.rank.

from mpi4py import MPI


print "my rank is:",comm.rank

if comm.rank == 1:
    print 'Doing the task of Rank 1'

if comm.rank == 0:
    print 'Doing the task of Rank 0!'

Here, we show the beginnings of how you might have very node-specific tasks.

Saving this as

mpirun.openmpi -np 2 -machinefile /home/pi/mpi_testing/machinefile python ~/Desktop/sct/


MPI with MPI4py and Python tutorial

The next tutorial:

  • Build a Supercomputer with Raspberry Pis
  • Intro
  • Supplies
  • Installing Operating System
  • Downloading and installing MPI
  • Testing Supercomputer
  • MPI with MPI4py Introduction
  • Installing mpi4py for use with Python and MPI
  • First basic MPI script with mpi4py
  • Using conditional, Python, statements alongside MPI commands example
  • Getting network processor size with the size command
  • Sending and Receiving data using send and recv commands with MPI
  • Dynamically sending messages to and from processors with MPI and mpi4py
  • Message and data tagging for send and recv MPI commands tutorial
  • MPI broadcasting tutorial with Python, mpi4py, and bcast
  • Scatter with MPI tutorial with mpi4py
  • Gather command with MPI, mpi4py, and Python