Changeset 1194


Ignore:
Timestamp:
07/04/17 14:28:50 (4 years ago)
Author:
oabramkina
Message:

Two server levels: simplifying context finalization.
Send of context finalization is blocking now on all server types.

Location:
XIOS/dev/dev_olga/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_olga/src/context_client.cpp

    r1193 r1194  
    248248     if (!mapBufferSize_.count(rank)) 
    249249     { 
    250        error(0) << "WARNING: Unexpected request for buffer to communicate with server " << rank << std::endl; 
     250//       error(0) << "WARNING: Unexpected request for buffer to communicate with server " << rank << std::endl; 
    251251       mapBufferSize_[rank] = CXios::minBufferSize; 
    252252     } 
     
    423423  } 
    424424 
    425   /*! 
    426   * Finalize context client and do some reports. Function is non-blocking. 
    427   */ 
    428  void CContextClient::postFinalize(void) 
    429  { 
    430    map<int,CClientBuffer*>::iterator itBuff; 
    431    bool stop = false; 
    432  
    433    CTimer::get("Blocking time").resume(); 
    434    while (hasTemporarilyBufferedEvent()) 
    435    { 
    436      checkBuffers(); 
    437      sendTemporarilyBufferedEvent(); 
    438    } 
    439    CTimer::get("Blocking time").suspend(); 
    440  
    441    CEventClient event(CContext::GetType(), CContext::EVENT_ID_CONTEXT_POST_FINALIZE); 
    442    if (isServerLeader()) 
    443    { 
    444      CMessage msg; 
    445      const std::list<int>& ranks = getRanksServerLeader(); 
    446      for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    447        event.push(*itRank, 1, msg); 
    448      sendEvent(event); 
    449    } 
    450    else sendEvent(event); 
    451  
    452    CTimer::get("Blocking time").resume(); 
    453 //   while (!stop) 
    454    { 
    455      checkBuffers(); 
    456      if (hasTemporarilyBufferedEvent()) 
    457        sendTemporarilyBufferedEvent(); 
    458      stop = true; 
    459 //     for (itBuff = buffers.begin(); itBuff != buffers.end(); itBuff++) stop &= !itBuff->second->hasPendingRequest(); 
    460    } 
    461    CTimer::get("Blocking time").suspend(); 
    462  
    463  } 
    464425 
    465426  /*! 
  • XIOS/dev/dev_olga/src/context_client.hpp

    r1158 r1194  
    5353//      void closeContext(void);  Never been implemented. 
    5454      void finalize(void); 
    55       void postFinalize(void); 
    5655 
    5756      void setBufferSize(const std::map<int,StdSize>& mapSize, const std::map<int,StdSize>& maxEventSize); 
  • XIOS/dev/dev_olga/src/context_server.cpp

    r1193 r1194  
    223223    { 
    224224      finished=true; 
     225      info(20)<<" CContextServer: Receive context <"<<context->getId()<<"> finalize."<<endl; 
     226      context->finalize(); 
    225227      std::map<int, StdSize>::const_iterator itbMap = mapBufferSize_.begin(), 
    226228                           iteMap = mapBufferSize_.end(), itMap; 
     
    232234        totalBuf += itMap->second; 
    233235      } 
    234       context->finalize(); 
    235236      report(0)<< " Memory report : Context <"<<ctxId<<"> : server side : total memory used for buffer "<<totalBuf<<" bytes"<<endl; 
    236     } 
    237     else if (event.classId==CContext::GetType() && event.type==CContext::EVENT_ID_CONTEXT_POST_FINALIZE) 
    238     { 
    239       info(20)<<" CContextServer: Receive context <"<<context->getId()<<"> finalize."<<endl; 
    240       context->postFinalize(); 
    241237    } 
    242238    else if (event.classId==CContext::GetType()) CContext::dispatchEvent(event); 
  • XIOS/dev/dev_olga/src/node/context.cpp

    r1193 r1194  
    413413     // (1) blocking send context finalize to its server 
    414414     // (2) blocking receive context finalize from its server 
    415      // (3) send post finalize to its server 
     415     // (3) some memory deallocations 
    416416     if (CXios::isClient) 
    417417     { 
     
    428428           server->eventLoop(); 
    429429 
    430          if (CXios::isServer) // Mode attache 
    431            postFinalize(); 
    432          else                  // Mode server 
    433            client->postFinalize(); 
    434  
    435        } 
    436      } 
    437      // Server: non-blocking send context finalize 
     430         if (hasServer) // Mode attache 
     431         { 
     432           closeAllFile(); 
     433           registryOut->hierarchicalGatherRegistry() ; 
     434           if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; 
     435         } 
     436 
     437         //! Deallocate client buffers 
     438         client->releaseBuffers(); 
     439 
     440         //! Free internally allocated communicators 
     441         for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) 
     442           MPI_Comm_free(&(*it)); 
     443         comms.clear(); 
     444 
     445         info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl; 
     446       } 
     447     } 
    438448     else if (CXios::isServer) 
    439449     { 
    440        // First context finalize message received from a model => send context finalize to its child contexts (if any) 
     450       // First context finalize message received from a model 
     451       // Send context finalize to its child contexts (if any) 
    441452       if (countChildCtx_ == 0) 
    442453         for (int i = 0; i < clientPrimServer.size(); ++i) 
     
    445456       // (Last) context finalized message received 
    446457       if (countChildCtx_ == clientPrimServer.size()) 
     458       { 
     459         // Blocking send of context finalize message to its client (e.g. primary server or model) 
    447460         client->finalize(); 
     461         bool bufferReleased; 
     462         do 
     463         { 
     464           client->checkBuffers(); 
     465           bufferReleased = !client->havePendingRequests(); 
     466         } while (!bufferReleased); 
     467         finalized = true; 
     468 
     469         if (hasServer && !hasClient) 
     470         { 
     471           closeAllFile(); 
     472           registryOut->hierarchicalGatherRegistry() ; 
     473           if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; 
     474         } 
     475 
     476         //! Deallocate client buffers 
     477         client->releaseBuffers(); 
     478         for (int i = 0; i < clientPrimServer.size(); ++i) 
     479           clientPrimServer[i]->releaseBuffers(); 
     480 
     481         //! Free internally allocated communicators 
     482         for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) 
     483           MPI_Comm_free(&(*it)); 
     484         comms.clear(); 
     485 
     486         info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl; 
     487       } 
    448488 
    449489       ++countChildCtx_; 
    450490     } 
    451    } 
    452  
    453    /*! 
    454    * \fn void CContext::postFinalize(void) 
    455    * Close files, gather registries, and make deallocations. 
    456    * Function is called when a context is finalized. 
    457    */ 
    458    void CContext::postFinalize(void) 
    459    { 
    460      finalized = true; 
    461  
    462      // Primary server: blocking send post finalize to secondary servers 
    463      for (int i = 0; i < clientPrimServer.size(); ++i) 
    464        clientPrimServer[i]->postFinalize(); 
    465      bool buffersReleased; 
    466      do 
    467      { 
    468        buffersReleased = true; 
    469        for (int i = 0; i < clientPrimServer.size(); ++i) 
    470        { 
    471          clientPrimServer[i]->checkBuffers(); 
    472          buffersReleased *= !clientPrimServer[i]->havePendingRequests(); 
    473        } 
    474      } while (!buffersReleased); 
    475  
    476      // Primary or classical server: block until all messages are sent to model 
    477      // Client (model): block until all messages are sent to server 
    478      if ( CServer::serverLevel==0 || CServer::serverLevel==1 || !hasServer) 
    479      do 
    480      { 
    481        client->checkBuffers(); 
    482        buffersReleased = !client->havePendingRequests(); 
    483      } while (!buffersReleased); 
    484  
    485      if (hasServer && !hasClient) 
    486      { 
    487        closeAllFile(); 
    488        registryOut->hierarchicalGatherRegistry() ; 
    489        if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; 
    490      } 
    491  
    492      //! Deallocate client buffers 
    493      client->releaseBuffers(); 
    494      for (int i = 0; i < clientPrimServer.size(); ++i) 
    495        clientPrimServer[i]->releaseBuffers(); 
    496  
    497      //! Free internally allocated communicators 
    498      for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) 
    499        MPI_Comm_free(&(*it)); 
    500      comms.clear(); 
    501  
    502      info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl; 
    503  
    504491   } 
    505492 
     
    530517     checkGridEnabledFields();     
    531518 
    532      setClientServerBuffer(client); 
     519     // Buffer for primary server for connection to client will be allocated by default (to min size) 
     520     if (CServer::serverLevel != 1) 
     521       setClientServerBuffer(client); 
    533522     if (hasServer) 
    534523       for (int i = 0; i < clientPrimServer.size(); ++i) 
  • XIOS/dev/dev_olga/src/node/context.hpp

    r1184 r1194  
    5151           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR, 
    5252           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE, 
    53            EVENT_ID_CONTEXT_POST_FINALIZE, 
    5453           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY, 
    5554           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES, 
     
    10099         // Finalize a context 
    101100         void finalize(void); 
    102          void postFinalize(void); 
    103101         bool isFinalized(void); 
    104102 
Note: See TracChangeset for help on using the changeset viewer.