Starting from:

$30

HPC Assignment #1ย  Monte Carlo Method for ๐œ‹ Solved



๐œ‹ is the area of the disk with the radius ๐‘Ÿ equals to one. The approximating of ๐œ‹ can be performed in the following steps:

•      Inscribe a circle with radius ๐‘Ÿ in a square with side length of 2๐‘Ÿ

•      The area of the circle is ๐œ‹๐‘Ÿ$ and the area of the square is 4๐‘Ÿ$

•      The ratio of the area of the circle to the area of the square is &)’’(( = &)

•      A simple way to compute the fraction is to generate the points in the square and count the number of points which lie in the inside of the circle

 

•      Therefore, ๐œ‹ is approximated as ๐œ‹=4∗  ,-./0’,-./0’                                           

 

 

The Monte Carlo methods are a class of algorithms that rely on repeated random sampling to calculate the result. To compute the value of ๐œ‹, it generates points in the square [-1, 1] * [-1, 1] and counts the number of points in the inside of the unit circle. The result is four times the fraction between the number of points which lie in the inside of the circle and the number of all generated points.  

 

Given the sequential Monte Carlo Method for ๐œ‹ program below, parallelize it with OpenMP.  

   

Requirements:

1.      Write the parallelized OpenMP code in either C or Fortran; try to maximize the performance with what you learned in class;

2.      Take a second command argument as the number of threads variable, such as  int nthreads = atoi(argv[2]);

3.      Set the number of threads in OpenMP using nthreads.  

4.      Fill in the table below with varying sets of threads and samples for your parallel program (top to down in the row direction: increasing number of threads in use; left to right in the column direction: increasing number of samples of points of the problem)

 

 

sec
100
100,000
10,000,000
1
 
 
 
2
 
 
 
4
 
 
 
8
 
 
 
16
 
 
 
 

5.      Turn in your code and table through canvas.

 

More products