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 "p2p_context_server.hpp" |
---|
25 | #include "legacy_context_server.hpp" |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | #include <boost/functional/hash.hpp> |
---|
30 | #include <random> |
---|
31 | #include <chrono> |
---|
32 | |
---|
33 | |
---|
34 | namespace xios |
---|
35 | { |
---|
36 | using namespace std ; |
---|
37 | |
---|
38 | CContextServer::CContextServer(CContext* parent,MPI_Comm intraComm_,MPI_Comm interComm_) |
---|
39 | : associatedClient_(nullptr) |
---|
40 | { |
---|
41 | context=parent; |
---|
42 | intraComm=intraComm_; |
---|
43 | MPI_Comm_size(intraComm,&intraCommSize); |
---|
44 | MPI_Comm_rank(intraComm,&intraCommRank); |
---|
45 | |
---|
46 | interComm=interComm_; |
---|
47 | int flag; |
---|
48 | MPI_Comm_test_inter(interComm,&flag); |
---|
49 | if (flag) MPI_Comm_remote_size(interComm,&clientSize_); |
---|
50 | else MPI_Comm_size(interComm,&clientSize_); |
---|
51 | |
---|
52 | SRegisterContextInfo contextInfo ; |
---|
53 | CXios::getContextsManager()->getContextInfo(context->getId(), contextInfo, intraComm) ; |
---|
54 | eventScheduler_=CXios::getPoolRessource()->getService(contextInfo.serviceId,contextInfo.partitionId)->getEventScheduler() ; |
---|
55 | |
---|
56 | // generate unique hash for server |
---|
57 | auto time=chrono::system_clock::now().time_since_epoch().count() ; |
---|
58 | std::default_random_engine rd(time); // not reproducible from a run to another |
---|
59 | std::uniform_int_distribution<size_t> dist; |
---|
60 | hashId=dist(rd) ; |
---|
61 | MPI_Bcast(&hashId,1,MPI_SIZE_T,0,intraComm) ; // Bcast to all server of the context |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | template<> |
---|
66 | CContextServer* CContextServer::getNew<CContextServer::generic>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) |
---|
67 | { |
---|
68 | string defaultProtocol = CXios::getin<string>("transport_protocol", "default") ; |
---|
69 | if (defaultProtocol=="one_sided") return new COneSidedContextServer(parent, intraComm, interComm) ; |
---|
70 | else if (defaultProtocol=="p2p") return new CP2pContextServer(parent, intraComm, interComm) ; |
---|
71 | else if (defaultProtocol=="legacy") return new CLegacyContextServer(parent, intraComm, interComm) ; |
---|
72 | else if (defaultProtocol=="default") return new CLegacyContextServer(parent, intraComm, interComm) ; |
---|
73 | else ERROR("CContextServer* CContextServer::getNew<CContextServer::generic>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm)", |
---|
74 | <<"Protocol name <"<<defaultProtocol<<"> is undefined, must be <default>, <one_sided> or <legacy>" ) ; |
---|
75 | } |
---|
76 | |
---|
77 | template<> |
---|
78 | CContextServer* CContextServer::getNew<CContextServer::oneSided>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) |
---|
79 | { |
---|
80 | return new COneSidedContextServer(parent, intraComm, interComm) ; |
---|
81 | } |
---|
82 | |
---|
83 | template<> |
---|
84 | CContextServer* CContextServer::getNew<CContextServer::p2p>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) |
---|
85 | { |
---|
86 | return new CP2pContextServer(parent, intraComm, interComm) ; |
---|
87 | } |
---|
88 | |
---|
89 | template<> |
---|
90 | CContextServer* CContextServer::getNew<CContextServer::legacy>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) |
---|
91 | { |
---|
92 | return new COneSidedContextServer(parent, intraComm, interComm) ; |
---|
93 | } |
---|
94 | |
---|
95 | } |
---|