g4tools  5.4.0
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::mpi::hmpi Class Reference
Inheritance diagram for tools::mpi::hmpi:
Inheritance graph
[legend]
Collaboration diagram for tools::mpi::hmpi:
Collaboration graph
[legend]

Public Member Functions

virtual bool pack (const tools::histo::h1d &a_h)
 
virtual bool pack (const tools::histo::h2d &a_h)
 
virtual bool pack (const tools::histo::h3d &a_h)
 
virtual bool pack (const tools::histo::p1d &a_h)
 
virtual bool pack (const tools::histo::p2d &a_h)
 
virtual bool beg_send (unsigned int a_nhist)
 
virtual bool send (int a_dest)
 
virtual bool wait_histos (int a_src, std::vector< std::pair< std::string, void * > > &a_hists)
 
virtual int rank () const
 
virtual bool comm_rank (int &a_rank) const
 
virtual bool comm_size (int &a_size) const
 
 hmpi (std::ostream &a_out, int a_rank, int a_tag, const MPI_Comm &a_comm, bool a_verbose=false)
 
virtual ~hmpi ()
 

Protected Types

typedef unsigned int num_t
 

Protected Member Functions

 hmpi (const hmpi &a_from)
 
hmpioperator= (const hmpi &a_from)
 

Static Protected Member Functions

static const std::string & s_class ()
 

Protected Attributes

std::ostream & m_out
 
int m_rank
 
int m_tag
 
const MPI_Commm_comm
 
bool m_verbose
 
wrmpi m_wrmpi
 

Detailed Description

Definition at line 23 of file hmpi.

Member Typedef Documentation

◆ num_t

typedef unsigned int tools::mpi::hmpi::num_t
protected

Definition at line 26 of file hmpi.

Constructor & Destructor Documentation

◆ hmpi() [1/2]

tools::mpi::hmpi::hmpi ( std::ostream &  a_out,
int  a_rank,
int  a_tag,
const MPI_Comm a_comm,
bool  a_verbose = false 
)
inline

Definition at line 218 of file hmpi.

219  :m_out(a_out)
220  ,m_rank(a_rank)
221  ,m_tag(a_tag)
222  ,m_comm(a_comm)
223  ,m_verbose(a_verbose)
224  ,m_wrmpi(a_out,a_comm)
225  {
226 #ifdef TOOLS_MEM
227  tools::mem::increment(s_class().c_str());
228 #endif
229  }

◆ ~hmpi()

virtual tools::mpi::hmpi::~hmpi ( )
inlinevirtual

Reimplemented from tools::histo::hmpi.

Definition at line 230 of file hmpi.

230  {
231 #ifdef TOOLS_MEM
232  tools::mem::decrement(s_class().c_str());
233 #endif
234  }

◆ hmpi() [2/2]

tools::mpi::hmpi::hmpi ( const hmpi a_from)
inlineprotected

Definition at line 236 of file hmpi.

237  :parent(a_from)
238  ,m_out(a_from.m_out)
239  ,m_rank(a_from.m_rank)
240  ,m_tag(a_from.m_tag)
241  ,m_comm(a_from.m_comm)
242  ,m_verbose(a_from.m_verbose)
243  ,m_wrmpi(a_from.m_out,a_from.m_comm)
244  {
245 #ifdef TOOLS_MEM
246  tools::mem::increment(s_class().c_str());
247 #endif
248  }

Member Function Documentation

◆ beg_send()

virtual bool tools::mpi::hmpi::beg_send ( unsigned int  a_nhist)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 58 of file hmpi.

58  {
60  return m_wrmpi.pack(a_nhist);
61  }

◆ comm_rank()

virtual bool tools::mpi::hmpi::comm_rank ( int &  a_rank) const
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 209 of file hmpi.

209  {
210  if(::MPI_Comm_rank(m_comm,&a_rank)!=MPI_SUCCESS) {a_rank=-1;return false;}
211  return true;
212  }

