Loading [MathJax]/extensions/tex2jax.js
Parallel numerical verification of the σ_odd problem  October 6, 2018
All Classes Namespaces Files Functions Variables Typedefs Macros
mpi__inline.hpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 /** \file mpi/mpi/mpi__inline.hpp (January 17, 2018)
3  *
4  * GPLv3 --- Copyright (C) 2017, 2018 Olivier Pirson
5  * http://www.opimedia.be/
6  */
7 
8 #ifndef PROGS_SRC_MPI_MPI_MPI__INLINE_HPP_
9 #define PROGS_SRC_MPI_MPI_MPI__INLINE_HPP_
10 
11 // \cond
12 #include <cassert>
13 
14 #include <string>
15 #include <utility>
16 // \endcond
17 
18 
19 namespace mpi {
20 
21  /* ********************
22  * constexpr function *
23  **********************/
24 
25  constexpr
26  bool
28  return rank == 0;
29  }
30 
31 
32 
33  /* ******************
34  * inline functions *
35  ********************/
36  inline
37  bool
39  int is_finished;
40 
41 #pragma GCC diagnostic push
42 #pragma GCC diagnostic ignored "-Wold-style-cast"
43  MPI_Iprobe(from_rank, 0, MPI_COMM_WORLD, &is_finished, MPI_STATUS_IGNORE);
44 #pragma GCC diagnostic pop
45 
46  return is_finished;
47  }
48 
49 
50  inline
51  unsigned int
53  unsigned int nb_process;
54 
55 #pragma GCC diagnostic push
56 #pragma GCC diagnostic ignored "-Wold-style-cast"
57  MPI_Comm_size(MPI_COMM_WORLD, reinterpret_cast<int*>(&nb_process));
58 #pragma GCC diagnostic pop
59 
60  return nb_process;
61  }
62 
63 
64  inline
65  std::string
67  char processor_name[MPI_MAX_PROCESSOR_NAME];
68  unsigned int len;
69 
70  MPI_Get_processor_name(processor_name, reinterpret_cast<int*>(&len));
71 
72  return std::string(processor_name);
73  }
74 
75 
76  inline
77  unsigned int
79  unsigned int rank;
80 
81 #pragma GCC diagnostic push
82 #pragma GCC diagnostic ignored "-Wold-style-cast"
83  MPI_Comm_rank(MPI_COMM_WORLD, reinterpret_cast<int*>(&rank));
84 #pragma GCC diagnostic pop
85 
86  return rank;
87  }
88 
89 
90  inline
91  void
93  const uint32_t n = b;
94 
95 #pragma GCC diagnostic push
96 #pragma GCC diagnostic ignored "-Wold-style-cast"
97  MPI_Send(&n, 1, MPI_UINT32_T, 0, 0, MPI_COMM_WORLD);
98 #pragma GCC diagnostic pop
99  }
100 
101 
102  inline
103  void
105 #pragma GCC diagnostic push
106 #pragma GCC diagnostic ignored "-Wold-style-cast"
107  MPI_Send(nullptr, 0, MPI_UINT32_T, 0, 0, MPI_COMM_WORLD);
108 #pragma GCC diagnostic pop
109  }
110 
111 
112  inline
113  void
115  nat_type bad_first_n, nat_type bad_last_n,
116  rank_type to_rank) {
117  assert(sizeof(nat_type) == 8);
118 
119  const uint64_t data[4] = {first_n, last_n, bad_first_n, bad_last_n};
120 
121 #pragma GCC diagnostic push
122 #pragma GCC diagnostic ignored "-Wold-style-cast"
123  MPI_Send(data, 4, MPI_UINT64_T, to_rank, 0, MPI_COMM_WORLD);
124 #pragma GCC diagnostic pop
125  }
126 
127 
128  inline
129  void
131  rank_type to_rank) {
132  assert(sizeof(nat_type) == 8);
133 
134  const uint64_t data[3] = {n, first_n, last_n};
135 
136 #pragma GCC diagnostic push
137 #pragma GCC diagnostic ignored "-Wold-style-cast"
138  MPI_Send(data, 3, MPI_UINT64_T, to_rank, 0, MPI_COMM_WORLD);
139 #pragma GCC diagnostic pop
140  }
141 
142 
143  inline
144  void
146  assert(sizeof(nat_type) == 8);
147 
148 #pragma GCC diagnostic push
149 #pragma GCC diagnostic ignored "-Wold-style-cast"
150  MPI_Send(&n, 1, MPI_UINT64_T, to_rank, 0, MPI_COMM_WORLD);
151 #pragma GCC diagnostic pop
152  }
153 
154 
155  inline
156  void
157  send_range_to(nat_type first_n, nat_type last_n, rank_type to_rank) {
158  assert(sizeof(nat_type) == 8);
159 
160  const nat_type data[2] = {first_n, last_n};
161 
162 #pragma GCC diagnostic push
163 #pragma GCC diagnostic ignored "-Wold-style-cast"
164  MPI_Send(data, 2, MPI_UINT64_T, to_rank, 0, MPI_COMM_WORLD);
165 #pragma GCC diagnostic pop
166  }
167 
168 
169  inline
170  void
171  send_size_to(unsigned int size, rank_type to_rank) {
172  uint32_t n = size;
173 
174 #pragma GCC diagnostic push
175 #pragma GCC diagnostic ignored "-Wold-style-cast"
176  MPI_Send(&n, 1, MPI_UINT32_T, to_rank, 0, MPI_COMM_WORLD);
177 #pragma GCC diagnostic pop
178  }
179 
180 
181  inline
182  bool
184  uint32_t n;
185 
186 #pragma GCC diagnostic push
187 #pragma GCC diagnostic ignored "-Wold-style-cast"
188  MPI_Recv(&n, 1, MPI_UINT32_T, from_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
189 #pragma GCC diagnostic pop
190 
191  return n;
192  }
193 
194 
195  inline
196  void
198 #pragma GCC diagnostic push
199 #pragma GCC diagnostic ignored "-Wold-style-cast"
200  MPI_Recv(nullptr, 0, MPI_UINT32_T, from_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
201 #pragma GCC diagnostic pop
202  }
203 
204 
205  inline
208  assert(sizeof(nat_type) == 8);
209 
210  uint64_t data[4];
211 
212 #pragma GCC diagnostic push
213 #pragma GCC diagnostic ignored "-Wold-style-cast"
214  MPI_Recv(data, 4, MPI_UINT64_T, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
215 #pragma GCC diagnostic pop
216 
217  return {data[0], data[1], data[2], data[3]};
218  }
219 
220 
221  inline
224  assert(sizeof(nat_type) == 8);
225 
226  uint64_t data[3];
227 
228 #pragma GCC diagnostic push
229 #pragma GCC diagnostic ignored "-Wold-style-cast"
230  MPI_Recv(data, 3, MPI_UINT64_T, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
231 #pragma GCC diagnostic pop
232 
233  return {data[0], data[1], data[2]};
234  }
235 
236 
237  inline
238  nat_type
240  assert(sizeof(nat_type) == 8);
241 
242  uint64_t n;
243 
244 #pragma GCC diagnostic push
245 #pragma GCC diagnostic ignored "-Wold-style-cast"
246  MPI_Recv(&n, 1, MPI_UINT64_T, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
247 #pragma GCC diagnostic pop
248 
249  return n;
250  }
251 
252 
253  inline
254  std::pair<nat_type, nat_type>
256  assert(sizeof(nat_type) == 8);
257 
258  nat_type data[2];
259 
260 #pragma GCC diagnostic push
261 #pragma GCC diagnostic ignored "-Wold-style-cast"
262  MPI_Recv(data, 2, MPI_UINT64_T, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
263 #pragma GCC diagnostic pop
264 
265  return std::make_pair(data[0], data[1]);
266  }
267 
268 
269  inline
270  unsigned int
272  uint32_t n;
273 
274 #pragma GCC diagnostic push
275 #pragma GCC diagnostic ignored "-Wold-style-cast"
276  MPI_Recv(&n, 1, MPI_UINT32_T, from_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
277 #pragma GCC diagnostic pop
278 
279  return n;
280  }
281 } // namespace mpi
282 
283 #endif // PROGS_SRC_MPI_MPI_MPI__INLINE_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.
unsigned int wait_size_from(rank_type from_rank)
Wait and receive a size from a process.
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.
Definition: mpi.cpp:21
void send_finished_to_master()
Send a finished empty message to the master.
nat_type wait_n_from_master()
Wait and receive a value from the master.
sigmaodd::nat_type nat_type
Definition: mpi.hpp:31
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
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.
Structure for first_n, last_n, bad_first_n and bad_last_n values.
Definition: mpi.hpp:49
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.
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.
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