Question: In C using the following 2 files to create a 3rd file that uses multiple threads to improve performance. Split the array into pieces and

In C using the following 2 files to create a 3rd file that uses multiple threads to improve performance. Split the array into pieces and each piece is handled by a different thread. Use 8 threads. run and compile in linux.

#include  #include  #define BUFFER_SIZE 4000000 int countPrime=0; int numbers[BUFFER_SIZE]; int isPrime(int n) { int i; for(i=2;i 

and a thread posix c file

#include  #include  #define THREAD_NUM 5 int sum=0; /* this data is shared by the thread(s) */ /** * The thread will begin control in this function */ void *runner(void *param) { int i, upper = atoi(param); if (upper > 0) { for (i = 1; i <= upper; i++) sum += 1; } printf("[thread %u] Done ",pthread_self()); pthread_exit(0); } int main(int argc, char *argv[]) { int i; pthread_t tid[THREAD_NUM]; /* the thread identifier */ pthread_attr_t attr; /* set of attributes for the thread */ if (argc != 2) { fprintf(stderr,"usage: a.out  "); return -1; } if (atoi(argv[1]) < 0) { fprintf(stderr,"Argument %d must be non-negative ",atoi(argv[1])); return -1; } /* get the default attributes */ pthread_attr_init(&attr); /* create the thread */ for (i=0;i 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!