19 #include "../common/helper/helper.hpp" 39 std::cerr <<
"Usage: check_gentle [options] (multi-threads version)" << std::endl
41 <<
"Version options of the parallel algorithm:" << std::endl
42 <<
" --by-range range of number for each thread with a barrier" << std::endl
43 <<
" --dynamic like by range but without barrier (by default)" << std::endl
44 <<
" --one-by-one one number for each thread with a barrier" << std::endl
46 <<
"Options:" << std::endl
47 <<
" --bad-table filename load bad numbers from this file" << std::endl
48 <<
" (If load bad numbers then must be contains all bad numbers < first." << std::endl
49 <<
" Can load them with several files.)" << std::endl
50 <<
" --first n first odd number to check (3 by default)" << std::endl
51 <<
" --last n last odd number to check (1000001 by default)" << std::endl
52 <<
" --nb n number of odd numbers to check" << std::endl
53 <<
" --nb-thread n number of threads (2 by default)" << std::endl
54 <<
" --no-print do not print bad numbers" << std::endl;
65 main(
int argc,
const char*
const argv[]) {
74 enum Algos:
unsigned int {by_range, dynamic, one_by_one};
76 const std::string algo_strings[3] = {
"by-range",
80 unsigned int algo = dynamic;
81 std::vector<sigmaodd::nat_type> bad_table;
84 unsigned int nb_thread = 2;
85 bool print_bad =
true;
89 for (
unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
90 const std::string param(argv[i]);
92 if (param ==
"--bad-table") {
96 std::cerr <<
"! Failed reading file \"" << filename <<
'"' << std::endl;
101 if (bad_table.empty()) {
102 std::cerr <<
"! Wrong format for the bad table file \"" << filename <<
'"' << std::endl;
106 else if (param ==
"--by-range") {
109 else if (param ==
"--first") {
115 else if (param ==
"--dynamic") {
118 else if (param ==
"--last") {
124 else if (param ==
"--nb") {
127 else if (param ==
"--nb-thread") {
129 if ((nb_thread == 0) || (nb_thread > 128)) {
133 else if (param ==
"--no-print") {
136 else if (param ==
"--one-by-one") {
144 const std::set<sigmaodd::nat_type> bad_table_set(bad_table.cbegin(), bad_table.cend());
148 const auto minmax = std::minmax_element(bad_table_set.cbegin(), bad_table_set.cend());
153 std::cout <<
"hardware_concurrency: " << std::thread::hardware_concurrency() << std::endl;
156 std::cout <<
"threads/check_gentle" 157 <<
"\t# threads: " << nb_thread
158 <<
"\tFirst: " << first
159 <<
"\tLast: " << last
160 <<
"\tNb: " << (first <= last
161 ? (last - first)/2 + 1
163 <<
"\tAlgorithm: " << algo_strings[algo];
164 if (!bad_table_set.empty()) {
165 std::cout <<
"\t# bad numbers loaded: " << bad_table_set.size()
166 <<
"\tBetween " << *minmax.first
167 <<
"\tand " << *minmax.second << std::endl;
169 std::cout << std::endl;
172 std::cout << std::endl
178 const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
180 if (algo == by_range) {
185 else if (algo == dynamic) {
190 else if (algo == one_by_one) {
200 std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
int main(int argc, const char *const argv[])
const std::string prime_filename
Default filename for the binary file "big_data/prime28.bin".
constexpr bool is_even(nat_type n)
Return true iff n is even.
std::string duration_to_string(std::chrono::duration< double > duration_second)
Return a string with the duration expressed in milliseconds, seconds, minutes and hours...
std::set< nat_type > threads_check_gentle_varsigma_odd__dynamic(unsigned int nb_thread, nat_type first_n, nat_type last_n, const std::set< nat_type > &previous_bad_table, bool print_bad, unsigned int range_size, unsigned int master_range_size)
Check in the order all odd gentle numbers between first_n and last_n, and if print_bad then print all...
Implementation of the threads parallel algorithms presented in the report.
bool read_primes_table()
Read the binary file prime_filename to fill the table with all primes < 2^28. This table must be read...
bool is_file_exists(std::string filename)
Return true iff the file (or directory) exists.
std::set< nat_type > threads_check_gentle_varsigma_odd__by_range(unsigned int nb_thread, nat_type first_n, nat_type last_n, const std::set< nat_type > &previous_bad_table, bool print_bad, unsigned int range_size)
std::string get_string(int argc, const char *const argv[], unsigned int i, void(*help_and_exit_function)())
Return argv[i] converted in string.
std::set< nat_type > threads_check_gentle_varsigma_odd__one_by_one(unsigned int nb_thread, nat_type first_n, nat_type last_n, const std::set< nat_type > &previous_bad_table, bool print_bad)
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
unsigned long get_ulong(int argc, const char *const argv[], unsigned int i, void(*help_and_exit_function)())
Return argv[i] converted in integer.
std::vector< nat_type > load_bad_table(const std::string &filename, const std::vector< nat_type > &bad_table)
Read a file that contains list of bad numbers, add after bad_table, and return the result...