Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

IBM Db2 11 1 Certification Guide Explore Techniques To Master Database Programming And Administration Tasks In IBM Db2

Authors: Mohankumar Saraswatipura ,Robert Collins

1st Edition

1788626915, 978-1788626910

More Books

Students also viewed these Databases questions

Question

Create the modular designs in Problems 4752. (21, 5)

Answered: 1 week ago

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago