[2343] | 1 | #include "context_server.hpp" |
---|
| 2 | #include "buffer_in.hpp" |
---|
| 3 | #include "type.hpp" |
---|
| 4 | #include "context.hpp" |
---|
| 5 | #include "object_template.hpp" |
---|
| 6 | #include "group_template.hpp" |
---|
| 7 | #include "attribute_template.hpp" |
---|
| 8 | #include "domain.hpp" |
---|
| 9 | #include "field.hpp" |
---|
| 10 | #include "file.hpp" |
---|
| 11 | #include "grid.hpp" |
---|
| 12 | #include "mpi.hpp" |
---|
| 13 | #include "tracer.hpp" |
---|
| 14 | #include "timer.hpp" |
---|
| 15 | #include "cxios.hpp" |
---|
| 16 | #include "event_scheduler.hpp" |
---|
| 17 | #include "server.hpp" |
---|
| 18 | #include "servers_ressource.hpp" |
---|
| 19 | #include "pool_ressource.hpp" |
---|
| 20 | #include "services.hpp" |
---|
| 21 | #include "contexts_manager.hpp" |
---|
| 22 | #include "timeline_events.hpp" |
---|
| 23 | #include "one_sided_context_server.hpp" |
---|
| 24 | #include "legacy_context_server.hpp" |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | #include <boost/functional/hash.hpp> |
---|
| 29 | #include <random> |
---|
| 30 | #include <chrono> |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | namespace xios |
---|
| 34 | { |
---|
| 35 | using namespace std ; |
---|
| 36 | |
---|
| 37 | CContextServer::CContextServer(CContext* parent,MPI_Comm intraComm_,MPI_Comm interComm_) |
---|
| 38 | : associatedClient_(nullptr) |
---|
| 39 | { |
---|
| 40 | context=parent; |
---|
| 41 | intraComm=intraComm_; |
---|
| 42 | MPI_Comm_size(intraComm,&intraCommSize); |
---|
| 43 | MPI_Comm_rank(intraComm,&intraCommRank); |
---|
| 44 | |
---|
| 45 | interComm=interComm_; |
---|
| 46 | int flag; |
---|
| 47 | MPI_Comm_test_inter(interComm,&flag); |
---|
| 48 | |
---|
| 49 | if (flag) attachedMode=false ; |
---|
| 50 | else attachedMode=true ; |
---|
| 51 | |
---|
| 52 | if (flag) MPI_Comm_remote_size(interComm,&clientSize_); |
---|
| 53 | else MPI_Comm_size(interComm,&clientSize_); |
---|
| 54 | |
---|
| 55 | SRegisterContextInfo contextInfo ; |
---|
| 56 | CXios::getContextsManager()->getContextInfo(context->getId(), contextInfo, intraComm) ; |
---|
| 57 | eventScheduler_=CXios::getPoolRessource()->getService(contextInfo.serviceId,contextInfo.partitionId)->getEventScheduler() ; |
---|
| 58 | |
---|
| 59 | // generate unique hash for server |
---|
| 60 | auto time=chrono::system_clock::now().time_since_epoch().count() ; |
---|
| 61 | std::default_random_engine rd(time); // not reproducible from a run to another |
---|
| 62 | std::uniform_int_distribution<size_t> dist; |
---|
| 63 | hashId=dist(rd) ; |
---|
| 64 | MPI_Bcast(&hashId,1,MPI_SIZE_T,0,intraComm) ; // Bcast to all server of the context |
---|
| 65 | |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | template<> |
---|
| 69 | CContextServer* CContextServer::getNew<CContextServer::generic>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) |
---|
| 70 | { |
---|
| 71 | string defaultProtocol = CXios::getin<string>("transport_protocol", "default") ; |
---|
| 72 | if (defaultProtocol=="one_sided") return new COneSidedContextServer(parent, intraComm, interComm) ; |
---|
| 73 | else if (defaultProtocol=="legacy") return new CLegacyContextServer(parent, intraComm, interComm) ; |
---|
| 74 | else if (defaultProtocol=="default") return new CLegacyContextServer(parent, intraComm, interComm) ; |
---|
| 75 | else ERROR("CContextServer* CContextServer::getNew<CContextServer::generic>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm)", |
---|
| 76 | <<"Protocol name <"<<defaultProtocol<<"> is undefined, must be <default>, <one_sided> or <legacy>" ) ; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | template<> |
---|
| 80 | CContextServer* CContextServer::getNew<CContextServer::oneSided>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) |
---|
| 81 | { |
---|
| 82 | return new COneSidedContextServer(parent, intraComm, interComm) ; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | template<> |
---|
| 86 | CContextServer* CContextServer::getNew<CContextServer::legacy>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) |
---|
| 87 | { |
---|
| 88 | return new COneSidedContextServer(parent, intraComm, interComm) ; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | //! Attached mode is used ? |
---|
| 92 | //! \return true if attached mode is used, false otherwise |
---|
| 93 | bool CContextServer::isAttachedModeEnabled() const |
---|
| 94 | { |
---|
| 95 | return attachedMode ; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | } |
---|