source: XIOS3/trunk/src/transport/context_server.cpp

Last change on this file was 2629, checked in by jderouillat, 2 months ago

Delete boost dependencies, the few features used are replaced by functions stored in extern/boost_extraction

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.3 KB
Line 
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 <random>
30#include <chrono>
31
32
33namespace 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    if (flag) MPI_Comm_remote_size(interComm,&clientSize_);
49    else MPI_Comm_size(interComm,&clientSize_);
50   
51    SRegisterContextInfo contextInfo ;
52    CXios::getContextsManager()->getContextInfo(context->getId(), contextInfo, intraComm) ;
53    eventScheduler_=CXios::getPoolRessource()->getService(contextInfo.serviceId,contextInfo.partitionId)->getEventScheduler() ;
54
55    // generate unique hash for server
56    auto time=chrono::system_clock::now().time_since_epoch().count() ;
57    std::default_random_engine rd(time); // not reproducible from a run to another
58    std::uniform_int_distribution<size_t> dist;
59    hashId=dist(rd) ;
60    MPI_Bcast(&hashId,1,MPI_SIZE_T,0,intraComm) ; // Bcast to all server of the context
61     
62  }
63
64  template<>
65  CContextServer* CContextServer::getNew<CContextServer::generic>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) 
66  { 
67    string defaultProtocol = CXios::getin<string>("transport_protocol", "default") ;
68    if (defaultProtocol=="one_sided") return new COneSidedContextServer(parent, intraComm, interComm) ;
69    else if  (defaultProtocol=="p2p") return new CP2pContextServer(parent, intraComm, interComm) ;
70    else if  (defaultProtocol=="legacy") return new CLegacyContextServer(parent, intraComm, interComm) ;
71    else if  (defaultProtocol=="default") return new CLegacyContextServer(parent, intraComm, interComm) ;
72    else ERROR("CContextServer* CContextServer::getNew<CContextServer::generic>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm)",
73              <<"Protocol name <"<<defaultProtocol<<"> is undefined,  must be <default>, <one_sided> or <legacy>" ) ;     
74  }
75
76  template<>
77  CContextServer* CContextServer::getNew<CContextServer::oneSided>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) 
78  { 
79    return new COneSidedContextServer(parent, intraComm, interComm) ; 
80  }
81
82  template<>
83  CContextServer* CContextServer::getNew<CContextServer::p2p>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) 
84  { 
85    return new CP2pContextServer(parent, intraComm, interComm) ; 
86  }
87
88  template<>
89  CContextServer* CContextServer::getNew<CContextServer::legacy>(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) 
90  { 
91    return new COneSidedContextServer(parent, intraComm, interComm) ; 
92  }
93
94}
Note: See TracBrowser for help on using the repository browser.