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 Friday February 3.


In-Class Assignment: Mmmmmmmm Pi¶

Cartoon picture of a slice of pie.  Visual joke because we are going to calculate the math number pi in class

Agenda for today's class (70 minutes)¶

  1. (20 minutes) Pre class Assignment
  2. (20 minutes) Project Default Project
  3. (50 minutes) Group OpenMP Pi code Timing Studies on the HPCC

1. Pre class Assignment¶

  • 11i--OMP_Threads_pre-class-assignment

2. Project Cross-cutting themes¶

As a class we are going to brainstorm topics and ideas that cut across your projects. We want to identify people in your class that are doing some aspect of their project which is similar to yours. The goal is to find teams of people that may be able to support each other.

Default project¶

I have made one honors project that can also be used as "the" project if you are not taking the honors option.

The default project is to implement a parallel version of the method by Heinz-Otto Kreiss, Anders Petersson and Jacob Ystrom for the wave equation with embedded boundary conditions

I have placed a starter code in the class repository.

Here suitable tasks are

  1. Equip the current code with output for vizualization.
  2. Parallelize the current code using OpenMP or MPI or both.
  3. Implement the embedded boundary method in the above paper (Section 4.)
  4. Investigate Penrose's unilluminable room.

3. Group OpenMP Pi code Timing Studies on the HPCC¶

The rest of class we will try to help each other out so that everyone gets a parallel OpenMP version of the Pi-code working. Lets see how far we get doing the following:

  • If you are stuck or confused, raise your hand and ask for help.
  • If you get stuck review code in the Google document.
  • Help your neighbors
  • If you have your basic code working, share it on the Google document.
  • Once you have a parallel code working, do a scaling study and very the number of cores. Plot the results and share your plot on the Google document.
  • Conduct the scaling study on different development nodes and generate different plots. Share them on the Google document.
  • Write a submission script and run the scaling study using the SLURM scheduler.
  • Share all of your solutions with each other using the following Google Document.
  • Review the Google Document and learn from each other's solutions.

Group Google Document

#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;
}

#include<iostream>
using std::cin; using std::cout; using std::endl;
#include<omp.h>


static long num_steps = 10000; // race condition...
double step;
int main()
{
    //cin >> num_steps ;
    int i; double x,pi=0.0;
    step = 1.0/(double) num_steps;
    omp_set_num_threads(4);
    double sum [4] ;
    #pragma omp parallel
    {
         int ID = omp_get_thread_num() ;
         cout << ID << endl;
        for (int i=ID ; i<num_steps; i += 4)

        {
            x = (i + 0.5) * step;
            sum[ID] += 4.0/(1.0+x*x);
        }
    }
    for (int i=0 ; i<4; i++){
       pi += sum[i] * step ;
    }
    cout.precision(17) ;
    cout << pi << " " << (pi-3.14159265358979324) << endl ;
}

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:¶

  • Website
  • ZOOM
  • JargonJar
  • GIT

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.