Question: Write a C program that performs the tasks described below. If there is just 1 command-line argument and it is -hw you should simply print

Write a C program that performs the tasks described below. If there is just 1 command-line argument and it is -hw you should simply print hello world and then exit(0).

Use pthreads to examine a range of integers *inclusive*.

For each integer, compute the square-root of the square-root of the integer, i.e. sqrt(sqrt(x))

Count the number of resultant values whose fractional part is > 0.93 45.79 do NOT count 674.96 DO count

The program should accept 3 command-line arguments: low value (inclusive) high value (inclusive) number of pthreads *to create* to perform the computation

The mainline program should NOT participate in examining the range of integers. Instead, it should create the required number of threads and wait for them to complete the computation. It should then compute any final results and print the results (see required format below).

For large problems, the program should be able to attain near-linear speedups. -------- ./p3 0 9000000000 4 ## sample run: 0 to 9 Billion (INCLUSIVE); 4 threads alarm(90);

// <--- **** make this the first executable line of your program cc -Ofast -o p3 p3.c -lm -lpthread ## -Ofast *** should be used in makefile ^ that is the capital letter O and not the digit 0

long int // use long ints in place of normal ints at all places in the code

time1 // copy this function from the timedemo.c file to get time to print sample output (required format) from the above run:

THREAD 0: 156549125

THREAD 1: 160706830

THREAD 2: 154135327

THREAD 3: 162360567

TOTAL 633751849

TIME 16.701560 As described above, you should produce the above output in the main thread; this will assure that the correct order of output lines is preserved.

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!