Question: Construct a C/C++ program for a UNIX environment to use the trapezoidal rule to approximate the integral of f(x) = 1/(x + 1) for the

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

f(x) = 1/(x + 1)

for the interval [0, 2]. Construct your solution so that you compute the areas of n small trapezoids by N individual worker processes. The master process should spawn N worker processes using the fork () and exec () UNIX system calls. Read about using system V UNIX shared memory in Lab Exercise 11.1, and then use the facility to implement the requisite synchronization and information sharing for a concurrent solution to this problem. Whenever a worker process is ready to compute the area for another trapezoid, it synchronizes with the master using a shared variable and gets new work via shared memory. When the master process receives all the sums from the worker processes, it should sum them and print the answer, along with the amount of time required to obtain the solution. It should ignore the time to set up the shared memory. 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 required to accomplish the computation. Plot the amount of time versus the number of trapezoids used in the approximation.

If you have a shared-memory multiprocessor available to use, solve this problem using the shared-memory kernel extensions provided by the machine.


Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This solution is for a Sequent Balance 8000 shared memory machine a little different than the System V shared memory facility but it gives you the fla... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (1 attachment)

Word file Icon

34-E-CE-OS (499).docx

120 KBs Word File

Students Have Also Explored These Related Computer Engineering Questions!