Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
check_load.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file sequential/check_load.cpp (January 6, 2018)
3  * \brief
4  * Check numbers loaded from a file for the varsigma_odd problem
5  * and print bad numbers or all, with or without path.
6  *
7  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
8  * http://www.opimedia.be/
9  */
10 
11 // \cond
12 #include <cstdlib>
13 
14 #include <chrono>
15 #include <iostream>
16 #include <vector>
17 // \endcond
18 
19 #include "../common/helper/helper.hpp"
21 
22 
23 
24 /* ***********
25  * Prototype *
26  *************/
27 
28 void
30 
31 
32 
33 /* **********
34  * Function *
35  ************/
36 
37 void
39  std::cerr << "Usage: check_load [options] filename" << std::endl
40  << std::endl
41  << "Options:" << std::endl
42  << " --complete check complete path until 1 (by default check only partial path until < n)" << std::endl
43  << " --print-all print all checked number (by default only bad number are printed)" << std::endl
44  << " --useless check all odd numbers (only with --complete option, by default avoid exactly divisible by 3, 7, 31 or 127)" << 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  bool complete = false;
66  std::string filename;
67  bool print_all = false;
68  bool useless = false;
69 
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 == "--complete") {
76  complete = true;
77  }
78  else if (param == "--print-all") {
79  print_all = true;
80  }
81  else if (param == "--useless") {
82  useless = true;
83  }
84  else if (i < static_cast<unsigned int>(argc)) {
85  filename = param;
86  }
87  else {
88  help_and_exit();
89  }
90  }
91 
92  if (filename.empty()) {
93  help_and_exit();
94  }
95 
96 
97  // Load numbers
98  const std::vector<sigmaodd::nat_type> list = sigmaodd::load_numbers(filename);
99 
100 
101  // Print intern configuration
103 
104 
105  // Print parameters
106  std::cout << "sequential/check_load"
107  << "\tFilename: " << filename
108  << "\tNb: " << list.size()
109  << "\tComplete?: " << helper::to_string(complete)
110  << "\tPrint all?: " << helper::to_string(print_all);
111  if (complete) {
112  std::cout << "\tUseless?: " << helper::to_string(useless);
113  }
114  std::cout << std::endl;
115 
116  // Print table legend
117  std::cout << std::endl
118  << "n\tLower\tPartial length\tPartial path";
119  if (complete) {
120  std::cout << "\tLength\tPath";
121  }
122  std::cout << std::endl;
123  std::cout.flush();
124 
125 
126  // Main calculation
127  const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
128 
129  for (sigmaodd::nat_type n : list) {
130  if (complete) {
131  sequential::sequential_check_varsigma_odd_complete(n, n, useless, true, print_all);
132  }
133  else {
134  sequential::sequential_check_varsigma_odd(n, n, true, print_all);
135  }
136  }
137 
138  // End
139  std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
140 
141  std::cout << "Total duration: " << helper::duration_to_string(duration)
142  << std::endl;
143 
144  return EXIT_SUCCESS;
145 }
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
Definition: primes.cpp:35
void sequential_check_varsigma_odd_complete(nat_type first_n, nat_type last_n, bool check_useless, bool print_bad, bool print_all, bool print_category, bool print_lower, bool print_length, bool print_path)
Check completely (until 1) in the order all odd numbers between first_n and last_n. The consequence of the result is that: all odd numbers checked between first_n and last_n (included) respect the conjecture.
Definition: sequential.cpp:148
int main(int argc, const char *const argv[])
Definition: check_load.cpp:56
void help_and_exit()
Definition: check_load.cpp:38
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
Implementation of the sequential algorithms presented in the report. (Some functions are not use in t...
std::vector< nat_type > load_numbers(const std::string &filename)
Read the file and extract each natural number begining a line. Return the list of these numbers...
Definition: helper.cpp:115
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Definition: helper.cpp:148
void sequential_check_varsigma_odd(nat_type first_n, nat_type last_n, bool print_bad, bool print_all, bool print_category, bool print_lower, bool print_length, bool print_path)
Check in the order all odd numbers between first_n and last_n. The consequence of the result is that:...
Definition: sequential.cpp:95
std::string to_string(bool b)
Return the string "true" if b, else "false".
Definition: helper.cpp:177