Link to this document's Jupyter Notebook

In order to successfully complete this assignment you need to participate both individually and in groups during class. If you attend class in-person then have one of the instructors check your notebook and sign you out before leaving class on Wednesday March 24. If you are attending asynchronously, turn in your assignment using D2L no later than _11:59pm on Wednesday March 24.


In-Class Assignment: MPI Programming Basics

Picture of two children wispering to each other. Included as a motivation for the Rumor Mill example

Agenda for today's class (70 minutes)

  1. (20 minutes) Pre class Review
  2. (30 minutes) Pi Estimation
  3. (20 minutes) Rumor Mill continued

1. Pre class Review


2. Pi Estimation

Lets go back and consider the pi estimation algorithm we used in 0217-OMP_Threads_in-class-assignment:

#include <omp.h>
static long num_steps = 100000; double step;
#define NUM_THREADS 2
void main ()
{ 
    int i, nthreads; double pi, sum[NUM_THREADS];
     step = 1.0/(double) num_steps;
     omp_set_num_threads(NUM_THREADS);
     #pragma omp parallel
     {
         int i, id,nthrds;
         double x;
         id = omp_get_thread_num();
         nthrds = omp_get_num_threads();
         if (id == 0) nthreads = nthrds;
         for (i=id, sum[id]=0.0;i< num_steps; i=i+nthrds) {
             x = (i+0.5)*step;
             sum[id] += 4.0/(1.0+x*x);
         }
     }
     for(i=0, pi=0.0;i<nthreads;i++)pi += sum[i] * step;
}

DO THIS: As a class, lets discuss the cons for moving this example to a Shared Memory system.

Dispyte this being a poor example for running in MPI, lets spend today converting the code to an MPI version just to get an idea about how MPI would work.

DO THIS: Take the above example and turn it into an MPI Only program.


3. Rumor Mill continued

For the last few minutes of class we will revisit the rumor mill example and see if we can start making modifications to run the example inside mpi.


Congratulations, we're done!

If you attend class in-person then have one of the instructors check your notebook and sign you out before leaving class. If you are attending asynchronously, turn in your assignment using D2L.

Course Resources:

Written by Dr. Dirk Colbry, Michigan State University Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.