UvA course 2016-06-15
Extras - Calculating π with OpenMP

UvA logo

SURFsara logo

This is an exercise from the Extras part of the Tutorial UvA course 2016-06-15.

In this advanced part of our HPC Cloud tutorial we ask you to play around with a parallel processing technique on a shared-memory system. For this purpose, we will be running a Monte Carlo simulation to calculate an approximation of the value of π.

NOTE:

You are now in the advanced section of the workshop. You have your laptop and an Internet connection. We expect you will be able to find out more on your own about things that we hardly/don’t explain but which you think you need. For example, if we were you, at this point we would’ve already googled for several things:

  1. Monte Carlo simulation
  2. Monte Carlo pi
  3. OpenMP cheatsheet

We provide you with an implementation of that simulation using OpenMP. You will be asked to perform multiple runs of each program, so that fluctuations caused by e.g. network can be middled out. The output of each program includes results for run time in wall-clock, user and system time.

This exercise will let you use OpenMP, first with a serial implementation within a single multicore VM and then with different parallel implementations. Please observe if the differences are significant or not for the scenarios below.

a) Setting up a VM for the exercise

sudo apt-get install build-essential

Optionally verify gcc and GNU make installation and version with gcc -v and make -v respectively.

wget https://doc.hpccloud.surfsara.nl/UvA-course-20160615/code/gridpi-mp.tar
tar -xvf gridpi-mp.tar
cd gridpi-mp/
ls -l

b) Serial runs

gcc -std=c99 -Wall -Werror -pedantic gridpi-serial.c -o gridpi-serial
./gridpi-serial

Food for brain b1:

  • Do you see significant differences between real and user time? Can you explain?

c) Simple OpenMP version

gcc -std=c99 -Wall -Werror -pedantic -fopenmp gridpi-mp-simple.c -lm -o gridpi-mp-simple
./gridpi-mp-simple

Food for brain c1:

  • How many threads are running?
  • Can you explain the differences in the code between this file and that of the previous exercise? In particular:
    • What runs in parallel? What not?
    • Which variables are used where?

d) Running the OpenMP optimised version

gcc -std=c99 -Wall -Werror -pedantic -fopenmp gridpi-mp-alt.c -lm -o gridpi-mp-alt
./gridpi-mp-alt

Food for brain d1:

  • How many threads are running?
  • Can you explain the differences in the code between this file and those of previous exercises b) and c)? In particular:
    • What runs in parallel? What not?
    • Which variables are used where?

e) Running the OpenMP optimised alternative version

gcc -std=c99 -Wall -Werror -pedantic -fopenmp gridpi-mp-reduction.c -lm -o gridpi-mp-reduction
./gridpi-mp-reduction

Food for brain e1:

  • How many threads are running?
  • Can you explain the differences in the code between this file and those of previous exercises b), c) and d)? In particular:
    • What runs in parallel? What not?
    • Which variables are used where?

Food for brain e2:

Replace your VM with one that has more cores (hint: make a new template or update the current). Then run some batches of each of the exercises b), c), d) and e) again.

  • How do times with more cores compare to those before?
  • Does the performance scale for all of the implementations? Do you see any number where it ceases to make sense to scale? Can you explain?

BONUS food for brain

This section is meant as extra questions that we thought would be nice for you to investigate, and we invite you to do/think about them even after the workshop is finished.

Bonus1: Make a batch of several runs (e.g.: 100) per exercise (b), c), d), e)) and calculate the average runtime and standard deviation. What do you observe?
(hint: make a table where each row is each exercise, one column is the average time and one is the deviation you measured).
Bonus2: Play around with the parameters in the source files (e.g. POINTS_ON_AXIS)
(hint: add an extra column to the table for each parameter you change). Any insight?
Bonus3: Can you draw some curves (graphs) with the measurements you have gathered? How do they compare?

NOTE: Do not forget to shutdown your VM when you are done with your performance tests.

If you want more of the advanced exercises on the HPC Cloud, see Extras.