openGPMP
Open Source Mathematics Package
Functions
factors.cpp File Reference
#include <chrono>
#include <cmath>
#include <iostream>
#include <openGPMP/core/threads.hpp>
#include <openGPMP/nt/factorization.hpp>
#include <vector>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void  )
Examples
factors.cpp.

Definition at line 15 of file factors.cpp.

15  {
16  gpmp::Factorization factorization;
17 
18  // find prime factor of 123456789
19  int64_t n = 9223372036854775803;
20  int64_t factor = factorization.pollard_rho(n);
21 
22  // print the result
23  std::cout << "The smallest prime factor of " << n << " is " << factor
24  << std::endl;
25 
26  /******* EXAMPLE USING openGPMP's THREADPOOL *******/
27  //
28  // specify the numbers to factorize
29  // pollard_rho accepts 64 bit integers
30  // std::vector<int64_t> nums_to_factorize = {
31  // 9223372036854775803, 9223372036854775807, 9223372036854775303,
32  // 4567890123456789LL, 5678901234567890LL, 6789012345678901LL,
33  // 7890123456789012LL, 8901234567890123LL};
34  std::vector<uint64_t> nums_to_factorize = {
35  9223372036854775803, 9223372036854775807, 9223372036854775303,
36  4567890123456789LL, 5678901234567890LL, 6789012345678901LL,
37  7890123456789012LL, 8901234567890123LL, 9999999967LL,
38  12345678901234567LL, 987654321987654321LL, 2147483647LL,
39  9223372036854775783LL, 1311768467463790320LL, 7237005577332262210LL,
40  3037000499LL, 2305843009213693951LL, 2305843009213693967LL,
41  2305843009213693971LL, 2305843009213693973LL, 2305843009213693977LL,
42  2305843009213693989LL};
43 
44  // std::vector<std::future<int64_t>> results =
45  // factorization.pollard_rho_thread(nums_to_factorize);
46 
47  // for (auto &res : results) {
48  // std::cout << res.get() << std::endl;
49  // }
50 
51  std::vector<std::future<uint64_t>> results;
53  gpmp::Factorization factors;
54  for (const auto &num : nums_to_factorize) {
55  results.emplace_back(gpmp::core::ThreadDispatch().dispatch(
56  *pool,
58  &factors,
59  num));
60  }
61 
62  for (auto &res : results) {
63  std::cout << res.get() << std::endl;
64  }
65 
66  delete pool;
67 
68  return 0;
69 }
uint64_t pollard_rho(uint64_t n)
A class that provides a function to dispatch a function call to a thread pool and return a future obj...
Definition: threads.hpp:204

References gpmp::Factorization::pollard_rho(), and python.linalg::res.