First basic MPI script with mpi4py

Getting processor name with MPI's comm.rank()



Before we begin, I will reiterate that everything written here needs to be copied to all nodes. You may eventually have a specific master-node script and then worker-node scripts, though this is not really necessary for us at the moment.

I will be storing scripts, like the following:

~/Desktop/sct/sct2.py

Here's the code for sct2.py

from mpi4py import MPI
comm = MPI.COMM_WORLD
name=MPI.Get_processor_name()
print("hello world")
print(("name:",name,"my rank is",comm.rank))
		

First we need to import mpi4py, then we establish communications.

Grab processor name, output generic message, then output dynamic info

To run this:

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

Output will be something like this, I used different print outs in the picture, but same idea:

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