Go to the documentation of this file.
4 #ifndef tools_mpi_wrmpi
5 #define tools_mpi_wrmpi
22 #define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
23 #define TOOLS_MPI_INT64 MPI_LONG_LONG
28 #define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG
29 #define TOOLS_MPI_INT64 MPI_LONG
34 #define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
35 #define TOOLS_MPI_INT64 MPI_LONG_LONG
47 static const std::string s_v(
"tools::mpi::wrmpi");
51 virtual bool pack(
char a_val) {
55 m_out <<
"tools::mpi::wrmpi : MPI_Pack(char) failed." << std::endl;
61 virtual bool pack(
short a_val) {
65 m_out <<
"tools::mpi::wrmpi : MPI_Pack(short) failed." << std::endl;
71 virtual bool pack(
int a_val) {
75 m_out <<
"tools::mpi::wrmpi : MPI_Pack(int) failed." << std::endl;
81 virtual bool pack(
unsigned int a_val) {
85 m_out <<
"tools::mpi::wrmpi : MPI_Pack(unsigned int) failed." << std::endl;
95 m_out <<
"tools::mpi::wrmpi : MPI_Pack(uint64) failed." << std::endl;
105 m_out <<
"tools::mpi::wrmpi : MPI_Pack(int64) failed." << std::endl;
111 virtual bool pack(
float a_val) {
115 m_out <<
"tools::mpi::wrmpi : MPI_Pack(float) failed." << std::endl;
121 virtual bool pack(
double a_val) {
125 m_out <<
"tools::mpi::wrmpi : MPI_Pack(double) failed." << std::endl;
134 unsigned char val = a_val?1:0;
136 m_out <<
"tools::mpi::wrmpi : MPI_Pack(bool) failed." << std::endl;
142 virtual bool spack(
const std::string& a_s) {
143 if(!
pack((
num_t)a_s.size()))
return false;
146 #ifdef TOOLS_USE_MPI_PACK_NOT_CONST
151 m_out <<
"tools::mpi::wrmpi : MPI_Pack(std::string) failed." << std::endl;
157 virtual bool vpack(
const std::vector<unsigned int>& a_v) {
158 if(!
pack((
num_t)a_v.size()))
return false;
161 #ifdef TOOLS_USE_MPI_PACK_NOT_CONST
167 m_out <<
"tools::mpi::wrmpi : MPI_Pack(std::vector<unsigned int>) failed." << std::endl;
173 virtual bool vpack(
const std::vector<int>& a_v) {
174 if(!
pack((
num_t)a_v.size()))
return false;
177 #ifdef TOOLS_USE_MPI_PACK_NOT_CONST
182 m_out <<
"tools::mpi::wrmpi : MPI_Pack(std::vector<int>) failed." << std::endl;
188 virtual bool vpack(
const std::vector<double>& a_v) {
189 if(!
pack((
num_t)a_v.size()))
return false;
192 #ifdef TOOLS_USE_MPI_PACK_NOT_CONST
197 m_out <<
"tools::mpi::wrmpi : MPI_Pack(std::vector<double>) failed." << std::endl;
207 #ifdef TOOLS_USE_MPI_PACK_NOT_CONST
212 m_out <<
"tools::mpi::wrmpi : MPI_Pack(char*) failed." << std::endl;
223 #ifdef TOOLS_USE_MPI_PACK_NOT_CONST
228 m_out <<
"tools::mpi::wrmpi : MPI_Pack(int*) failed." << std::endl;
237 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(char) failed." << std::endl;
245 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(short) failed." << std::endl;
253 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(int) failed." << std::endl;
259 virtual bool unpack(
unsigned int& a_val) {
261 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(unsigned int) failed." << std::endl;
269 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(uint64) failed." << std::endl;
277 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(int64) failed." << std::endl;
285 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(float) failed." << std::endl;
293 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(double) failed." << std::endl;
300 typedef unsigned char bool_t;
303 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(bool) failed." << std::endl;
307 a_val = val==1?
true:
false;
310 virtual bool vunpack(std::vector<unsigned int>& a_v) {
312 if(!
unpack(num)) {a_v.clear();
return false;}
315 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(std::vector<unsigned int>) failed." << std::endl;
323 if(!
unpack(num)) {a_v.clear();
return false;}
326 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(std::vector<int>) failed." << std::endl;
332 virtual bool vunpack(std::vector<double>& a_v) {
334 if(!
unpack(num)) {a_v.clear();
return false;}
337 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(std::vector<double>) failed." << std::endl;
345 if(!
unpack(num)) {a_s.clear();
return false;}
348 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(std::string) failed." << std::endl;
356 if(!
unpack(num)) {a_size = 0;a_buffer = 0;
return false;}
357 a_buffer =
new char[num];
359 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(char*) failed." << std::endl;
370 if(!
unpack(num)) {a_size = 0;a_buffer = 0;
return false;}
371 a_buffer =
new int[num];
373 m_out <<
"tools::mpi::wrmpi : MPI_Unpack(int*) failed." << std::endl;
395 m_out <<
"tools::mpi::wrmpi::send_buffer : MPI_Send() failed for rank destination " << a_dest <<
"." << std::endl;
401 virtual bool wait_buffer(
int a_rank,
int a_src,
int a_tag,
int& a_probe_src,
bool a_verbose =
false) {
405 m_out <<
"tools::mpi::wrmpi::wait_buffer : failed for rank " << a_rank <<
" and source " << a_src <<
"." << std::endl;
418 virtual bool wait_buffer(
int a_rank,
int a_tag,
int& a_probe_src,
bool a_verbose =
false) {
433 tools::mem::increment(
s_class().c_str());
451 tools::mem::increment(
s_class().c_str());
459 tools::mem::decrement(
s_class().c_str());
474 tools::mem::increment(
s_class().c_str());
480 #ifdef TOOLS_USE_MPI_PACK_NOT_CONST
492 m_out <<
"tools::mpi::wrmpi::expand :"
493 <<
" can't realloc " << a_new_size <<
" bytes."
int MPI_Send(const void *, int, MPI_Datatype, int, int, MPI_Comm)
int MPI_Pack(const void *, int, MPI_Datatype, void *, int, int *, MPI_Comm)
void * MPI_Comm
to pass hd2mpi ////////////////////////////////////////////
#define MPI_UNSIGNED_CHAR
int MPI_Unpack(const void *, int, int *, void *, int, MPI_Datatype, MPI_Comm)