Question: Write a parallel program pie.c in C or C++ (pie.cc) for Linux that computes an approximation of the number ? using a series' with N+1
Write a parallel program pie.c in C or C++ (pie.cc) for Linux that computes an approximation of the number ? using a series' with N+1 terms. The series sum is partitioned in T non-overlapping partial sums, each computed by T separate child processes created with the fork() library function. This program demonstrates data parallelism and interprocess communication using pipes. Each child process could perform a (potentially) long computation on a separate CPU (or core), thus, the entire computation could reach a speedup close to T. Numbers N and T are passed from the shell to the pie program as command line parameters. The main(argc, argv[]) function call gets these parameters (T, N) in argv[1] and argv[2] as strings, respectively. (Element argv[0] contains the program name and we dont need it.)
The first parameter, N, is the upper limit for i in the formula above. The second parameter, T, is the number of child processes that compute partial sums. N should always be greater than T, N>T. Otherwise the program should display an error message and call exit(1). Use the Nilakantha approximation formula for ? (http://en.wikipedia.org/wiki/Pi): ? = 3 + 4/(2*3*4) 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + . + k*4/((2*i)* (2*i+1)*( 2*i+2))+... where k = 1 if i is odd and k = -1 if i is even and i goes from 1 to N. The program can be run like this from the shell: ./pie N T For instance, ./pie 100 4 This command computes the approximation with 101 terms (starting with term 3) with 4 child processes. Here is a description of the algorithm to be implemented. The parent process iterates with an index variable of type int called j from 0 to T (0?j
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
