Ignore:
Timestamp:
11/15/17 15:21:13 (5 years ago)
Author:
oabramkina
Message:

Adding buffer evaluation in case of reading.

File:
1 edited

Legend:

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

    r1318 r1330  
    297297   } 
    298298 
    299    void CContext::setClientServerBuffer(CContextClient* contextClient) 
     299   /*! 
     300    Sets client buffers. 
     301    \param [in] contextClient 
     302    \param [in] bufferForWriting True if buffers are used for sending data for writing 
     303    This flag is only true for client and server-1 for communication with server-2 
     304  */ 
     305   void CContext::setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting) 
    300306   { 
    301307      // Estimated minimum event size for small events (10 is an arbitrary constant just for safety) 
     
    314320     // Compute the buffer sizes needed to send the attributes and data corresponding to fields 
    315321     std::map<int, StdSize> maxEventSize; 
    316      std::map<int, StdSize> bufferSize = getAttributesBufferSize(maxEventSize, contextClient); 
    317      std::map<int, StdSize> dataBufferSize = getDataBufferSize(maxEventSize, contextClient); 
     322     std::map<int, StdSize> bufferSize = getAttributesBufferSize(maxEventSize, contextClient, bufferForWriting); 
     323     std::map<int, StdSize> dataBufferSize = getDataBufferSize(maxEventSize, contextClient, bufferForWriting); 
    318324 
    319325     std::map<int, StdSize>::iterator it, ite = dataBufferSize.end(); 
     
    544550     distributeFiles(); 
    545551 
    546      setClientServerBuffer(client); 
     552     setClientServerBuffer(client, (hasClient && !hasServer)); 
    547553     for (int i = 0; i < clientPrimServer.size(); ++i) 
    548          setClientServerBuffer(clientPrimServer[i]); 
     554         setClientServerBuffer(clientPrimServer[i], true); 
    549555 
    550556     if (hasClient) 
     
    13341340   /*! 
    13351341    * Compute the required buffer size to send the attributes (mostly those grid related). 
    1336     * 
    13371342    * \param maxEventSize [in/out] the size of the bigger event for each connected server 
     1343    * \param [in] contextClient 
     1344    * \param [in] bufferForWriting True if buffers are used for sending data for writing 
     1345      This flag is only true for client and server-1 for communication with server-2 
    13381346    */ 
    1339    std::map<int, StdSize> CContext::getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient) 
     1347   std::map<int, StdSize> CContext::getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, 
     1348                                                           CContextClient* contextClient, bool bufferForWriting /*= "false"*/) 
    13401349   { 
    13411350     std::map<int, StdSize> attributesSize; 
    13421351 
    1343      if (hasClient) 
    1344      { 
    1345        size_t numEnabledFiles = this->enabledWriteModeFiles.size(); 
     1352//     if (hasClient) 
     1353     { 
     1354       std::vector<CFile*>& fileList = bufferForWriting ? this->enabledWriteModeFiles : this->enabledReadModeFiles; 
     1355//       size_t numEnabledFiles = this->enabledWriteModeFiles.size(); 
     1356       size_t numEnabledFiles = fileList.size(); 
    13461357       for (size_t i = 0; i < numEnabledFiles; ++i) 
    13471358       { 
    1348          CFile* file = this->enabledWriteModeFiles[i]; 
    1349          // if (file->getContextClient() == contextClient) 
     1359//           CFile* file = this->enabledWriteModeFiles[i]; 
     1360         CFile* file = fileList[i]; 
     1361//         if (file->getContextClient() == contextClient) 
    13501362         { 
    13511363           std::vector<CField*> enabledFields = file->getEnabledFields(); 
     
    13531365           for (size_t j = 0; j < numEnabledFields; ++j) 
    13541366           { 
    1355              const std::map<int, StdSize> mapSize = enabledFields[j]->getGridAttributesBufferSize(contextClient); 
     1367             const std::map<int, StdSize> mapSize = enabledFields[j]->getGridAttributesBufferSize(contextClient, bufferForWriting); 
    13561368             std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); 
    13571369             for (; it != itE; ++it) 
    13581370             { 
    13591371               // If attributesSize[it->first] does not exist, it will be zero-initialized 
    1360                // so we can use it safely without checking for its existance 
     1372               // so we can use it safely without checking for its existence 
    13611373               if (attributesSize[it->first] < it->second) 
    13621374                 attributesSize[it->first] = it->second; 
     
    13691381       } 
    13701382 
    1371       // Not a good approach here, duplicate code 
    1372        if (!hasServer) 
    1373        { 
    1374          size_t numEnabledFiles = this->enabledReadModeFiles.size(); 
    1375          for (size_t i = 0; i < numEnabledFiles; ++i) 
    1376          { 
    1377            CFile* file = this->enabledReadModeFiles[i];   
    1378            { 
    1379              std::vector<CField*> enabledFields = file->getEnabledFields(); 
    1380              size_t numEnabledFields = enabledFields.size(); 
    1381              for (size_t j = 0; j < numEnabledFields; ++j) 
    1382              { 
    1383                const std::map<int, StdSize> mapSize = enabledFields[j]->getGridAttributesBufferSize(contextClient); 
    1384                std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); 
    1385                for (; it != itE; ++it) 
    1386                { 
    1387                  // If attributesSize[it->first] does not exist, it will be zero-initialized 
    1388                  // so we can use it safely without checking for its existance 
    1389                  if (attributesSize[it->first] < it->second) 
    1390                    attributesSize[it->first] = it->second; 
    1391  
    1392                  if (maxEventSize[it->first] < it->second) 
    1393                    maxEventSize[it->first] = it->second; 
    1394                } 
    1395              } 
    1396            } 
    1397          } 
    1398        } 
     1383//      // Not a good approach here, duplicate code 
     1384//       if (!hasServer) 
     1385//       { 
     1386//         size_t numEnabledFiles = this->enabledReadModeFiles.size(); 
     1387//         for (size_t i = 0; i < numEnabledFiles; ++i) 
     1388//         { 
     1389//           CFile* file = this->enabledReadModeFiles[i]; 
     1390//           { 
     1391//             std::vector<CField*> enabledFields = file->getEnabledFields(); 
     1392//             size_t numEnabledFields = enabledFields.size(); 
     1393//             for (size_t j = 0; j < numEnabledFields; ++j) 
     1394//             { 
     1395//               const std::map<int, StdSize> mapSize = enabledFields[j]->getGridAttributesBufferSize(contextClient); 
     1396//               std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); 
     1397//               for (; it != itE; ++it) 
     1398//               { 
     1399//                 // If attributesSize[it->first] does not exist, it will be zero-initialized 
     1400//                 // so we can use it safely without checking for its existance 
     1401//                 if (attributesSize[it->first] < it->second) 
     1402//                   attributesSize[it->first] = it->second; 
     1403// 
     1404//                 if (maxEventSize[it->first] < it->second) 
     1405//                   maxEventSize[it->first] = it->second; 
     1406//               } 
     1407//             } 
     1408//           } 
     1409//         } 
     1410//       } 
    13991411     } 
    14001412 
     
    14041416   /*! 
    14051417    * Compute the required buffer size to send the fields data. 
    1406     * 
    14071418    * \param maxEventSize [in/out] the size of the bigger event for each connected server 
     1419    * \param [in] contextClient 
     1420    * \param [in] bufferForWriting True if buffers are used for sending data for writing 
     1421      This flag is only true for client and server-1 for communication with server-2 
    14081422    */ 
    1409    std::map<int, StdSize> CContext::getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient) 
    1410    { 
    1411      CFile::mode_attr::t_enum mode = hasClient ? CFile::mode_attr::write : CFile::mode_attr::read; 
     1423   std::map<int, StdSize> CContext::getDataBufferSize(std::map<int, StdSize>& maxEventSize, 
     1424                                                      CContextClient* contextClient, bool bufferForWriting /*= "false"*/) 
     1425   { 
     1426//     CFile::mode_attr::t_enum mode = hasClient ? CFile::mode_attr::write : CFile::mode_attr::read; 
    14121427 
    14131428     std::map<int, StdSize> dataSize; 
    14141429 
    14151430     // Find all reference domain and axis of all active fields 
    1416      size_t numEnabledFiles = this->enabledFiles.size(); 
     1431     std::vector<CFile*>& fileList = bufferForWriting ? this->enabledWriteModeFiles : this->enabledReadModeFiles; 
     1432     size_t numEnabledFiles = fileList.size(); 
     1433//     size_t numEnabledFiles = this->enabledFiles.size(); 
    14171434     for (size_t i = 0; i < numEnabledFiles; ++i) 
    14181435     { 
    1419        CFile* file = this->enabledFiles[i]; 
     1436//       CFile* file = this->enabledFiles[i]; 
     1437       CFile* file = fileList[i]; 
    14201438       if (file->getContextClient() == contextClient) 
    14211439       { 
    1422          CFile::mode_attr::t_enum fileMode = file->mode.isEmpty() ? CFile::mode_attr::write : file->mode.getValue(); 
    1423  
    1424          if (fileMode == mode) 
     1440//         CFile::mode_attr::t_enum fileMode = file->mode.isEmpty() ? CFile::mode_attr::write : file->mode.getValue(); 
     1441//         if (fileMode == mode) 
     1442 
    14251443         { 
    14261444           std::vector<CField*> enabledFields = file->getEnabledFields(); 
     
    14291447           { 
    14301448             // const std::vector<std::map<int, StdSize> > mapSize = enabledFields[j]->getGridDataBufferSize(contextClient); 
    1431             const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataBufferSize(contextClient); 
     1449            const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataBufferSize(contextClient,bufferForWriting); 
    14321450             // for (size_t c = 0; c < mapSize.size(); ++c) 
    14331451             // { 
Note: See TracChangeset for help on using the changeset viewer.