Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 Here S is denoting the required area ( under the curve ) depicted in grey in the above figures, S 0 is the area
Here S is denoting the required area under the curve depicted in grey in the above figures, S
is the area of the enclosing rectangle and p is a value between and representing the ratio of
the generated points which fall inside the S area grey zone in the figure divided by the total
number of points. For example in the figure above we would have p
The function whose definite integral will be calculated, will be given in hardcoded way in the
form of a function but notice that our basic method works only for the cases when the values
of the function in the integration interval are always nonnegative:
In this problem you are required to write a parallel program which will estimate the value of a
definite integral. The program will create several parallel units and each of them will generate
random points inside the enclosing rectangle. Finally the definite integral will be estimated as:
N
Definite integral
N
Area of enclosing rectagle
Here, N is the total number of generated random points by all threads and N is the number of
random points which are located below the curve.
a Write a programusing POSIX threads which receives as command line parameters the total
number of random points N that will be generated, the number ofthreads that will be used,
the bounds of the definite integral, an upper bound on the values of the function in this
interval, and will estimate the value of the definite integral using the Monte Carlo method
described above. A sample execution may be:
MonteCarloIntegralEstimator
b Write a program using OpenMP which receives as command line parameters the total
number of random points N that will be generated, the number of threads that will be used,
the bounds of the definite integral, an upper bound on the values of the function in this
interval, and will estimate the value of the definite integral using the Monte Carlo method
described above. A sample execution may be:
MonteCarloIntegralEstimator
c Write a program using MPI which reads as input from the user only once the total number
of random points N that will be generated, the bounds of the definite integral, an upper
bound on the values ofthe function in this interval, and will estimate the value ofthe definite
integral using the Monte Carlo method described above. The number of processes will be
provided to the mpiexec command. A sample execution may be:
mpiexec n MonteCarloIntegralEstimator
An example that may be used for testing purposes:
fx x from to as an upper bound may use any value greater than is fine and
the expected result is In this case the enclosing rectangle is determined by the lines
x x y y so its area is If we generate points and points
are below the curve, then the approximation of the integral for this case is:
Definite integral
The key idea in our approach is to construct an enclosing rectangle for the required area and to
randomly generate points inside that rectangle. Finally we approximate the required area by
checking the percentage of the generated points which are inside it so we can express it by the
formula:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started