Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
benchmarks_big.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file common/benchmarks_big.cpp (January 5 , 2018)
3  * \brief
4  * Some benchmarks for the sigma_odd problem,
5  * only on some "big" numbers.
6  *
7  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
8  * http://www.opimedia.be/
9  */
10 
11 // \cond
12 #include <cstdlib>
13 
14 #include <algorithm>
15 #include <chrono>
16 #include <iostream>
17 // \endcond
18 
19 #include "helper/helper.hpp"
20 #include "sigmaodd/pentagonal.hpp"
21 #include "sigmaodd/primes.hpp"
22 #include "sigmaodd/sigmaodd.hpp"
23 
24 
25 
26 /* ***********
27  * Prototype *
28  *************/
29 
30 void
32 
33 
34 
35 /* **********
36  * Function *
37  ************/
38 
39 void
41  std::cerr << "Usage: benchmarks [option]" << std::endl
42  << std::endl
43  << "Option:" << std::endl
44  << " --nb n number of odd numbers to check by range (100 by default)" << std::endl;
45 
46  exit(EXIT_FAILURE);
47 }
48 
49 
50 
51 /* ******
52  * Main *
53  ********/
54 
55 int
56 main(int argc, const char* const argv[]) {
57  // Load primes table
59  std::cerr << "! Impossible to load \"" << sigmaodd::prime_filename << '"' << std::endl
60  << std::endl;
61  help_and_exit();
62  }
63 
64 
65  std::srand(666); // to have deterministic "random" numbers
66 
67  const sigmaodd::nat_type first = 2305843009213693945u;
68  // 2305843009213693951 is prime, https://oeis.org/A000668
69  sigmaodd::nat_type nb = 100;
70 
71  // Read command line parameters
72  for (unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
73  const std::string param(argv[i]);
74 
75  if (param == "--nb") {
76  nb = helper::get_ulong(argc, argv, ++i, &help_and_exit);;
77  }
78  else {
79  help_and_exit();
80  }
81  }
82 
83  const sigmaodd::nat_type last = first + nb*2;
84 
85  assert(sigmaodd::is_odd(first));
86  assert(sigmaodd::is_odd(last));
87 
88 
89  // Print intern configuration
91 
92 
93  // Print parameter
94  std::cout << "First: " << first
95  << "\tLast: " << last
96  << "\tNb: " << nb << std::endl;
97 
98 
99  // Print table legend
100  std::cout << std::endl
101  << " \t \t/# nb tested\t/# nb naturals\t% tested" << std::endl;
102  std::cout.flush();
103 
104 
105  // Main calculation
106  std::chrono::duration<double> total_duration = std::chrono::duration<double>(0);
107 
108 
109  // Factorize
110  {
111  sigmaodd::nat_type real_nb = 0;
112  const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
113 
114  for (sigmaodd::nat_type n = first; n <= last; n += 2) {
116  continue;
117  }
118 
119  ++real_nb;
120 
121 #pragma GCC diagnostic push
122 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
123  volatile const std::pair<sigmaodd::nat_type, unsigned int> result_length
125 #pragma GCC diagnostic pop
126  }
127 
128  const std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
129 
130  std::cout << "Factorize\taverage:\t"
131  << static_cast<double>(duration.count())/static_cast<double>(real_nb) << " s\t"
132  << static_cast<double>(duration.count())/static_cast<double>(nb*2) << " s\t"
133  << static_cast<double>(real_nb*100)/static_cast<double>(nb*2) << "%"
134  << std::endl;
135  total_duration += duration;
136  }
137  std::cout.flush();
138 
139  // Factorize bound
140  {
141  sigmaodd::nat_type real_nb = 0;
142  const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
143 
144  for (sigmaodd::nat_type n = first; n <= last; n += 2) {
146  continue;
147  }
148 
149  ++real_nb;
150 
151 #pragma GCC diagnostic push
152 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
153  volatile const std::pair<sigmaodd::nat_type, unsigned int> result_length
155 #pragma GCC diagnostic pop
156  }
157 
158  const std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
159 
160  std::cout << "Factorize bound\taverage:\t"
161  << static_cast<double>(duration.count())/static_cast<double>(real_nb) << " s\t"
162  << static_cast<double>(duration.count())/static_cast<double>(nb*2) << " s\t"
163  << static_cast<double>(real_nb*100)/static_cast<double>(nb*2) << "%"
164  << std::endl;
165  total_duration += duration;
166  }
167 
168  std::cerr << "Total duration (for all calculation): "
169  << helper::duration_to_string(total_duration)
170  << std::endl;
171 
172  return EXIT_SUCCESS;
173 }
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
constexpr bool is_odd(nat_type n)
Return true iff n is odd.
std::pair< nat_type, unsigned int > sum_odd_divisors_divided_until_odd_iterate_until_lower__factorize(nat_type n)
Iterates the sum_odd_divisors_divided_until_odd__factorize() function from n until have a result lowe...
Definition: sigmaodd.cpp:712
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
Definition: primes.cpp:35
Functions to calculate pentagonal numbers and one useless algorithm that used the Euler formula to ca...
std::pair< nat_type, unsigned int > sum_odd_divisors_divided_until_odd_iterate_until_lower__factorize_bound(nat_type n)
Iterates the sum_odd_divisors_divided_until_odd__factorize() function from n until have a result lowe...
Definition: sigmaodd.cpp:731
std::string duration_to_string(std::chrono::duration< double > duration_second)
Return a string with the duration expressed in milliseconds, seconds, minutes and hours...
Definition: helper.cpp:61
bool read_primes_table()
Read the binary file prime_filename to fill the table with all primes < 2^28. This table must be read...
Definition: primes.cpp:241
Functions to access to tables of precaculated prime numbers and offsets to iterate on possible prime ...
Some generic helper functions for programs.
int main(int argc, const char *const argv[])
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Definition: helper.cpp:148
constexpr bool is_little_mersenne_prime_unitary_divide(nat_type n)
Return true iff at least one of 3, 7, 31, 127, 8191, 131071 or 524287 is an unitary divisor of n...
Main functions to deal the sigma_odd problem.
void help_and_exit()
unsigned long get_ulong(int argc, const char *const argv[], unsigned int i, void(*help_and_exit_function)())
Return argv[i] converted in integer.
Definition: helper.cpp:124