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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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) 
Note: See TracChangeset for help on using the changeset viewer.