20 #include "../common/helper/helper.hpp" 49 std::cerr <<
"Usage: check_gentle [options] (MPI version)" << std::endl
51 <<
"Version options of the parallel algorithm:" << std::endl
52 <<
" --dynamic range of number for each process without a barrier (by default)" << std::endl
53 <<
" --one-by-one one number for each process with a barrier" << std::endl
55 <<
"Options:" << std::endl
56 <<
" --bad-table filename load bad numbers from this file" << std::endl
57 <<
" (If load bad numbers then must be contains all bad numbers < first." << std::endl
58 <<
" Can load them with several files.)" << std::endl
59 <<
" --first n first odd number to check (3 by default)" << std::endl
60 <<
" --last n last odd number to check (1000001 by default)" << std::endl
61 <<
" --nb n number of odd numbers to check" << std::endl
62 <<
" --no-print do not print bad numbers" << std::endl;
75 main(
int argc,
char* argv[]) {
77 MPI_Init(&argc, &argv);
90 enum Algos:
unsigned int {dynamic, one_by_one};
92 const std::string algo_strings[2] = {
"dynamic",
95 unsigned int algo = dynamic;
96 std::vector<sigmaodd::nat_type> bad_table;
99 bool print_bad =
true;
103 for (
unsigned int i = 1; i < static_cast<unsigned int>(argc); ++i) {
104 const std::string param(argv[i]);
106 if (param ==
"--bad-table") {
111 std::cerr <<
"! Failed reading file \"" << filename <<
'"' << std::endl;
116 if (bad_table.empty()) {
117 std::cerr <<
"! Wrong format for the bad table file \"" << filename <<
'"' << std::endl;
122 else if (param ==
"--first") {
128 else if (param ==
"--dynamic") {
131 else if (param ==
"--last") {
137 else if (param ==
"--nb") {
140 else if (param ==
"--no-print") {
143 else if (param ==
"--one-by-one") {
156 const std::set<sigmaodd::nat_type> bad_table_set(bad_table.cbegin(), bad_table.cend());
160 const auto minmax = std::minmax_element(bad_table_set.cbegin(), bad_table_set.cend());
166 std::cout <<
"Process id: " <<
rank 171 std::cout <<
"mpi/check_gentle" 172 <<
"\tFirst: " << first
173 <<
"\tLast: " << last
174 <<
"\tNb: " << (first <= last
175 ? (last - first)/2 + 1
177 <<
"\tAlgorithm: " << algo_strings[algo];
178 if (!bad_table_set.empty()) {
179 std::cout <<
"\t# bad numbers loaded: " << bad_table_set.size()
180 <<
"\tBetween " << *minmax.first
181 <<
"\tand " << *minmax.second << std::endl;
183 std::cout << std::endl;
186 std::cout << std::endl
192 const double openmpi_start_time = MPI_Wtime();
193 const std::chrono::steady_clock::time_point clock_start = std::chrono::steady_clock::now();
195 if (algo == dynamic) {
200 else if (algo == one_by_one) {
211 const std::chrono::duration<double> duration = std::chrono::steady_clock::now() - clock_start;
212 const double openmpi_duration = MPI_Wtime() - openmpi_start_time;
223 if (algo == dynamic) {
228 else if (algo == one_by_one) {
unsigned int mpi_rank()
Return the rank of this process.
int main(int argc, char *argv[])
bool mpi_slave_wait_compute_n()
Computation of one n by a slave, for the mpi_check_gentle_varsigma_odd__one_by_one() master function...
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
std::string duration_ms_to_string(double duration_ms)
Return a string with the duration expressed in milliseconds, seconds, minutes and hours...
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...
void print_mpi_versions()
Print the Open MPI version and the library version.
bool read_primes_table()
Read the binary file prime_filename to fill the table with all primes < 2^28. This table must be read...
unsigned int mpi_nb_process()
Return the number of process.
bool is_file_exists(std::string filename)
Return true iff the file (or directory) exists.
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::string mpi_processor_name()
Return the processor name.
std::set< nat_type > mpi_check_gentle_varsigma_odd__one_by_one(nat_type first_n, nat_type last_n, const std::set< nat_type > &previous_bad_table, bool print_bad)
std::set< nat_type > mpi_check_gentle_varsigma_odd__dynamic(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...
void print_intern_config_compiler()
Print to stdcout the intern configuration of the compiler.
Implementation of the message-passing (MPI) algorithms presented in the report.
bool mpi_slave_wait_compute_range()
Computation of one range by a slave, for the mpi_check_gentle_varsigma_odd__dynamic() master function...
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...
constexpr bool is_master(rank_type rank)
Return true iff rank correspond to the master instance.