◆ comm_size()

virtual bool tools::mpi::hmpi::comm_size ( int &  a_size) const
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 213 of file hmpi.

213  {
214  if(::MPI_Comm_size(m_comm,&a_size)!=MPI_SUCCESS) {a_size=0;return false;}
215  return true;
216  }

◆ operator=()

hmpi& tools::mpi::hmpi::operator= ( const hmpi a_from)
inlineprotected

Definition at line 249 of file hmpi.

249  {
250  m_rank = a_from.m_rank;
251  m_tag = a_from.m_tag;
252  m_verbose = a_from.m_verbose;
253  return *this;
254  }

◆ pack() [1/5]

virtual bool tools::mpi::hmpi::pack ( const tools::histo::h1d a_h)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 32 of file hmpi.

32  {
33  if(!m_wrmpi.spack(a_h.s_cls())) return false;
34  if(!histo_data_duiuid_pack(m_wrmpi,a_h.dac())) return false;
35  return true;
36  }

◆ pack() [2/5]

virtual bool tools::mpi::hmpi::pack ( const tools::histo::h2d a_h)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 37 of file hmpi.

37  {
38  if(!m_wrmpi.spack(a_h.s_cls())) return false;
39  if(!histo_data_duiuid_pack(m_wrmpi,a_h.dac())) return false;
40  return true;
41  }

◆ pack() [3/5]

virtual bool tools::mpi::hmpi::pack ( const tools::histo::h3d a_h)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 42 of file hmpi.

42  {
43  if(!m_wrmpi.spack(a_h.s_cls())) return false;
44  if(!histo_data_duiuid_pack(m_wrmpi,a_h.dac())) return false;
45  return true;
46  }

◆ pack() [4/5]

virtual bool tools::mpi::hmpi::pack ( const tools::histo::p1d a_h)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 47 of file hmpi.

47  {
48  if(!m_wrmpi.spack(a_h.s_cls())) return false;
49  if(!profile_data_duiuidd_pack(m_wrmpi,a_h.get_histo_data())) return false;
50  return true;
51  }

◆ pack() [5/5]

virtual bool tools::mpi::hmpi::pack ( const tools::histo::p2d a_h)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 52 of file hmpi.

52  {
53  if(!m_wrmpi.spack(a_h.s_cls())) return false;
54  if(!profile_data_duiuidd_pack(m_wrmpi,a_h.get_histo_data())) return false;
55  return true;
56  }

◆ rank()

virtual int tools::mpi::hmpi::rank ( ) const
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 208 of file hmpi.

208 { return m_rank;}

◆ s_class()

static const std::string& tools::mpi::hmpi::s_class ( )
inlinestaticprotected

Definition at line 27 of file hmpi.

27  {
28  static const std::string s_v("tools::mpi::hmpi");
29  return s_v;
30  }

◆ send()

virtual bool tools::mpi::hmpi::send ( int  a_dest)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 62 of file hmpi.

62  {
64  m_out << "tools::mpi::hmpi::send : rank " << m_rank << " : MPI_Send failed." << std::endl;
65  return false;
66  }
68  return true;
69  }

◆ wait_histos()

virtual bool tools::mpi::hmpi::wait_histos ( int  a_src,
std::vector< std::pair< std::string, void * > > &  a_hists 
)
inlinevirtual

Implements tools::histo::hmpi.

Definition at line 71 of file hmpi.

