15 #include <boost/mpi/environment.hpp>
16 #include <boost/mpi/communicator.hpp>
17 #include <boost/mpi/collectives.hpp>
18 #include <boost/mpi/datatype.hpp>
19 #include <boost/optional.hpp>
22 namespace mpi = boost::mpi;
26 namespace communicationPolicy {
42 typedef unsigned ContextID;
43 typedef unsigned VAddr;
52 Context(ContextID contextID, mpi::communicator comm) :
60 id = otherContext.getID();
61 isValid = otherContext.valid();
62 comm = otherContext.comm;
71 VAddr getVAddr()
const {
75 ContextID getID()
const {
83 mpi::communicator comm;
100 Event(mpi::request request) : request(request){
114 boost::optional<mpi::status> status = request.test();
126 mpi::request request;
131 typedef unsigned Tag;
132 typedef unsigned ContextID;
133 typedef unsigned VAddr;
135 typedef unsigned MsgType;
141 initialContext(contextCount, mpi::communicator()){
143 uriMap.push_back(std::vector<Uri>());
145 for(
unsigned i = 0; i < initialContext.size(); ++i){
146 uriMap.back().push_back(i);
337 template <
typename T_Send,
typename T_Recv>
339 mpi::all_gather(context.comm, sendData.data(), sendData.size(), recvData.data());
459 template <
typename T_Send,
typename T_Recv,
typename T_Op>
461 mpi::all_reduce(context.comm, sendData.data(), sendData.size(), recvData.data(), op);
520 assert(vAddrs.size() > 0);
522 VAddr myVAddr = oldContext.getVAddr();
523 bool isPartOfNewContext =
false;
525 for(VAddr vAddr : vAddrs){
526 if(vAddr == myVAddr){
527 isPartOfNewContext =
true;
532 mpi::communicator newComm = oldContext.comm.split(isPartOfNewContext);
534 if(isPartOfNewContext){
535 std::array<Uri, 1> uri;
537 Context newContext(++contextCount, newComm);
538 uri[0] = newContext.getVAddr();
541 uriMap.push_back(std::vector<Uri>(newContext.size()));
542 std::vector<Uri> otherUris(newContext.size());
546 std::copy(otherUris.begin(), otherUris.end(), uriMap[newContext.getID()].begin());
566 return initialContext;
577 ContextID contextCount;
578 std::vector<std::vector<Uri>> uriMap;
579 Context initialContext;
580 mpi::environment env;
589 void error(VAddr vAddr, std::string msg){
590 std::cout <<
"[" << vAddr <<
"] " << msg;
599 template <
typename T_Context>
600 inline Uri getVAddrUri(
const T_Context context,
const VAddr vAddr){
603 uri = uriMap.at(context.getID()).at(vAddr);
605 }
catch(
const std::out_of_range& e){
606 std::stringstream errorStream;
607 errorStream <<
"MPI::getVAddrUri::" << e.what()<<
" : Communicator with ID " << vAddr <<
" is not part of the context " << context.getID() << std::endl;
608 error(context.getID(), errorStream.str());
Context createContext(const std::vector< VAddr > vAddrs, const Context oldContext)
Creates a new context from peer ids of an oldContext
Definition: MinBMPI.hpp:519
void allReduce(const Context context, T_Op op, const T_Send &sendData, T_Recv &recvData)
Collects sendData from all peers of the context. Size of sendData can vary in size. The data is received by every peer in the context.
Definition: MinBMPI.hpp:460
void allGather(const Context context, const T_Send &sendData, T_Recv &recvData)
Collects sendData from all peers of the context and transmits it as a list to the peer with rootVAddr...
Definition: MinBMPI.hpp:338
Implementation of the Cage communicationPolicy interface based on the MPI implementation boost::mpi...
Definition: MinBMPI.hpp:35
Context getGlobalContext()
Returns the context that contains all peers.
Definition: MinBMPI.hpp:565
A context represents a set of peers which are able to communicate with each other.
Definition: MinBMPI.hpp:41
An event is returned by non-blocking communication operations and can be asked whether an operation h...
Definition: MinBMPI.hpp:98