Changeset 2405


Ignore:
Timestamp:
09/20/22 11:12:53 (21 months ago)
Author:
ymipsl
Message:

Refactor service management from context
YM

Location:
XIOS3/trunk/src/node
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/src/node/context.cpp

    r2397 r2405  
    4949      , allProcessed(false), countChildContextFinalized_(0), isProcessingEvent_(false) 
    5050 
    51    { /* Ne rien faire de plus */ } 
     51   { /* Ne rien faire de plus */  } 
    5252 
    5353   CContext::CContext(const StdString & id) 
     
    542542  CATCH_DUMP_ATTR 
    543543 
     544   
     545  void CContext::createServerInterComm(const string& poolId, const string& serverId, vector<pair<string, pair<CContextClient*,CContextServer*>>>& clientServers ) 
     546  TRY 
     547  { 
     548    MPI_Comm interCommClient, interCommServer ; 
     549    int commRank ; 
     550    MPI_Comm_rank(intraComm_,&commRank) ; 
     551     
     552    int nbPartitions ; 
     553    if (commRank==0) 
     554    { 
     555      CXios::getServicesManager()->getServiceNbPartitions(poolId, serverId, 0, nbPartitions) ; 
     556      for(int i=0 ; i<nbPartitions; i++) CXios::getContextsManager()->createServerContext(poolId, serverId, i, getContextId()) ; 
     557    } 
     558    setCurrent(getId()) ; // getCurrent/setCurrent may be supress, it can cause a lot of trouble (attached ???) 
     559    MPI_Bcast(&nbPartitions, 1, MPI_INT, 0, intraComm_) ; 
     560       
     561    MPI_Comm interComm ; 
     562    for(int i=0 ; i<nbPartitions; i++) 
     563    { 
     564      parentServerContext_->createIntercomm(poolId, serverId, i, getContextId(), intraComm_, interCommClient, interCommServer) ; 
     565      int type ;  
     566      if (commRank==0) CXios::getServicesManager()->getServiceType(poolId, serverId, 0, type) ; 
     567      MPI_Bcast(&type,1,MPI_INT,0,intraComm_) ; 
     568      string fullServerId=CXios::getContextsManager()->getServerContextName(poolId, serverId, i, type, getContextId()) ; 
     569 
     570      MPI_Comm intraCommClient, intraCommServer ; 
     571 
     572      intraCommClient=intraComm_ ; 
     573      MPI_Comm_dup(intraComm_, &intraCommServer) ; 
     574 
     575      CContextClient* client = CContextClient::getNew(this, intraCommClient, interCommClient) ; 
     576      CContextServer* server = CContextServer::getNew(this, intraCommServer, interCommServer) ; 
     577      client->setAssociatedServer(server) ; 
     578      server->setAssociatedClient(client) ; 
     579       
     580      clientServers.push_back({fullServerId,{client,server}}) ; 
     581    } 
     582  } 
     583  CATCH_DUMP_ATTR 
     584   
    544585  void CContext::createServerInterComm(void)  
     586  TRY 
     587  { 
     588    vector<pair<string, pair<CContextClient*,CContextServer*>>> clientServers ; 
     589 
     590    if (serviceType_ == CServicesManager::CLIENT) 
     591    { 
     592      if (attached_mode) createServerInterComm(CClient::getPoolRessource()->getId(), getContextId()+"_"+CXios::defaultServerId, clientServers) ; 
     593      else if (CXios::usingServer2) createServerInterComm(CXios::defaultPoolId, CXios::defaultGathererId, clientServers) ; 
     594      else createServerInterComm(CXios::defaultPoolId, CXios::defaultServerId, clientServers) ; 
     595       
     596      client = clientServers[0].second.first ; 
     597      server = clientServers[0].second.second ; 
     598    } 
     599    else if (serviceType_ == CServicesManager::GATHERER) 
     600    { 
     601      createServerInterComm(CXios::defaultPoolId, CXios::defaultServerId, clientServers) ; 
     602      for(auto& clientServer : clientServers) 
     603      { 
     604        primServerId_.push_back(clientServer.first) ; 
     605        clientPrimServer.push_back(clientServer.second.first); 
     606        serverPrimServer.push_back(clientServer.second.second);  
     607      } 
     608    } 
     609 
     610  } 
     611  CATCH_DUMP_ATTR 
     612 
     613  void CContext::createServerInterComm_old(void)  
    545614  TRY 
    546615  { 
     
    582651      else 
    583652      { 
     653         
    584654        //CXios::getContextsManager()->createServerContextIntercomm(CXios::defaultPoolId, CXios::defaultServerId, 0, getContextId(), intraComm_, interComm) ; 
    585655        parentServerContext_->createIntercomm(CXios::defaultPoolId, CXios::defaultServerId, 0, getContextId(), intraComm_, 
     
    16381708             return true; 
    16391709             break; 
    1640            case EVENT_ID_CREATE_FILE_HEADER : 
    1641              recvCreateFileHeader(event); 
    1642              return true; 
    1643              break; 
    16441710           case EVENT_ID_COUPLER_IN_READY: 
    16451711             recvCouplerInReady(event); 
     
    17611827   CATCH_DUMP_ATTR 
    17621828 
    1763    //! Client side: Send a message to create header part of netcdf file 
    1764    void CContext::sendCreateFileHeader(void) 
    1765    TRY 
    1766    { 
    1767      int nbSrvPools ; 
    1768      if (serviceType_==CServicesManager::CLIENT) nbSrvPools = 1 ; 
    1769      else if (serviceType_==CServicesManager::GATHERER) nbSrvPools = this->clientPrimServer.size() ; 
    1770      else nbSrvPools = 0 ; 
    1771      CContextClient* contextClientTmp ; 
    1772  
    1773      for (int i = 0; i < nbSrvPools; ++i) 
    1774      { 
    1775        if (serviceType_==CServicesManager::CLIENT) contextClientTmp = client ; 
    1776        else if (serviceType_==CServicesManager::GATHERER ) contextClientTmp = clientPrimServer[i] ; 
    1777        CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER); 
    1778  
    1779        if (contextClientTmp->isServerLeader()) 
    1780        { 
    1781          CMessage msg; 
    1782          const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); 
    1783          for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    1784            event.push(*itRank,1,msg) ; 
    1785          contextClientTmp->sendEvent(event); 
    1786        } 
    1787        else contextClientTmp->sendEvent(event); 
    1788      } 
    1789    } 
    1790    CATCH_DUMP_ATTR 
    1791  
    1792    //! Server side: Receive a message of client annoucing the creation of header part of netcdf file 
    1793    void CContext::recvCreateFileHeader(CEventServer& event) 
    1794    TRY 
    1795    { 
    1796       CBufferIn* buffer=event.subEvents.begin()->buffer; 
    1797       getCurrent()->recvCreateFileHeader(*buffer); 
    1798    } 
    1799    CATCH 
    1800  
    1801    //! Server side: Receive a message of client annoucing the creation of header part of netcdf file 
    1802    void CContext::recvCreateFileHeader(CBufferIn& buffer) 
    1803    TRY 
    1804    { 
    1805       if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)  
    1806         createFileHeader(); 
    1807    } 
    1808    CATCH_DUMP_ATTR 
    18091829 
    18101830   void CContext::createCouplerInterCommunicator(void) 
  • XIOS3/trunk/src/node/context.hpp

    r2404 r2405  
    5555           EVENT_ID_COLLECTIVE=100, 
    5656           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR, 
    57            EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE, 
     57           EVENT_ID_CONTEXT_FINALIZE, 
    5858           EVENT_ID_CONTEXT_FINALIZE_CLIENT, 
    5959           EVENT_ID_COUPLER_IN_READY, 
     
    104104         void initServer(MPI_Comm intraComm, int serviceType ); 
    105105         void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ; 
     106  
    106107         void createServerInterComm(void)  ; 
     108         void createServerInterComm_old(void)  ; 
     109         void createServerInterComm(const string& poolId, const string& serverId, vector<pair<string, pair<CContextClient*,CContextServer*>>>& clientServers ) ; 
     110  
    107111 
    108112         bool isInitialized(void); 
     
    168172         // There are something to send on closing context defintion 
    169173         void sendUpdateCalendar(int step); 
    170          void sendCreateFileHeader(void); 
    171174         void sendEnabledFiles(const std::vector<CFile*>& activeFiles); 
    172175         void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
     
    187190         void recvUpdateCalendar(CBufferIn& buffer); 
    188191         static void recvCloseDefinition(CEventServer& event); 
    189          static void recvCreateFileHeader(CEventServer& event); 
    190          void recvCreateFileHeader(CBufferIn& buffer); 
    191192         static void recvSolveInheritanceContext(CEventServer& event); 
    192193         void recvSolveInheritanceContext(CBufferIn& buffer); 
     
    315316         // list of slave servers (IO server or others) 
    316317         set<CContextClient*> slaveServers_ ; 
     318 
     319      private: 
     320        std::string defaultReaderId ; 
     321        std::string defaultWriterId ; 
     322        std::string defaultGathererId ; 
     323 
     324        std::map<std::string, CContextClient*> clients_ ; 
     325        std::map<std::string, CContextClient*> servers_ ; 
     326 
    317327      private: 
    318328         // the map containing context client associated to it string id for coupling out ; 
Note: See TracChangeset for help on using the changeset viewer.