71  {
72  a_hists.clear();
73 
74  typedef std::pair<std::string,void*> class_pointer;
75 
76  MPI_Status status;
77  if(::MPI_Probe(a_src,m_tag,m_comm,&status)!=MPI_SUCCESS) {
78  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank << " : MPI_Probe : failed." << std::endl;
79  return false;
80  }
81 
82  int buffer_size = 0;
83  if(::MPI_Get_count(&status,MPI_CHAR,&buffer_size)!=MPI_SUCCESS) {
84  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank << " : MPI_Get_count : failed." << std::endl;
85  return false;
86  }
87 
88  if(!buffer_size) {
89  m_out << "exlb::mpi::wait_histos : MPI_Get_count returns zero data." << std::endl;
90  return false;
91  }
92 
93  if(m_verbose) m_out << "rank " << m_rank << " : get_count " << buffer_size << std::endl;
94 
95  char* buffer = new char[buffer_size];
96  if(!buffer) {
97  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank << " : can't alloc buffer of size " << buffer_size << std::endl;
98  return false;
99  }
100 
101  if(::MPI_Recv(buffer,buffer_size,MPI_CHAR,a_src,m_tag,m_comm,&status)!=MPI_SUCCESS) {
102  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank << " : MPI_Recv : failed." << std::endl;
103  delete [] buffer;
104  return false;
105  }
106 
107  if(m_verbose) m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank << " : unpack data ..." << std::endl;
108 
109  wrmpi _mpi(m_out,m_comm,buffer_size,buffer); //give ownership of buffer to _mpi.
110 
111  num_t nhist;
112  if(!_mpi.unpack(nhist)) return false;
113 
114  if(m_verbose)
115  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank << " : number of histos to unpack " << nhist << std::endl;
116 
117  {for(num_t ihist=0;ihist<nhist;ihist++) {
118 
119  std::string scls;
120  if(!_mpi.sunpack(scls)) return false;
121 
122  if(scls==tools::histo::h1d::s_class()) {
124  if(!histo_data_duiuid_unpack(_mpi,hdata)) return false;
125  tools::histo::h1d* h = new tools::histo::h1d("",10,0,1);
126  h->copy_from_data(hdata);
127  if(m_verbose) {
128  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank
129  << " : got a " << scls
130  << ", title " << h->title()
131  << ", mean_x " << h->mean() << ", rms " << h->rms()
132  << std::endl;
133  }
134  a_hists.push_back(class_pointer(h->s_cls(),h)); //give ownership of h.
135 
136  } else if(scls==tools::histo::h2d::s_class()) {
138  if(!histo_data_duiuid_unpack(_mpi,hdata)) return false;
139  tools::histo::h2d* h = new tools::histo::h2d("",10,0,1,10,0,1);
140  h->copy_from_data(hdata);
141  if(m_verbose) {
142  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank
143  << " : got a " << scls
144  << ", title " << h->title()
145  << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
146  << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
147  << std::endl;
148  }
149  a_hists.push_back(class_pointer(h->s_cls(),h)); //give ownership of h.
150 
151  } else if(scls==tools::histo::h3d::s_class()) {
153  if(!histo_data_duiuid_unpack(_mpi,hdata)) return false;
154  tools::histo::h3d* h = new tools::histo::h3d("",10,0,1,10,0,1,10,0,1);
155  h->copy_from_data(hdata);
156  if(m_verbose) {
157  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank
158  << " : got a " << scls
159  << ", title " << h->title()
160  << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
161  << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
162  << ", mean_z " << h->mean_z() << ", rms_z " << h->rms_z()
163  << std::endl;
164  }
165  a_hists.push_back(class_pointer(h->s_cls(),h)); //give ownership of h.
166 
167  } else if(scls==tools::histo::p1d::s_class()) {
169  if(!profile_data_duiuidd_unpack(_mpi,pdata)) return false;
170  tools::histo::p1d* h = new tools::histo::p1d("",10,0,1);
171  h->copy_from_data(pdata);
172  if(m_verbose) {
173  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank
174  << " : got a " << scls
175  << ", title " << h->title()
176  << ", mean_x " << h->mean() << ", rms " << h->rms()
177  << std::endl;
178  }
179  a_hists.push_back(class_pointer(h->s_cls(),h)); //give ownership of h.
180 
181  } else if(scls==tools::histo::p2d::s_class()) {
183  if(!profile_data_duiuidd_unpack(_mpi,pdata)) return false;
184  tools::histo::p2d* h = new tools::histo::p2d("",10,0,1,10,0,1);
185  h->copy_from_data(pdata);
186  if(m_verbose) {
187  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank
188  << " : got a " << scls
189  << ", title " << h->title()
190  << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
191  << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
192  << std::endl;
193  }
194  a_hists.push_back(class_pointer(h->s_cls(),h)); //give ownership of h.
195 
196  } else {
197  m_out << "tools::mpi::hmpi::wait_histos : rank " << m_rank
198  << " : got not treated class " << scls
199  << std::endl;
200  }
201 
202  }} //ihist
203 
204  return true;
205  }

