angel
mercurial changeset:
|
00001 // $Id: gmpi_impl.hpp,v 1.3 2004/02/22 18:44:46 gottschling Exp $ 00002 /* 00003 ############################################################# 00004 # This file is part of angel released under the BSD license # 00005 # The full COPYRIGHT notice can be found in the top # 00006 # level directory of the angel distribution # 00007 ############################################################# 00008 */ 00009 00010 00011 namespace GMPI { 00012 00013 template <class Comm_ref_t> 00014 void Comm::Send (const Comm_ref_t& data, int dest, int tag) const { 00015 typedef typename Comm_ref_t::base_t base_t; 00016 buffer_t<base_t> buffer; 00017 buffer << data.object_ref(); 00018 // size_t bsize= buffer.size(); 00019 // my_comm.Bsend (&bsize, 1, mpi_size_t, dest, tag); // at first send buffer size 00020 my_comm.Send (buffer.address(), buffer.size(), buffer.mpi_t, dest, tag); 00021 } 00022 00023 template <class Comm_ref_t> 00024 void Comm::Recv (Comm_ref_t& data, int source, int tag, MPI::Status& status) const { 00025 typedef typename Comm_ref_t::base_t base_t; 00026 // size_t bsize; 00027 // my_comm.Recv (&bsize, 1, mpi_size_t, source, tag, status); // at first receive buffer size 00028 // MPI::Status status; 00029 my_comm.Probe (source, tag, status); 00030 buffer_t<base_t> buffer; 00031 size_t bsize= status.Get_count (buffer.mpi_t); 00032 buffer.reserve (bsize); 00033 // if wildcards are used make sure to get the second message from the same processor 00034 // source= status.Get_source (); tag= status.Get_tag (); 00035 my_comm.Recv (buffer.address(), bsize, buffer.mpi_t, source, tag, status); 00036 } 00037 00038 template <class Comm_ref_t> 00039 void Intracomm::Bcast (Comm_ref_t& data, int root) const { 00040 typedef typename Comm_ref_t::base_t base_t; 00041 buffer_t<base_t> buffer; 00042 size_t bsize; 00043 if (Get_rank () == root) { 00044 buffer << data.object_ref(); bsize= buffer.size(); } 00045 my_comm.Bcast (&bsize, 1, mpi_size_t, root); 00046 if (Get_rank () != root) 00047 buffer.reserve (bsize); 00048 my_comm.Bcast (buffer.address(), bsize, buffer.mpi_t, root); 00049 if (Get_rank () != root) 00050 buffer >> data.object_ref(); 00051 } 00052 00053 } // namespace GMPI