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

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, all inclusive. 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 computation. Instead, it should create one pthread to examine each range.

BE SURE TO HAVE THIS AS THE FIRST EXECUTABLE LINE IN YOUR PROGRAM:

alarm(90)

Use time1 from timedemo.c 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 number of primes the number of primes in range 1 the number of primes in range 2 etc

An example print for the above test might be:

0.014 281 26 135 120

where I just made up the 0.014 time.

timedemo.c :

#include #include #include #include #include double time1() { struct timeval tv;

gettimeofday( &tv, ( struct timezone * ) 0 ); return ( (double) (tv.tv_sec + (tv.tv_usec / 1000000.0)) ); }

double time2() { return ( (double) time(NULL) ); }

void main(int argc,char *argv[]) { double t1, t2, t3, t4;

t1 = time1(); t2 = time2(); printf("%lf %lf ",t1,t2); sleep(2); t3 = time1(); t4 = time2(); printf("%lf %lf ",t3,t4);

printf("%lf %lf ",t3-t1,t4-t2); }

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

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions

Question

What is meant by "copy style"?

Answered: 1 week ago

Question

4. Devise an interview strategy from the interviewers point of view

Answered: 1 week ago