Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a multithreaded integer factorization program in C++ In number theory, integer factorization is the process of breaking a composite number into a product of

Develop a multithreaded integer factorization program in C++

In number theory, integer factorization is the process of breaking a composite number into a product of two smaller integers. If these factors are further restricted to prime numbers, the process is called prime factorization https://en.wikipedia.org/wiki/Integer_factorization

Prime check

Note that a number n is considered prime if it does not have any factors in the range 2 to (inclusive). The program will be supplied with 1 or more numbers(use C++ data type unsigned long long int) to be factorized as command-line arguments. Each number should be processed in the following manner

Base case

  1. If the number itself is prime (i.e., it cannot be factorized) then just print Is already prime as shown in the first sample output below.
  2. if the number is not prime, then print the two factors with one of them being the first smallest factor. In addition, indicate if the factors are prime by printing (prime) after the factors.

Additional functionality (multithreading):

Multithread the program such that each number is processed by a separate thread. That is, if you are given k command-line arguments, you should use k threads. Pay attention to the following notes:

First ensure your single-threaded solution (i.e., base case) is working correctly.

For multithreading, it would be easiest to store the integer factorization result (i.e., what you would like to print) for each number in a separate entry in a std::vector (ensure you initially create k entries to store results from each thread).

Ensure you do all the necessary processing in each thread. Minimize the work done in the main thread.

print the results only after all the threads have joined.

Outputs example

$ ./prime 78167

78167: Is already prime.

$ ./prime 18446744073709551614 18446744073709551614 = 2 (prime) * 9223372036854775807

Additional functionality output:

$ ./prime 78167 462403710681259 18446744073709551614 37118488909 11141099973001 15463387808083

78167: Is already prime.

462403710681259 = 78167 (prime) * 5915587277 (prime)

18446744073709551614 = 2 (prime) * 9223372036854775807

37118488909 = 191519 (prime) * 193811 (prime)

11141099973001 = 1114111 (prime) * 9999991 (prime)

15463387808083 = 1878781 (prime) * 8230543 (prime

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago