Ignore:
Timestamp:
05/18/17 19:27:26 (7 years ago)
Author:
oabramkina
Message:

Fixing a bug in context finalization. Now context finalization is done in two stages.
Tested on Cure with test_regular and test_xios2_cmip6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_olga/src/node/context.cpp

    r1130 r1139  
    2626      : CObjectTemplate<CContext>(), CContextAttributes() 
    2727      , calendar(), hasClient(false), hasServer(false) 
    28       , isPostProcessed(false)//, finalized(false) 
     28      , isPostProcessed(false), finalized(false) 
    2929      , idServer_(), client(0), server(0) 
    3030      , allProcessed(false), countChildCtx_(0) 
     
    3434      : CObjectTemplate<CContext>(id), CContextAttributes() 
    3535      , calendar(), hasClient(false), hasServer(false) 
    36       , isPostProcessed(false)//, finalized(false) 
     36      , isPostProcessed(false), finalized(false) 
    3737      , idServer_(), client(0), server(0) 
    3838      , allProcessed(false), countChildCtx_(0) 
     
    4545     for (std::vector<CContextClient*>::iterator it = clientPrimServer.begin(); it != clientPrimServer.end(); it++)  delete *it; 
    4646     for (std::vector<CContextServer*>::iterator it = serverPrimServer.begin(); it != serverPrimServer.end(); it++)  delete *it; 
     47 
    4748   } 
    4849 
     
    391392    else if (CServer::serverLevel == 1) 
    392393    { 
    393       client->checkBuffers(); 
    394       bool serverFinished = server->eventLoop(); 
     394      if (!finalized) 
     395        client->checkBuffers(); 
     396      bool serverFinished = true; 
     397      if (!finalized) 
     398        serverFinished = server->eventLoop(); 
    395399      bool serverPrimFinished = true; 
    396400      for (int i = 0; i < clientPrimServer.size(); ++i) 
    397401      { 
    398         clientPrimServer[i]->checkBuffers(); 
    399         serverPrimFinished *= serverPrimServer[i]->eventLoop(); 
     402        if (!finalized) 
     403          clientPrimServer[i]->checkBuffers(); 
     404        if (!finalized) 
     405          serverPrimFinished *= serverPrimServer[i]->eventLoop(); 
    400406      } 
    401407      return ( serverFinished && serverPrimFinished); 
     
    419425     // (1) blocking send context finalize to its server 
    420426     // (2) blocking receive context finalize from its server 
     427     // (3) send post finalize to its server 
    421428     if (CXios::isClient) 
    422429     { 
     
    432439         while (!server->hasFinished()) 
    433440           server->eventLoop(); 
     441 
     442         if (CXios::isServer) // Mode attache 
     443           postFinalize(); 
     444         else                  // Mode server 
     445           client->postFinalize(); 
     446 
    434447       } 
    435448     } 
     
    442455           clientPrimServer[i]->finalize(); 
    443456 
    444        // (Last) context finalized message received => send context finalize to its parent context 
     457       // (Last) context finalized message received 
     458       // Close files, gather registries, send context finalize to its parent context 
    445459       if (countChildCtx_ == clientPrimServer.size()) 
    446460         client->finalize(); 
     
    448462       ++countChildCtx_; 
    449463     } 
    450  
    451      // If in mode attache call postFinalize 
    452      if (CXios::isServer && CXios::isClient) 
    453        postFinalize(); 
    454464   } 
    455465 
    456466   /*! 
    457467   * \fn void CContext::postFinalize(void) 
    458    * Close files, gather registries, , and make deallocations. 
     468   * Close files, gather registries, and make deallocations. 
    459469   * Function is called when a context is finalized (it has nothing to receive and nothing to send). 
    460470   */ 
    461471   void CContext::postFinalize(void) 
    462472   { 
     473     finalized = true; 
     474 
     475     // Primary server: blocking send post finalize to secondary servers 
     476     for (int i = 0; i < clientPrimServer.size(); ++i) 
     477       clientPrimServer[i]->postFinalize(); 
     478     bool buffersReleased; 
     479     do 
     480     { 
     481       buffersReleased = true; 
     482       for (int i = 0; i < clientPrimServer.size(); ++i) 
     483       { 
     484         clientPrimServer[i]->checkBuffers(); 
     485         buffersReleased *= !clientPrimServer[i]->havePendingRequests(); 
     486       } 
     487     } while (!buffersReleased); 
     488 
    463489     info(20)<<"Context <"<<getId()<<"> is finalized."<<endl; 
    464490 
     
    469495       if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; 
    470496     } 
     497 
     498     //! Deallocate client buffers 
     499     client->releaseBuffers(); 
     500     for (int i = 0; i < clientPrimServer.size(); ++i) 
     501       clientPrimServer[i]->releaseBuffers(); 
    471502 
    472503     //! Free internally allocated communicators 
     
    475506     comms.clear(); 
    476507 
    477      //! Deallocate client buffers 
    478      client->releaseBuffers(); 
    479      for (int i = 0; i < clientPrimServer.size(); ++i) 
    480        clientPrimServer[i]->releaseBuffers(); 
    481508   } 
    482509 
     
    10001027   void CContext::recvCreateFileHeader(CBufferIn& buffer) 
    10011028   { 
    1002      // The creation of header file should be delegated to server2, for now 
    1003       // if (hasClient && hasServer) 
    1004       // {         
    1005       //   sendCreateFileHeader(); 
    1006       // } 
    1007        
    10081029      if (!hasClient && hasServer)  
    10091030        createFileHeader(); 
     
    10141035   { 
    10151036      // Use correct context client to send message 
    1016      // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1; 
    10171037     int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; 
    10181038     for (int i = 0; i < nbSrvPools; ++i) 
     
    11511171      // Find all enabled fields of each file 
    11521172      this->findAllEnabledFields(); 
    1153       // this->findAllEnabledFieldsInReadModeFiles(); 
    11541173      // For now, only read files with client and only one level server 
    11551174      if (hasClient && !hasServer) this->findAllEnabledFieldsInReadModeFiles(); 
     
    11621181     } 
    11631182 
    1164       // // Only search and rebuild all reference objects of enable fields, don't transform 
    1165       // this->solveOnlyRefOfEnabledFields(false); 
    1166  
    1167       // // Search and rebuild all reference object of enabled fields 
    1168       // this->solveAllRefOfEnabledFields(false); 
    1169  
    1170       // // Find all fields with read access from the public API 
    1171       // findFieldsWithReadAccess(); 
    1172       // // and solve the all reference for them 
    1173       // solveAllRefOfFieldsWithReadAccess(); 
    1174  
    11751183      // Only search and rebuild all reference objects of enable fields, don't transform 
    11761184      this->solveOnlyRefOfEnabledFields(false); 
    11771185 
    11781186      // Search and rebuild all reference object of enabled fields, and transform 
    1179       // this->solveAllEnabledFields 
    11801187      this->solveAllRefOfEnabledFieldsAndTransform(false); 
    1181       // // Check grid and calculate its distribution 
    1182       // if (hasClient) checkGridEnabledFields(); 
    11831188 
    11841189      // Find all fields with read access from the public API 
     
    15851590  /*! 
    15861591  * \fn bool CContext::isFinalized(void) 
    1587   * Context is finalized if: 
    1588   * (1) it has received all context finalize events 
    1589   * (2) it has no pending events to send. 
     1592  * Context is finalized if it received context post finalize event. 
    15901593  */ 
    15911594  bool CContext::isFinalized(void) 
    15921595  { 
    1593     if (countChildCtx_==clientPrimServer.size()+1) 
    1594     { 
    1595       bool buffersReleased = !client->havePendingRequests(); 
    1596       for (int i = 0; i < clientPrimServer.size(); ++i) 
    1597         buffersReleased *= !clientPrimServer[i]->havePendingRequests(); 
    1598       return buffersReleased; 
    1599     } 
    1600     else 
    1601       return false; 
     1596    return finalized; 
    16021597  } 
    16031598 
Note: See TracChangeset for help on using the changeset viewer.