Link to this document's Jupyter Notebook

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 on Tuesday February 16. Students must come to class the next day prepared to discuss the material covered in this assignment.


Pre-Class Assignment: OMP Loops

Goals for today's pre-class assignment

  1. Review/Recap of Critical Sections
  2. Work Sharing
  3. Reduction
  4. Assignment wrap up

1. Review/Recap of Critical Sections

This is a good video but is mostly a review of what we have already discussed. It is great if you want to solidify your understanding. However, there is a lot of videos this week and your instructors want to be mindful of your time.

DO THIS: Watch the following video on YouTube which is a review of the "Pi" program and it's summary on critical sections Introduction to OpenMP: 08 Discussion 3


2. Work Sharing

The following video introduces the concept of work sharing using loops in OpenMP. This is a critical topic and will likely be the most common way you will use OpenMP (This is very true for the homework).

DO THIS: Watch the following video on YouTube and answer the questions provided Introduction to OpenMP: 09 part 1 Module 5

QUESTION: What is the OpenMP pragma command that transforms a simple for loop into parallel section?

Put your answer to the above question here.

QUESTION: What BASH command could you use in a submission script to set the OMP_SCHEDULE environment variable before running your program using the schedule(runtime) runtime option.

Put your answer to the above question here.

3. Reduction

We talked about reduction loops briefly in class. You will also be using this on your homework.

DO THIS: Watch the following video on YouTube Introduction to OpenMP: 09 part 2 Module 5

Steps to using OpenMP on loops

  1. Find the compute intensive loops
  2. Modify those loops so that there are no loop carry dependencies
  3. Add the loop pragmas.

QUESTION: What is a carry dependency?

Put your answer to the above question here.

DO THIS: Go back to the serial pi program (shown below) and parallelize it with a loop construct using a reduction operator. Be prepared to share your answer in class.

MAKE SURE YOU AT LEAST TRY!!! The act of trying to figure this code out will teach you much more than just coying and pasting answers from your peers during class. Don't just stop when you don't understand something. Programming is often about being frustrated because you don't understand what is going on yet still pushing though that frustration. Be mindful of your time but do not be lazy in your learning.

Original Serial Pi program

static long num_steps  = 100000;
double step;
int main()
{
    int i; double x,pi,sum=0.0;
    step = 1.0/(double) num_steps;
    for (i=0;i<num_steps;i++) 
    {
        x = (i + 0.5) * step;
        sum = sum+4.0/(1.0+x*x);
    }
    pi = step * sum;
}

4. 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 Google Form

If you have trouble with the embedded form, please make sure you log on with your MSU google account at googleapps.msu.edu and then click on the direct link above.

Assignment-Specific QUESTION: Where you able to back to parallelize the above serial code with an OpenMP loop construct using a reduction operator. If not, where did you get stuck?

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


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:

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.