Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/mpi/wait_buffer is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef toolx_mpi_wait_buffer
0005 #define toolx_mpi_wait_buffer
0006 
0007 #include <mpi.h>
0008 
0009 #include <ostream>
0010 
0011 namespace toolx {
0012 namespace mpi {
0013 
0014 inline bool wait_buffer(std::ostream& a_out,int a_rank,int a_src,int a_tag,const MPI_Comm& a_comm,
0015                         int& a_buffer_size,char*& a_buffer,int& a_probe_src,bool a_verbose = false) {
0016   a_buffer = 0;
0017   a_buffer_size = 0;
0018   a_probe_src = -1;
0019 
0020   MPI_Status status;
0021   if(::MPI_Probe(a_src,a_tag,a_comm,&status)!=MPI_SUCCESS) {
0022     a_out << "toolx::mpi::wait_buffer : rank " << a_rank << " : MPI_Probe : failed." << std::endl;
0023     return false;
0024   }
0025 
0026   if(::MPI_Get_count(&status,MPI_CHAR,&a_buffer_size)!=MPI_SUCCESS) {
0027     a_out << "toolx::mpi::wait_buffer : rank " << a_rank << " : MPI_Get_count : failed." << std::endl;
0028     a_buffer_size = 0;
0029     return false;
0030   }
0031 
0032   a_probe_src = status.MPI_SOURCE;
0033 
0034   if(!a_buffer_size) {
0035     a_out << "exlb::mpi::wait_buffer : MPI_Get_count returns zero data." << std::endl;
0036     a_probe_src = -1;
0037     return false;
0038   }
0039 
0040   if(a_verbose) a_out << "toolx::mpi::wait_buffer : rank " << a_rank << " : get_count " << a_buffer_size << std::endl;
0041 
0042   a_buffer = new char[a_buffer_size];
0043   if(!a_buffer) {
0044     a_out << "toolx::mpi::wait_buffer : rank " << a_rank << " : can't alloc buffer of size " << a_buffer_size << std::endl;
0045     a_buffer_size = 0;
0046     a_probe_src = -1;
0047     return false;
0048   }
0049 
0050   if(::MPI_Recv(a_buffer,a_buffer_size,MPI_CHAR,status.MPI_SOURCE,status.MPI_TAG,a_comm,&status)!=MPI_SUCCESS) {
0051     a_out << "toolx::mpi::wait_buffer : rank " << a_rank << " : MPI_Recv : failed." << std::endl;
0052     a_buffer_size = 0;
0053     delete [] a_buffer;
0054     a_buffer = 0;
0055     a_probe_src = -1;
0056     return false;
0057   }
0058 
0059   if(a_verbose) a_out << "toolx::mpi::wait_buffer : rank " << a_rank << " : unpack data ..." << std::endl;
0060 
0061   return true;
0062 }
0063 
0064 }}
0065 
0066 #endif