Changeset 1139


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.

Location:
XIOS/dev/dev_olga
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_olga/bld.cfg

    r1136 r1139  
    3434bld::target xios_server.exe  
    3535bld::target test_regular.exe 
    36 #bld::target test_xios2_cmip6.exe 
     36bld::target test_xios2_cmip6.exe 
    3737#bld::target test_new_features.exe test_unstruct_complete.exe  
    3838bld::target test_remap.exe 
    3939bld::target test_complete.exe 
    4040bld::target test_client.exe 
    41 bld::target test_unstruct_complete.exe 
    42 bld::target test_unstructured.exe 
     41#bld::target test_unstruct_complete.exe 
     42#bld::target test_unstructured.exe 
    4343bld::exe_dep 
    4444 
  • XIOS/dev/dev_olga/src/context_client.cpp

    r1130 r1139  
    276276      map<int,CClientBuffer*>::iterator itBuff; 
    277277      for (itBuff = buffers.begin(); itBuff != buffers.end(); itBuff++) 
     278      { 
    278279          delete itBuff->second; 
     280      } 
    279281      buffers.clear(); 
    280282   } 
     
    420422    //releaseBuffers(); // moved to CContext::finalize() 
    421423  } 
     424 
     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 
     459     stop = true; 
     460   } 
     461   CTimer::get("Blocking time").suspend(); 
     462 
     463 } 
    422464 
    423465  /*! 
  • XIOS/dev/dev_olga/src/context_client.hpp

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

    r1130 r1139  
    225225    { 
    226226      finished=true; 
    227 //      info(20)<<"Server Side context <"<<context->getId()<<"> finalized"<<endl;   // moved to CContext::finalize() 
    228227      std::map<int, StdSize>::const_iterator itbMap = mapBufferSize_.begin(), 
    229228                           iteMap = mapBufferSize_.end(), itMap; 
     
    237236      context->finalize(); 
    238237      report(0)<< " Memory report : Context <"<<ctxId<<"> : server side : total memory used for buffer "<<totalBuf<<" bytes"<<endl; 
     238    } 
     239    else if (event.classId==CContext::GetType() && event.type==CContext::EVENT_ID_CONTEXT_POST_FINALIZE) 
     240    { 
     241      info(20)<<"Server side context <"<<context->getId()<<"> finalized."<<endl; 
     242      context->postFinalize(); 
    239243    } 
    240244    else if (event.classId==CContext::GetType()) CContext::dispatchEvent(event); 
  • 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 
  • XIOS/dev/dev_olga/src/node/context.hpp

    r1130 r1139  
    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, 
    5354           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY, 
    5455           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES, 
     
    247248         bool isPostProcessed; 
    248249         bool allProcessed; 
    249 //         bool finalized; 
     250         bool finalized; 
    250251         int countChildCtx_;        //!< Counter of child contexts (for now it is the number of secondary server pools) 
    251252         StdString idServer_; 
  • XIOS/dev/dev_olga/src/server.cpp

    r1133 r1139  
    319319       while(!stop) 
    320320       { 
    321  
    322321         if (isRoot) 
    323322         { 
     
    588587     { 
    589588       bool isFinalized ; 
    590  
    591589       map<string,CContext*>::iterator it ; 
    592590 
     
    596594         if (isFinalized) 
    597595         { 
    598            it->second->postFinalize(); 
     596//           it->second->postFinalize(); 
    599597           contextList.erase(it) ; 
    600598           break ; 
    601599         } 
    602600         else 
    603          { 
    604            isFinalized=it->second->checkBuffersAndListen(); 
    605          } 
     601           it->second->checkBuffersAndListen(); 
    606602       } 
    607603     } 
Note: See TracChangeset for help on using the changeset viewer.