Construct a C/C++ program for a UNIX environment to use the trapezoidal rule to approximate the integral

Question:

Construct a C/C++ program for a UNIX environment to use the trapezoidal rule to approximate the integral of

ƒ(x) = 1/(x+1)

for the interval [0,2]. In quadrature (numerical integration), the value of the integral is approximated by partitioning the x-axis into n equal-sized segments. If xi and xi+1 are two points on the x-axis that are the endpoints of one of these segments, then you can think of a trapezoid formed by the straight lines from ƒ(xi) to ƒ(xi+1), from ƒ(xi+1) to xi+1, from xi+1 to xi, and from xi to ƒ(xi). The straight line from ƒ(xi) to ƒ(xi+1) is an approximation of the function, so the trapezoid is an approximation of the integral for that part of the function. You can approximate the integral for [0,2] by computing the sum if the n trapezoids in that interval. This approximation to an integral is called numerical quadrature. Construct your solution so that you compute the areas of the n small trapezoids by N individual worker process. The controller process should spawn N worker processes using the fork and exec ( ) UNIX system calls. There should be one pipe with which all N worker processes send results to the controller and N pipes the controller uses to assign a trapezoid to a worker process. Whenever a worker process is ready to compute the area for another trapezoid, it sends the controller a result on the shared “input” pope. When the controller process receives all the sums from the worker processes, it sums them and prints the answer, along with the amount of time required to obtain the solution (and ignoring the time to set up the processes and the pipes). Experiment with various values of N between 1 and 8 for n = 64 trapezoids. Use a getTime ( ) routine (see the exercises in Chapter 1) to instrument your program so that you can measure the amount of time spent processing your code. Include a suitably large for loop in your procedure to evaluate the area of a trapezoid so that you can measure the time to accomplish the computation. Plot the amount of time versus the value of N used in the approximation.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: