Question
Write a program to approximate (using the Trapezoidal rule) the integral of using C p rogramming language and modify the attached program by using N
Write a program to approximate (using the Trapezoidal rule) the integral of using C programming language and modify the attached program
by using N processes to sum up n trapezoids (n>N).
N should vary in the range of 1 to 8, while n will be input by the user.
The parent process should create N ( [1, 8]), child processes using fork().
There should be N pairs of pipes through which the parent process assigns jobs to associated child processes, and receives results back from them when the calculation is completed.
More specifically, the parent process will initially assign the first N pieces to the N child processes to do their respective calculation. Whenever a process has done its calculation of the area of another trapezoid, it will send it back to the parent process. Upon receiving such a piece, the parent process will update the sum accordingly, and, if there are still un-calculated pieces, the parent will also assign the next piece to the just returned child process. After the parent has received all the n results, it prints out the final answer.
Some useful Points:
- Use atof() to convert from string to a numerica floating point value. Example: double d = atof(buffer);
- Use sprintf() to convert from numerica floating point value to a string. Example: sprintf(buffer,"%f", d);
#include
//write child message into fds2 close(fds2[0]); write(fds2[1], string2, sizeof(string2)); exit(0); } else {//Parent process starts--zs //write parent message into fds0 close(fds0[0]); write(fds0[1], string0, sizeof(string0)); //read child 1 message from its associated pipe--zs close(fds1[1]); read(fds1[0],buf,sizeof(string1)); printf("parent reads from Child 1: %s ", buf); //write something into fds0 again to child 2--zs close(fds0[0]); write(fds0[1], string0, sizeof(string0)); //read child 2 message from its associated pipe--zs close(fds2[1]); read(fds2[0],buf,sizeof(string2)); printf("parent reads from Child 2: %s ", buf); exit(0); } }
rcos (2) daStep 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