Information

Author(s) Erik-Jan Lingen, Matthias Möller
Deadline No deadline
Submission limit No limitation

Sign in

[Introduction] Exercise 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-introduction/Pi_mc.png

Functions in minimpi.h

/* Initialization of parallel communication                   */
void init()

/* Finalization of parallel communication                     */
void finalize()

/* Get the total number of processors involved                */
int get_total_proc_number()

/* Get the number of the current processor                    */
int get_my_proc_number()

/* Send an integer to processor dest                          */
/* value  IN   Integer to be sent.                            */
/* dest   IN   Processor number to which the integer is sent. */
void send_int ( int value, int dest );

/* Receive an integer from processor source                   */
/* value  OUT  Pointer to the integer to be received.         */
/* source IN   Processor from which the message is received.  */
void recv_int ( int* value, int source );

Question 1: Compute PI
Question 2: Number of MPI processes

Specify the number of MPI processes (1-64) that should be used for running your program (mpirun -np <nproc>)

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.