Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C/C++ program that will calculate the prime numbers in a specified range. Use threads to implement the program. The lower range, upper range,

Write a C/C++ program that will calculate the prime numbers in a specified range. Use threads to implement the program. The lower range, upper range, and the number of threads to be created as command line arguments. The range should be partitioned into equal data sizes for all the threads. Always create an extra thread than what is specified on the command line. This thread will be used to sort the prime numbers from the shared file. All threads should be created continuously without any delay. Save the results from all the threads to a single shared file named results_lastname.dat. Use mutex to lock access to the file by the threads, so that at any point of time only one thread has exclusive access to the file. Calculate the execution time for computing the prime numbers and for sorting these numbers(only CPU time). When the threads are done executing, the extra thread created should sort the prime numbers and print them to a file called sorted_lastname.dat. Finally the main program should print the sorted results to standard output. The programs output should looks as follows: $ ./primethread_lastname 1 20000 20 P Prime 1 = 2 Prime 2 = 3 Prime 3 = 5 . . . The time the program took to compute and save the prime numbers is: 1245 The time the program took to sort the number: 14

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

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

Question What is a Roth 403 (b) plan?

Answered: 1 week ago