g4tools  5.4.0
Classes | Functions
tools::mpi Namespace Reference

Classes

class  hmpi
 
class  world
 
class  wrmpi
 

Functions

bool wait_buffer (std::ostream &a_out, int a_rank, int a_src, int a_tag, const MPI_Comm &a_comm, int &a_buffer_size, char *&a_buffer, int &a_probe_src, bool a_verbose=false)
 

Function Documentation

◆ wait_buffer()

bool tools::mpi::wait_buffer ( std::ostream &  a_out,
int  a_rank,
int  a_src,
int  a_tag,
const MPI_Comm a_comm,
int &  a_buffer_size,
char *&  a_buffer,
int &  a_probe_src,
bool  a_verbose = false 
)
inline

Definition at line 18 of file wait_buffer.

19  {
20  a_buffer = 0;
21  a_buffer_size = 0;
22  a_probe_src = -1;
23 
24  MPI_Status status;
25  if(::MPI_Probe(a_src,a_tag,a_comm,&status)!=MPI_SUCCESS) {
26  a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Probe : failed." << std::endl;
27  return false;
28  }
29 
30  if(::MPI_Get_count(&status,MPI_CHAR,&a_buffer_size)!=MPI_SUCCESS) {
31  a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Get_count : failed." << std::endl;
32  a_buffer_size = 0;
33  return false;
34  }
35 
36  a_probe_src = status.MPI_SOURCE;
37 
38  if(!a_buffer_size) {
39  a_out << "exlb::mpi::wait_buffer : MPI_Get_count returns zero data." << std::endl;
40  a_probe_src = -1;
41  return false;
42  }
43 
44  if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : get_count " << a_buffer_size << std::endl;
45 
46  a_buffer = new char[a_buffer_size];
47  if(!a_buffer) {
48  a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : can't alloc buffer of size " << a_buffer_size << std::endl;
49  a_buffer_size = 0;
50  a_probe_src = -1;
51  return false;
52  }
53 
54  if(::MPI_Recv(a_buffer,a_buffer_size,MPI_CHAR,status.MPI_SOURCE,status.MPI_TAG,a_comm,&status)!=MPI_SUCCESS) {
55  a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Recv : failed." << std::endl;
56  a_buffer_size = 0;
57  delete [] a_buffer;
58  a_buffer = 0;
59  a_probe_src = -1;
60  return false;
61  }
62 
63  if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : unpack data ..." << std::endl;
64 
65  return true;
66 }
MPI_CHAR
#define MPI_CHAR
Definition: dummy_mpi.h:20
_MPI_Status::MPI_TAG
int MPI_TAG
Definition: dummy_mpi.h:46
MPI_Recv
int MPI_Recv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *)
Definition: dummy_mpi.h:53
_MPI_Status::MPI_SOURCE
int MPI_SOURCE
Definition: dummy_mpi.h:45
_MPI_Status
to pass h2mpi, hs2mpi /////////////////////////////////////
Definition: dummy_mpi.h:44
MPI_SUCCESS
#define MPI_SUCCESS
Definition: dummy_mpi.h:30
MPI_Get_count
int MPI_Get_count(const MPI_Status *, MPI_Datatype, int *)
Definition: dummy_mpi.h:51
MPI_Probe
int MPI_Probe(int, int, MPI_Comm, MPI_Status *)
Definition: dummy_mpi.h:50