Member Data Documentation

◆ m_comm

const MPI_Comm& tools::mpi::hmpi::m_comm
protected

Definition at line 259 of file hmpi.

◆ m_out

std::ostream& tools::mpi::hmpi::m_out
protected

Definition at line 256 of file hmpi.

◆ m_rank

int tools::mpi::hmpi::m_rank
protected

Definition at line 257 of file hmpi.

◆ m_tag

int tools::mpi::hmpi::m_tag
protected

Definition at line 258 of file hmpi.

◆ m_verbose

bool tools::mpi::hmpi::m_verbose
protected

Definition at line 260 of file hmpi.

◆ m_wrmpi

wrmpi tools::mpi::hmpi::m_wrmpi
protected

Definition at line 261 of file hmpi.


The documentation for this class was generated from the following file:
MPI_CHAR
#define MPI_CHAR
Definition: dummy_mpi.h:20
tools::histo::p1d
Definition: p1d:12
tools::histo::profile_data_duiuidd_pack
bool profile_data_duiuidd_pack(impi &a_mpi, const profile_data< double, unsigned int, unsigned int, double, double > &a_pd)
profile_data to C struct ////////////////////////////////////////////////
Definition: hd2mpi:170
MPI_Send
int MPI_Send(const void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition: dummy_mpi.h:52
tools::histo::b2::rms_x
TC rms_x() const
Definition: b2:37
tools::histo::h3d::s_class
static const std::string & s_class()
Definition: h3d:15
tools::histo::b3::rms_x
TC rms_x() const
Definition: b3:52
tools::mpi::hmpi::s_class
static const std::string & s_class()
Definition: hmpi:27
tools::mpi::hmpi::num_t
unsigned int num_t
Definition: hmpi:26
tools::mpi::wrmpi::pack_reset
virtual void pack_reset()
Definition: wrmpi:383
MPI_Comm_size
int MPI_Comm_size(MPI_Comm, int *)
Definition: dummy_mpi.h:64
tools::histo::h1d
Definition: h1d:14
MPI_Recv
int MPI_Recv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *)
Definition: dummy_mpi.h:53
tools::histo::p1d::s_class
static const std::string & s_class()
Definition: p1d:15
tools::histo::h2d::s_class
static const std::string & s_class()
Definition: h2d:15
tools::mpi::hmpi::m_verbose
bool m_verbose
Definition: hmpi:260
tools::histo::base_histo::dac
const hd_t & dac() const
Definition: base_histo:56
tools::histo::histo_data_duiuid_unpack
bool histo_data_duiuid_unpack(impi &a_mpi, histo_data< double, unsigned int, unsigned int, double > &a_hd)
Definition: hd2mpi:104
tools::histo::p2d
Definition: p2d:12
tools::histo::b3::mean_x
TC mean_x() const
Definition: b3:37
tools::histo::b2::mean_x
TC mean_x() const
Definition: b2:27
tools::mpi::hmpi::m_tag
int m_tag
Definition: hmpi:258
_MPI_Status
to pass h2mpi, hs2mpi /////////////////////////////////////
Definition: dummy_mpi.h:44
tools::histo::histo_data_duiuid_pack
bool histo_data_duiuid_pack(impi &a_mpi, const histo_data< double, unsigned int, unsigned int, double > &a_hd)
Definition: hd2mpi:36
tools::histo::h2d
Definition: h2d:12
tools::histo::b3::mean_z
TC mean_z() const
Definition: b3:47
tools::mpi::wrmpi::buffer
const char * buffer() const
Definition: wrmpi:483
tools::histo::b3::mean_y
TC mean_y() const
Definition: b3:42
tools::histo::b2::mean_y
TC mean_y() const
Definition: b2:32
tools::histo::b3::rms_y
TC rms_y() const
Definition: b3:58
tools::mpi::hmpi::m_rank
int m_rank
Definition: hmpi:257
tools::histo::p1d::s_cls
const std::string & s_cls() const
Definition: p1d:19
MPI_Comm_rank
int MPI_Comm_rank(MPI_Comm, int *)
Definition: dummy_mpi.h:65
MPI_SUCCESS
#define MPI_SUCCESS
Definition: dummy_mpi.h:30
tools::histo::profile_data
Definition: profile_data:13
tools::histo::p2d::s_class
static const std::string & s_class()
Definition: p2d:15
tools::histo::p2::copy_from_data
void copy_from_data(const pd_t &a_from)
Definition: p2:101
tools::histo::h3::copy_from_data
void copy_from_data(const hd_t &a_from)
Definition: h3:34
tools::histo::p1::copy_from_data
void copy_from_data(const pd_t &a_from)
Definition: p1:109
tools::histo::profile_data_duiuidd_unpack
bool profile_data_duiuidd_unpack(impi &a_mpi, profile_data< double, unsigned int, unsigned int, double, double > &a_pd)
mpi to profile_data /////////////////////////////////////////////////////
Definition: hd2mpi:190
tools::mpi::hmpi::m_out
std::ostream & m_out
Definition: hmpi:256
tools::histo::b1::rms
TC rms() const
Definition: b1:37
tools::histo::h1d::s_cls
const std::string & s_cls() const
Definition: h1d:21
tools::histo::h2d::s_cls
const std::string & s_cls() const
Definition: h2d:19
tools::histo::histo_data< double, unsigned int, unsigned int, double >
tools::histo::p2d::s_cls
const std::string & s_cls() const
Definition: p2d:19
tools::mpi::hmpi::m_wrmpi
wrmpi m_wrmpi
Definition: hmpi:261
tools::histo::h1d::s_class
static const std::string & s_class()
Definition: h1d:17
tools::histo::h1::copy_from_data
void copy_from_data(const hd_t &a_from)
Definition: h1:40
tools::histo::base_histo::title
const std::string & title() const
Definition: base_histo:87
tools::mpi::wrmpi::pack
virtual bool pack(char a_val)
Definition: wrmpi:51
MPI_Get_count
int MPI_Get_count(const MPI_Status *, MPI_Datatype, int *)
Definition: dummy_mpi.h:51
tools::histo::b3::rms_z
TC rms_z() const
Definition: b3:64
tools::histo::p1::get_histo_data
pd_t get_histo_data() const
Definition: p1:117
MPI_Probe
int MPI_Probe(int, int, MPI_Comm, MPI_Status *)
Definition: dummy_mpi.h:50
tools::mpi::wrmpi::ipos
int ipos() const
Definition: wrmpi:479
tools::histo::h3d
Definition: h3d:12
tools::histo::h2::copy_from_data
void copy_from_data(const hd_t &a_from)
Definition: h2:34
tools::mpi::wrmpi::spack
virtual bool spack(const std::string &a_s)
Definition: wrmpi:142
tools::histo::p2::get_histo_data
pd_t get_histo_data() const
Definition: p2:109
tools::histo::h3d::s_cls
const std::string & s_cls() const
Definition: h3d:19
tools::histo::b1::mean
TC mean() const
Definition: b1:30
tools::histo::b2::rms_y
TC rms_y() const
Definition: b2:43
tools::mpi::hmpi::m_comm
const MPI_Comm & m_comm
Definition: hmpi:259