Question
Write pesudo code of the fiven code #include #include #include #include void *computinParallelPiSerial(int start, int end, double *sum) { int i; //printf(looping from %d to
Write pesudo code of the fiven code
#include
void *computinParallelPiSerial(int start, int end, double *sum) { int i; //printf("looping from %d to %d ",start, end ); double factor; for (i = start; i < end; i++){ if (i % 2 == 0){ factor = 1.0; } else { factor = -1.0; } *sum = *sum + 4 * factor / (2*i+1); } return NULL; }
int main(){ double sum = 0; long start=0,last=0, n = 100000; int i=0; void *status; // holds the thread execution status int threadCount = 4; pthread_t thread_ids[threadCount];
for (i = 0; i < threadCount; i++){ start = last; last = start+n/threadCount; pthread_create(&thread_ids[i], NULL, computinParallelPiSerial(start,last,&sum), NULL); }
//for (i = 0; i < threadCount; i++) // pthread_join(&thread_ids[i], NULL);
printf("Pi is equal to %f ", sum); return 0; }
Step 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