In order to successfully complete this assignment you must do the required reading, watch the provided videos and complete all instructions. The embedded survey form must be entirely filled out and submitted on or before 11:59pm. Students must come to class the next day prepared to discuss the material covered in this assignment.


PCA 33: More MPI#

Goals for today’s pre-class assignment#

  1. The MPI Header function

  2. Assignment wrap-up

1. MPI is Simple#

Remember that many MPI programs can be written using just these six functions, only two of which are non-trivial:

  • MPI_INIT

  • MPI_COMM_SIZE

  • MPI_COMM_RANK

  • MPI_SEND

  • MPI_RECV

  • MPI_FINALIZE

If you can remember these functions the rest is easy.

2. MPI Reduce Options#

Like OpenMP there are some special MPI messages that are specifically designed to help with common types of algorithms. THese are:

  • MPI_Allreduce

  • MPI_reduce

Name

Meaning

MPI_MAX

maximum

MPI_MIN

minimum

MPI_SUM

sum

MPI_PROD

product

MPI_LAND

logical and

MPI_BAND

bit-wise and

MPI_LOR

logical or

MPI_BOR

bit-wise or

MPI_LXOR

logical xor

MPI_BXOR

bit-wise xor

MPI_MAXLOC

max value and location

MPI_MINLOC

min value and location

https://www.mpi-forum.org/docs/mpi-1.1/mpi-11-html/node78.html


3. Monte Carlo Method for Estimating \(\pi\)#

from IPython.display import YouTubeVideo
YouTubeVideo("M34TO71SKGk",width=640,height=360)

QUESTION: In a Distributed Memory System we no longer can pass information though memory. How is data passed in a distributred memory system?

Put your answer here.

Example Serial Code#

#include <stdlib.h>
#include <stdio.h>
#define sqr(x)	((x)*(x))
long random(void);

double dboard(int darts)
     {
     double x_coord,       /* x coordinate, between -1 and 1  */
            y_coord,       /* y coordinate, between -1 and 1  */
            pi,            /* pi  */
            r;             /* random number between 0 and 1  */
     int score,            /* number of darts that hit circle */
         n;
     long rd;
     unsigned long cconst; /* used to convert integer random number */
                           /* between 0 and 2^31 to double random number */
                           /* between 0 and 1  */

     cconst = 2 << (31 - 1); 
     cconst = RAND_MAX;
     score = 0;

     /* "throw darts at board" */
     for (n = 1; n <= darts; n++)  {
          /* generate random numbers for x and y coordinates */
          rd = random();
	  //printf("Rand - %ld\t",rd);
          r = (double)rd/cconst;
          //printf("%10.8f\n",r);
          x_coord = (2.0 * r) - 1.0;
          r = (double)random()/cconst;
          y_coord = (2.0 * r) - 1.0;

          /* if dart lands in circle, increment score */
          if ((sqr(x_coord) + sqr(y_coord)) <= 1.0)
               score++;
          }

     /* calculate pi */
     pi = 4.0 * (double)score/(double)darts;
     return(pi);
     } 

Assignment wrap-up#

Please fill out the form that appears when you run the code below. You must completely fill this out in order to receive credits for the assignment!

Direct Link to Survey Form

Assignment-Specific QUESTION: No assignment specific question today.

Put your answer to the above question here

QUESTION: Summarize what you did in this assignment.

Put your answer to the above question here

QUESTION: What questions do you have, if any, about any of the topics discussed in this assignment after working through the jupyter notebook?

Put your answer to the above question here

QUESTION: How well do you feel this assignment helped you to achieve a better understanding of the above mentioned topic(s)?

Put your answer to the above question here

QUESTION: What was the most challenging part of this assignment for you?

Put your answer to the above question here

QUESTION: What was the least challenging part of this assignment for you?

Put your answer to the above question here

QUESTION: What kind of additional questions or support, if any, do you feel you need to have a better understanding of the content in this assignment?

Put your answer to the above question here

QUESTION: Do you have any further questions or comments about this material, or anything else that’s going on in class?

Put your answer to the above question here

QUESTION: Approximately how long did this pre-class assignment take?

Put your answer to the above question here

from IPython.display import HTML
HTML(
"""
<iframe 
	src="https://cmse.msu.edu/cmse401-pc-survey" 
	width="100%" 
	height="500px" 
	frameborder="0" 
	marginheight="0" 
	marginwidth="0">
	Loading...
</iframe>
"""
)

###STARTFOOTER###


Congratulations, we’re done!#

To get credit for this assignment you must fill out and submit the above survey from on or before the assignment due date.

Course Resources:#

###LINKS###

##ANSWER## 
#this cell gets the name of the current notebook.
from jupyterinstruct import InstructorNotebook
InstructorNotebook.cleanNsave()

import thiscourse
tags = thiscourse.tags()
##ANSWER## 
##ANSWER## 
#This cell runs the converter which removes ANSWER feilds, renames the notebook and cleans out output fields. 
studentnotebook = InstructorNotebook.makestudent(this_notebook, "./"+tags['COURSE_CODE']+"/", tags)
InstructorNotebook.validate(studentnotebook)
##ANSWER## 
##ANSWER##
from jupyterinstruct import webtools

webtools.publish2folder(studentnotebook, './cmse401-S21-student/assignments')

##ANSWER##
##ANSWER##
from jupyterinstruct import InstructorNotebook

InstructorNotebook.cleanNsave()
##ANSWER##

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.