Question: 2. Summing up to ? (50 pts.) Write a parallel program pie.c in CorC++(ple.oc) for Linux that computes an approximation of the number x using
2. Summing up to ? (50 pts.) Write a parallel program pie.c in CorC++(ple.oc) for Linux that computes an approximation of the number x using a series with N+1 terms. The series sum is partiioned in T non-overlapping partial sums, each computed by T separate child processes created with the ork labeary function This program demonstrates data parallelism and inserpeocess communication using pipes. Each child process could perform a(pocentially) long computacion on a separate CPU (or core). Depending on the computer anchitecture, the entire computation could reach a speedup close to T Numbers N and T are passed from the shell to the pile program as command line parameters. The main(argc, argvI) function call gets these parameters (T.N) in arg1] and argv12) as strings, respectively. (Element ag [0] contains the program name and we don't 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 peocesses that compute partial sums, N should always be greater than T, NT Otherwise the program should display an ereor message and call exit(1). where k 1 if i isodd and k-1 if i is even and i goes from 1 to N The program can be run like this from the shell: pieNT For instance pie 100 4 This command computes the approximation with 101 terms (starting wi term 3) with 4 child processes Here is a description of the algorithm to be implemented The parent precess iterates with an index variable of type int called j from O to T (0siT), During iteration with index j, the paret process 1. creates a pipe associated with child process with index j 2. creames a child process with fork 3, writes the binary values of N, T, and j to the pipe After ending the loop (above) chat created the T child processes, the parent process starts a new loop. wikh index j from 0 to T (OsjcT) In iteration with index j, the parent process reads from the pipe associated with child j the value of the partial sum computed by the child and adds it to an accumulator double variable After the second loop ends, the parent peocess L. displays the sum approximating the value of x saored in the accumulator, with a message that reads like (this is a C printf format string, make sure the code displays the actual numbers!) waits for all child processes to 4, exits with code 0 The child process ?.ih index j nas its code ia function called compusePartialSum In this function the child process does this: L. closes any unnecessary file descripeors (which ones? 2. reads the values for N.T, and j from the pipe the were writen by the paremt process compuies the partial sum of the series (as described below) writes the partial sum to the pipe S calls exitO) 2. Summing up to ? (50 pts.) Write a parallel program pie.c in CorC++(ple.oc) for Linux that computes an approximation of the number x using a series with N+1 terms. The series sum is partiioned in T non-overlapping partial sums, each computed by T separate child processes created with the ork labeary function This program demonstrates data parallelism and inserpeocess communication using pipes. Each child process could perform a(pocentially) long computacion on a separate CPU (or core). Depending on the computer anchitecture, the entire computation could reach a speedup close to T Numbers N and T are passed from the shell to the pile program as command line parameters. The main(argc, argvI) function call gets these parameters (T.N) in arg1] and argv12) as strings, respectively. (Element ag [0] contains the program name and we don't 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 peocesses that compute partial sums, N should always be greater than T, NT Otherwise the program should display an ereor message and call exit(1). where k 1 if i isodd and k-1 if i is even and i goes from 1 to N The program can be run like this from the shell: pieNT For instance pie 100 4 This command computes the approximation with 101 terms (starting wi term 3) with 4 child processes Here is a description of the algorithm to be implemented The parent precess iterates with an index variable of type int called j from O to T (0siT), During iteration with index j, the paret process 1. creates a pipe associated with child process with index j 2. creames a child process with fork 3, writes the binary values of N, T, and j to the pipe After ending the loop (above) chat created the T child processes, the parent process starts a new loop. wikh index j from 0 to T (OsjcT) In iteration with index j, the parent process reads from the pipe associated with child j the value of the partial sum computed by the child and adds it to an accumulator double variable After the second loop ends, the parent peocess L. displays the sum approximating the value of x saored in the accumulator, with a message that reads like (this is a C printf format string, make sure the code displays the actual numbers!) waits for all child processes to 4, exits with code 0 The child process ?.ih index j nas its code ia function called compusePartialSum In this function the child process does this: L. closes any unnecessary file descripeors (which ones? 2. reads the values for N.T, and j from the pipe the were writen by the paremt process compuies the partial sum of the series (as described below) writes the partial sum to the pipe S calls exitO)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
