Lab 6. MPI Programs to Approximate PI.
Task 1 – Monte Carlo Approximation.
- Get organised. (create the folder lab6 + a subfolder pi1)
- Copy in the folder the program myPiExample.c and Makefile.
- Run the program for several values of p (e.g. 1, 2, 4).
- Run the program for several values of n e.g. 1000, 10000,…etc.
Task 2 – Buffon’s Needle Problem
- Read some information about the Buffon’s needle problem http://mathworld.wolfram.com/BuffonsNeedleProblem.html
- Implement a MPI program for this problem.
o Start from the program myPyExample.c.
o Generate random values for x, y and d. !!! What randomness you have to put in place for d!!!
o Draw the needle this the eye at (x,y) and the direction d.
§ Calculate the coordinates of the head x1, y1.
§ Draw the line between (x,y) and (x1,y1).
o Test if the needle intersects the grid of horizontal lines.
§ You should consider only y and y1 for this.
§ Devise a test for the intersection.
o Approximate PI with PI=2*(size*n)/final_count.
- Run the program for several values of p.
Task 3 – The Julia Fractals.
- Get organised. (create the folder lab7 + a subfolder Julia)
- Copy in the folder the program to generate the Julia set (the following files JuliaUniform.c, comp.c, and comp.h plus Makefile from last week).
- Run the program for several values of p (e.g. 1, 2, 4, 8).
- Run the program for other values of c e.g. 0.29 and 0.54 etc.
- Use another way to partition the for loops:
o Cyclic: for(i=rank; i<width; i+=size) for(j=0; j<width; j++)
o On Columns: for(i=0; i<width; i++)for(j=rank*width/size; j<=(rank+1)*width/size; j++)
- Observe the execution times.
- Change the value for the complex number c e.g. 0.281 or 0.54 and see how the fractal varies.
- Generate the Julia set associated with some other iterative functions e.g. z^2+c^2, z^3+c, z^3+c^3, etc.
Task 4 – The Mandelbrot Fractals.
- Modify the Julia program to generate the Mandelbrot set.
o Declare and make an array of colors.
o Start from z=0 and c=(x,y) inside of the loop for.
o Draw the point with the color given by k.
- Generate the Mandelbrot sets associated with some other iterative functions e.g. z^2+c^2, z^3+c, z^3+c^3, etc.
Note: Visit the Multimedia Fractal site for a complete collection of Mandelbrot sets etc.