Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that uses pthreads to compute the number of prime numbers between multiple ranges of specified low and high values inclusive. Here

image text in transcribed
Write a C program that uses pthreads to compute the number of prime numbers between multiple ranges of specified low and high values inclusive. Here is an example execution: p3 3 103 1000 2000 3000 4000 The first range is 3 through 103, the second is 1000 through 2000, and the third is 3000 through 4000, al inelusive. You can assume that there will be no more than 4 ranges of values, implying that you will need to create no more than 4 threads Note that you only count the total number of primes found in each range, and not the actual prime numbers themselves. The mainline program should NOT perform any of the it should create one pthread to examine cach range. BE SURE TO HAVE THIS AS THE FIRST EXECUTABLE LINE IN YOUR PROGRAM Use timel from timedemo.e in main to determine the amount of time between starting the threads and termination of all threads. The print should contain EXACTLY 1 LINE OF OUTPUT containing these values the total time the total mumber of primes the number of primes in range 1 the number of primes in range 2 An example print for the above test might be: 0,014 281 26 135 120 where I just made up the 0,014 time. #include Winclude cunistd.h #include include qme.h> Winclude sys time.h double timel0 struct timeval tv gettimeofday&tv, (struct timezone)0) return ((double) (tv.tv sec+(v.t us1000000.0) double time20 return ((double) time(NULL) ) void main(int arge,char argvD double t1-12,t3.4; 1timel0 12 time0 sleep(2) 13 timel0 14 timc20 printf("%lf %afun"a344); printR'%lf%2fln",t3-11,1442); Write a C program that uses pthreads to compute the number of prime numbers between multiple ranges of specified low and high values inclusive. Here is an example execution: p3 3 103 1000 2000 3000 4000 The first range is 3 through 103, the second is 1000 through 2000, and the third is 3000 through 4000, al inelusive. You can assume that there will be no more than 4 ranges of values, implying that you will need to create no more than 4 threads Note that you only count the total number of primes found in each range, and not the actual prime numbers themselves. The mainline program should NOT perform any of the it should create one pthread to examine cach range. BE SURE TO HAVE THIS AS THE FIRST EXECUTABLE LINE IN YOUR PROGRAM Use timel from timedemo.e in main to determine the amount of time between starting the threads and termination of all threads. The print should contain EXACTLY 1 LINE OF OUTPUT containing these values the total time the total mumber of primes the number of primes in range 1 the number of primes in range 2 An example print for the above test might be: 0,014 281 26 135 120 where I just made up the 0,014 time. #include Winclude cunistd.h #include include qme.h> Winclude sys time.h double timel0 struct timeval tv gettimeofday&tv, (struct timezone)0) return ((double) (tv.tv sec+(v.t us1000000.0) double time20 return ((double) time(NULL) ) void main(int arge,char argvD double t1-12,t3.4; 1timel0 12 time0 sleep(2) 13 timel0 14 timc20 printf("%lf %afun"a344); printR'%lf%2fln",t3-11,1442)

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

Step: 3

blur-text-image

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions