Informations

Auteur(s) Erik-Jan Lingen, Matthias Möller
Date limite Pas de date limite
Limite de soumission Pas de limite

Se connecter

[OpenMP] Solution 2 : Compute PI

This material is part of the course Practical Introduction to Parallel Programming and meant for educational purposes only.


Background

The area of a circle of radius \(R\) is \(\pi R^2\), the area of a square with side length \(2R\) is \(4R^2\). If the circle is inscribed inside the square then the ratio of both areas is \(\pi/4\).

Monte Carlo method

If we pick \(N\) points at random inside the square and count the number of points that are inside the circle (\(M\)) then we can compute the approximation \(\pi\approx 4M/N\).

02-compute-pi-openmp_sol/Pi_mc.png

Hints

You can retrieve an upper bound of the numbers of threads that will be created in a parallel regions using omp_get_max_threads(). This even works outside any parallel region.

Use an array of size omp_get_max_threads() to pass data from the different threads to the master thread.

Use #pragma omp parallel default(none) to force yourself to specify the behaviour of all variables (private/shared) explicitly.


Question 1: Compute PI
Question 2: OpenMP environment variables

Specify the OpenMP environment variables that should be used for running your program (export OMP_NUM_THREADS=1 ...). Use semicolons to separate multiple variables

Question 3: Command Line Argument

Specify the command line arguments that should be passed to your program when it is run. Arguments must be given in quotes and separated by commas. Leave this filed empty if you do not want to specify command line arguments.

Example: "1","int","arg=2" is interpreted as three arguments 1, int, and arg=2.