Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
mpi.hpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file mpi/mpi/mpi.hpp (January 17, 2018)
3  * \brief
4  * Implementation of the message-passing (MPI) algorithms presented in the report.
5  *
6  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
7  * http://www.opimedia.be/
8  */
9 
10 #ifndef PROGS_SRC_MPI_MPI_MPI_HPP_
11 #define PROGS_SRC_MPI_MPI_MPI_HPP_
12 
13 // \cond
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wold-style-cast"
16 #pragma GCC diagnostic ignored "-Weffc++"
17 #include <mpi.h>
18 #pragma GCC diagnostic pop
19 
20 #include <set>
21 #include <string>
22 #include <utility>
23 // \endcond
24 
25 #include "../../common/sigmaodd/helper.hpp"
26 #include "../../common/sigmaodd/primes.hpp"
27 
28 
29 namespace mpi {
30 
33 
34 
35 
36  /* *******
37  * Types *
38  *********/
39 
40  /** \brief
41  * Type of MPI rank.
42  */
43  typedef unsigned int rank_type;
44 
45 
46  /** \brief
47  * Structure for first_n, last_n, bad_first_n and bad_last_n values.
48  */
49  typedef
56 
57 
58  /** \brief
59  * Structure for n, first_n and last_n values.
60  */
61  typedef
62  struct n_bad_bad_struct {
67 
68 
69 
70  /* ************
71  * Prototypes *
72  **************/
73 
74  /** \brief
75  * Return true iff the process send an empty finished message.
76  */
77  inline
78  bool
79  is_finished_from(rank_type from_rank);
80 
81 
82  /** \brief
83  * Return true iff rank correspond to the master instance.
84  */
85  constexpr
86  bool
87  is_master(rank_type rank);
88 
89 
90  /** \brief
91  * Check in the order all odd gentle numbers between first_n and last_n,
92  * and if print_bad
93  * then print all bad numbers between first_n and last_n (included).
94  * The consequence of the result is that:
95  * if (all numbers < first_n respect the conjecture)
96  * and (all perfect squares < last_n respect the conjecture)
97  * and (all bad numbers < last_n respect the conjecture)
98  * then all numbers < last_n respect the conjecture.
99  *
100  * One master process dispatch one range of numbers for each of the (nb_process - 1) slaves process
101  * and compute itself one range.
102  * There is no barrier, the master process dispatch new range for free slave process
103  * and compute itself one new range.
104  * And so forth with next numbers.
105  *
106  * Printing is do in increasing order.
107  *
108  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
109  *
110  * @param first_n 3 <= odd <= last_n
111  * @param last_n <= MAX_POSSIBLE_N
112  * @param previous_bad_table if not empty then must be contains all bad numbers < first_n
113  * @param print_bad
114  * @param range_size even
115  * @param master_range_size even
116  *
117  * @return the set of all bad numbers between first_n and last_n (included)
118  */
119  std::set<nat_type>
122  const std::set<nat_type> &previous_bad_table = std::set<nat_type>(),
123  bool print_bad = true,
124  unsigned int range_size = 20000,
125  unsigned int master_range_size = 200);
126 
127 
128  /**
129  * Check in the order all odd gentle numbers between first_n and last_n,
130  * and if print_bad
131  * then print all bad numbers between first_n and last_n (included).
132  * The consequence of the result is that:
133  * if (all numbers < first_n respect the conjecture)
134  * and (all perfect squares < last_n respect the conjecture)
135  * and (all bad numbers < last_n respect the conjecture)
136  * then all numbers < last_n respect the conjecture.
137  *
138  * One master process dispatch one number for each of the (nb_process - 1) slaves process
139  * and compute itself one number.
140  * Then wait that they all finish, and so forth with next numbers.
141  *
142  * Printing is do in not deterministic order.
143  *
144  * sigmaodd::primes.cpp must be compiled without the macro PRIME16.
145  *
146  * @param first_n 3 <= odd <= last_n
147  * @param last_n <= MAX_POSSIBLE_N
148  * @param previous_bad_table if not empty then must be contains all bad numbers < first_n
149  * @param print_bad
150  *
151  * @return the set of all bad numbers between first_n and last_n (included)
152  */
153  std::set<nat_type>
155  (nat_type first_n, nat_type last_n,
156  const std::set<nat_type> &previous_bad_table = std::set<nat_type>(),
157  bool print_bad = true);
158 
159 
160  /** \brief
161  * Return the number of process.
162  */
163  inline
164  unsigned int
165  mpi_nb_process();
166 
167 
168  /** \brief
169  * Return the processor name.
170  */
171  inline
172  std::string
174 
175 
176  /** \brief
177  * Return the rank of this process.
178  */
179  inline
180  unsigned int
181  mpi_rank();
182 
183 
184  /** \brief
185  * Computation of one n by a slave,
186  * for the mpi_check_gentle_varsigma_odd__one_by_one() master function.
187  */
188  bool
190 
191 
192  /** \brief
193  * Computation of one range by a slave,
194  * for the mpi_check_gentle_varsigma_odd__dynamic() master function.
195  */
196  bool
198 
199  /** \brief
200  * Print the Open MPI version and the library version.
201  */
202  void
204 
205 
206  /** \brief
207  * Send bad values to a process.
208  */
209  void
210  send_bad_table_to(const std::set<nat_type> &bad_table, rank_type to_rank);
211 
212 
213  /** \brief
214  * Send a boolean value to the master.
215  */
216  inline
217  void
218  send_bool_to_master(bool b);
219 
220 
221  /** \brief
222  * Send a finished empty message to the master.
223  */
224  inline
225  void
227 
228 
229  /** \brief
230  * Send first_n, last_n, bad_first and bad_last_n to a process.
231  */
232  inline
233  void
236  rank_type to_rank);
237 
238 
239  /** \brief
240  * Send n, first_n and last_n to a process.
241  */
242  inline
243  void
244  send_n_bad_bad_to(nat_type n, nat_type first_n, nat_type last_n,
245  rank_type to_rank);
246 
247 
248  /** \brief
249  * Send a value to a process.
250  */
251  inline
252  void
253  send_n_to(nat_type n, rank_type to_rank);
254 
255 
256  /** \brief
257  * Send a range (first_n, last_n) to a process.
258  */
259  inline
260  void
261  send_range_to(nat_type first_n, nat_type last_n, rank_type to_rank);
262 
263 
264  /** \brief
265  * Send a size to a process.
266  */
267  inline
268  void
269  send_size_to(unsigned int size, rank_type to_rank);
270 
271 
272  /** \brief
273  * Wait and receive bad values from a process.
274  */
275  std::set<nat_type>
276  wait_bad_table_from(rank_type from_rank);
277 
278 
279  /** \brief
280  * Wait and receive a boolean value from a process.
281  */
282  inline
283  bool
284  wait_bool_from(rank_type from_rank);
285 
286 
287  /** \brief
288  * Wait and received a finished empty message from a process.
289  */
290  inline
291  void
292  wait_finished_from(rank_type from_rank);
293 
294 
295  /** \brief
296  * Wait and receive values first_n, last_n and bad_last_n from the master.
297  */
298  inline
301 
302 
303  /** \brief
304  * Wait and receive values n, first_n and last_n from the master.
305  */
306  inline
309 
310 
311  /** \brief
312  * Wait and receive a value from the master.
313  */
314  inline
315  nat_type
317 
318 
319  /** \brief
320  * Wait and receive a range (first_n, last_n) from the master.
321  */
322  inline
323  std::pair<nat_type, nat_type>
325 
326 
327  /** \brief
328  * Wait and receive a size from a process.
329  */
330  inline
331  unsigned int
332  wait_size_from(rank_type from_rank);
333 
334 } // namespace mpi
335 
336 #include "mpi__inline.hpp"
337 
338 #endif // PROGS_SRC_MPI_MPI_MPI_HPP_
unsigned int mpi_rank()
Return the rank of this process.
Definition: mpi__inline.hpp:78
void send_size_to(unsigned int size, rank_type to_rank)
Send a size to a process.
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...
Definition: mpi.cpp:237
unsigned int wait_size_from(rank_type from_rank)
Wait and receive a size from a process.
uint64_t nat_type
Type for natural number used in all code, on 64 bits.
Definition: helper.hpp:33
Structure for n, first_n and last_n values.
Definition: mpi.hpp:61
void send_bool_to_master(bool b)
Send a boolean value to the master.
Definition: mpi__inline.hpp:92
first_last_bad_bad_type wait_first_last_bad_bad_from_master()
Wait and receive values first_n, last_n and bad_last_n from the master.
nat_type bad_first_n
Definition: mpi.hpp:64
void print_mpi_versions()
Print the Open MPI version and the library version.
Definition: mpi.cpp:300
Definition: mpi.cpp:21
void send_finished_to_master()
Send a finished empty message to the master.
uint32_t prime_type
Type for prime number, particularly for the table of primes.
Definition: primes.hpp:49
nat_type wait_n_from_master()
Wait and receive a value from the master.
sigmaodd::nat_type nat_type
Definition: mpi.hpp:31
std::set< nat_type > wait_bad_table_from(rank_type from_rank)
Wait and receive bad values from a process.
Definition: mpi.cpp:332
bool wait_bool_from(rank_type from_rank)
Wait and receive a boolean value from a process.
unsigned int mpi_nb_process()
Return the number of process.
Definition: mpi__inline.hpp:52
unsigned int rank
struct mpi::first_last_bad_bad_struct first_last_bad_bad_type
Structure for first_n, last_n, bad_first_n and bad_last_n values.
void send_n_to(nat_type n, rank_type to_rank)
Send a value to a process.
unsigned int rank_type
Type of MPI rank.
Definition: mpi.hpp:43
bool is_finished_from(rank_type from_rank)
Return true iff the process send an empty finished message.
Definition: mpi__inline.hpp:38
std::string mpi_processor_name()
Return the processor name.
Definition: mpi__inline.hpp:66
std::pair< nat_type, nat_type > wait_range_from_master()
Wait and receive a range (first_n, last_n) from the master.
void send_bad_table_to(const std::set< nat_type > &bad_table, rank_type to_rank)
Send bad values to a process.
Definition: mpi.cpp:315
Structure for first_n, last_n, bad_first_n and bad_last_n values.
Definition: mpi.hpp:49
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)
Definition: mpi.cpp:147
void send_first_last_bad_bad_to(nat_type first_n, nat_type last_n, nat_type bad_first_n, nat_type bad_last_n, rank_type to_rank)
Send first_n, last_n, bad_first and bad_last_n to a process.
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...
Definition: mpi.cpp:28
nat_type bad_last_n
Definition: mpi.hpp:65
bool mpi_slave_wait_compute_range()
Computation of one range by a slave, for the mpi_check_gentle_varsigma_odd__dynamic() master function...
Definition: mpi.cpp:265
struct mpi::n_bad_bad_struct n_bad_bad_type
Structure for n, first_n and last_n values.
n_bad_bad_type wait_n_bad_bad_from_master()
Wait and receive values n, first_n and last_n from the master.
void send_range_to(nat_type first_n, nat_type last_n, rank_type to_rank)
Send a range (first_n, last_n) to a process.
sigmaodd::prime_type prime_type
Definition: mpi.hpp:32
void wait_finished_from(rank_type from_rank)
Wait and received a finished empty message from a process.
void send_n_bad_bad_to(nat_type n, nat_type first_n, nat_type last_n, rank_type to_rank)
Send n, first_n and last_n to a process.
constexpr bool is_master(rank_type rank)
Return true iff rank correspond to the master instance.
Definition: mpi__inline.hpp:27