Changeset 1966


Ignore:
Timestamp:
10/28/20 16:24:06 (4 years ago)
Author:
oabramkina
Message:

dev_oa: first working version for tiled domains

Location:
XIOS/dev/dev_oa/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_oa/src/filter/source_filter.cpp

    r1963 r1966  
    2020    , hasMissingValue(hasMissingValue), defaultValue(defaultValue) 
    2121    , ntiles(0) 
     22    , storedTileData() 
    2223  { 
    2324    if (!grid) 
     
    5556 
    5657  template <int N> 
    57   void CSourceFilter::streamTile(CDate date, const CArray<double, N>& data, int ntile) 
     58  void CSourceFilter::streamTile(CDate date, const CArray<double, N>& tileData, int tileId) 
    5859  { 
    59     // TO DO 
     60    if (ntiles==0) 
     61    { 
     62      const double nanValue = std::numeric_limits<double>::quiet_NaN(); 
     63      storedTileData.resize(grid->storeIndex_client.numElements()); 
     64      storedTileData = nanValue; 
     65    } 
     66    grid->copyTile(tileData, storedTileData, tileId); 
     67    ++ntiles; 
     68    if (ntiles==grid->getNTiles()) 
     69    { 
     70      // Data entering workflow will be exactly of size ni*nj for a grid 2d or ni*nj*n for a grid 3d 
     71      streamData(date, storedTileData); 
     72    } 
    6073  } 
    61  
    6274 
    6375  template <int N> 
  • XIOS/dev/dev_oa/src/filter/source_filter.hpp

    r1963 r1966  
    7979      const bool mask ;        //!< indicates whether grid mask should be applied (true for clients, false for servers) 
    8080      int ntiles ; 
     81      CArray<double, 1> storedTileData; 
    8182  }; // class CSourceFilter 
    8283} // namespace xios 
  • XIOS/dev/dev_oa/src/node/domain.cpp

    r1852 r1966  
    3535      , clients(), hasLatInReadFile_(false), hasBoundsLatInReadFile_(false) 
    3636      , hasLonInReadFile_(false), hasBoundsLonInReadFile_(false) 
     37      , isTiled_(false) 
    3738   { 
    3839   } 
     
    4849      , clients(), hasLatInReadFile_(false), hasBoundsLatInReadFile_(false) 
    4950      , hasLonInReadFile_(false), hasBoundsLonInReadFile_(false) 
     51      , isTiled_(false) 
    5052   { 
    5153    } 
     
    246248   { 
    247249      return isCompressible_; 
     250   } 
     251   CATCH 
     252 
     253   bool CDomain::isTiled(void) const 
     254   TRY 
     255   { 
     256      return isTiled_; 
     257   } 
     258   CATCH 
     259 
     260   int CDomain::getTileId(int i, int j) const 
     261   TRY 
     262   { 
     263     int tileId = 0; 
     264     bool stop = false; 
     265     while (!stop) 
     266     { 
     267       if ((i >= tile_ibegin(tileId) ) && (i < tile_ni(tileId)+tile_ibegin(tileId) ) 
     268           && (j >= tile_jbegin(tileId) ) && (j < tile_nj(tileId)+tile_jbegin(tileId) ) ) 
     269         stop = true; 
     270       ++tileId; 
     271     } 
     272     return (tileId - 1); 
    248273   } 
    249274   CATCH 
     
    17231748   CATCH_DUMP_ATTR 
    17241749 
     1750   //---------------------------------------------------------------- 
     1751   void CDomain::checkTiles() 
     1752   TRY 
     1753   { 
     1754     if (!ntiles.isEmpty() && ntiles.getValue() >1)  isTiled_ = true; 
     1755     if (isTiled_) 
     1756     { 
     1757 
     1758       // Attributes tile_ni/nj and tile_i/jbegin are mandatory for tiled domains 
     1759       if (tile_ni.numElements() != ntiles || tile_ibegin.numElements() != ntiles) 
     1760           ERROR("CDomain::checkTiles()", 
     1761                 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1762                 << "'tile_ni' or 'tile_ibegin' are ill defined: these attributes must be specified for tiled domains and be of the size 'ntiles'." << std::endl 
     1763                 << "The number of tiles is  " << ntiles.getValue() << " while the size of 'tile_ni' is " << tile_ni.numElements()  
     1764                 << " and the size of 'tile_ibegin' is " << tile_ibegin.numElements() << "."); 
     1765 
     1766       if (tile_nj.numElements() != ntiles || tile_jbegin.numElements() != ntiles) 
     1767           ERROR("CDomain::checkTiles()", 
     1768                 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1769                 << "'tile_nj' or 'tile_jbegin' are ill defined: these attributes must be specified for tiled domains and be of the size 'ntiles'." << std::endl 
     1770                 << "The number of tiles is  " << ntiles.getValue() << " while the size of 'tile_nj' is " << tile_nj.numElements() 
     1771                 << " and the size of 'tile_jbegin' is " << tile_jbegin.numElements() << "."); 
     1772 
     1773       // Check on consistency of individual tile sizes and local domain size 
     1774       int sizeTiles = 0; 
     1775       for (int iTile = 0; iTile < ntiles.getValue(); ++iTile) 
     1776       { 
     1777         sizeTiles += tile_ni(iTile) * tile_nj(iTile); 
     1778       } 
     1779       if (sizeTiles != (ni*nj)) 
     1780           ERROR("CDomain::checkTiles()", 
     1781                 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1782                 << "tiles should cover the entire local domain and cannot overlap." << std::endl << "."); 
     1783 
     1784 
     1785       // Fill in tile_data_ni/nj and tile_data_i/jbegin if they are not specified 
     1786       if (tile_data_ni.numElements() == 0 || tile_data_nj.numElements() == 0) 
     1787       { 
     1788         tile_data_ni.resize(ntiles); 
     1789         tile_data_nj.resize(ntiles); 
     1790         for (int iTile = 0; iTile < ntiles.getValue(); ++iTile) 
     1791         { 
     1792           tile_data_ni(iTile) = tile_ni(iTile); 
     1793           tile_data_nj(iTile) = tile_nj(iTile); 
     1794         } 
     1795       } 
     1796 
     1797       if (tile_data_ibegin.numElements() == 0 || tile_data_jbegin.numElements() == 0) 
     1798       { 
     1799         tile_data_ibegin.resize(ntiles); 
     1800         tile_data_jbegin.resize(ntiles); 
     1801         tile_data_ibegin = 0; 
     1802         tile_data_jbegin = 0; 
     1803       } 
     1804 
     1805     } // isTiled_ 
     1806   } 
     1807   CATCH_DUMP_ATTR 
     1808 
     1809   //---------------------------------------------------------------- 
     1810   int CDomain::getTileDataISize(int tileId) const 
     1811   TRY 
     1812   { 
     1813     int retvalue = (tile_data_ni(tileId) > tile_ni(tileId)) ? tile_data_ni(tileId) : tile_ni(tileId); 
     1814     return retvalue; 
     1815   } 
     1816   CATCH_DUMP_ATTR 
     1817 
     1818   //---------------------------------------------------------------- 
     1819   int CDomain::getTileDataJSize(int tileId) const 
     1820   TRY 
     1821   { 
     1822     int retvalue = (tile_data_nj(tileId) > tile_nj(tileId)) ? tile_data_nj(tileId) : tile_nj(tileId); 
     1823     return retvalue; 
     1824   } 
     1825   CATCH_DUMP_ATTR 
     1826 
    17251827   void CDomain::checkAttributesOnClientAfterTransformation() 
    17261828   TRY 
     
    17561858        this->checkArea(); 
    17571859        this->checkLonLat(); 
     1860        this->checkTiles(); 
    17581861      } 
    17591862 
  • XIOS/dev/dev_oa/src/node/domain.hpp

    r1639 r1966  
    104104         bool isDistributed(void) const; 
    105105         bool isCompressible(void) const;  
    106   
     106 
     107         bool isTiled(void) const; 
     108         int getTileId(int i, int j) const; 
     109         int getTileDataISize(int tileId) const; 
     110         int getTileDataJSize(int tileId) const; 
     111 
    107112         std::vector<int> getNbGlob(); 
    108113         bool isEqual(CDomain* domain); 
     
    169174         void checkArea(void); 
    170175         void checkLonLat(); 
     176         void checkTiles(); 
    171177 
    172178         void setTransformations(const TransMapTypes&);          
     
    228234         bool isUnstructed_; 
    229235         std::unordered_map<size_t,size_t> globalLocalIndexMap_; 
    230         
     236 
     237         bool isTiled_; 
     238 
    231239       private: 
    232240         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m); 
  • XIOS/dev/dev_oa/src/node/grid.cpp

    r1927 r1966  
    3333      , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) 
    3434      , connectedDataSize_(), connectedServerRank_(), connectedServerRankRead_(), connectedDataSizeRead_() 
    35           , isDataDistributed_(true), isCompressible_(false) 
     35      , isDataDistributed_(true), isCompressible_(false) 
    3636      , transformations_(0), isTransformed_(false) 
    3737      , axisPositionInGrid_(), hasDomainAxisBaseRef_(false) 
     
    3939      , computedWrittenIndex_(false) 
    4040      , clients() 
     41      , nTiles_(0) 
     42      , isTiled_(false) 
     43      , storeTileIndex() 
    4144   { 
    4245     setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group")); 
     
    5457      , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) 
    5558      , connectedDataSize_(), connectedServerRank_(), connectedServerRankRead_(), connectedDataSizeRead_() 
    56           , isDataDistributed_(true), isCompressible_(false) 
     59      , isDataDistributed_(true), isCompressible_(false) 
    5760      , transformations_(0), isTransformed_(false) 
    5861      , axisPositionInGrid_(), hasDomainAxisBaseRef_(false) 
     
    6063      , computedWrittenIndex_(false) 
    6164      , clients() 
     65      , nTiles_(0) 
     66      , isTiled_(false) 
     67      , storeTileIndex() 
    6268   { 
    6369     setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group")); 
     
    102108   } 
    103109   CATCH 
     110 
     111   //--------------------------------------------------------------- 
     112   /*! 
     113    * Returns size of tile data 
     114    */ 
     115 
     116   StdSize CGrid::getTileDataSize(int tileId) 
     117   TRY 
     118   { 
     119     StdSize tileGridSize =1 ; 
     120     int numElement = axis_domain_order.numElements(); 
     121 
     122     std::vector<CAxis*> axisListP = this->getAxis(); 
     123     std::vector<CDomain*> domainListP = this->getDomains(); 
     124 
     125     int axisIndex = 0, domIndex = 0; 
     126     for (int idx = 0; idx < numElement; ++idx) 
     127     { 
     128       int eleDim = axis_domain_order(idx); 
     129       if (2 == eleDim) 
     130       { 
     131         tileGridSize *= domainListP[domIndex]->tile_data_ni(tileId); 
     132         tileGridSize *= domainListP[domIndex]->tile_data_nj(tileId); 
     133         ++domIndex; 
     134          } 
     135       else if (1 == eleDim) 
     136       { 
     137         tileGridSize *= axisListP[axisIndex]->n.getValue(); 
     138         ++axisIndex; 
     139       } 
     140     } // loop over grid elements 
     141     return tileGridSize; 
     142   } 
     143   CATCH 
     144 
     145   //--------------------------------------------------------------- 
     146   /*! 
     147    * Returns tile size 
     148    */ 
     149 
     150   StdSize CGrid::getTileSize(int tileId) 
     151   TRY 
     152   { 
     153     StdSize tileGridSize =1 ; 
     154     int numElement = axis_domain_order.numElements(); 
     155 
     156     std::vector<CAxis*> axisListP = this->getAxis(); 
     157     std::vector<CDomain*> domainListP = this->getDomains(); 
     158 
     159     int axisIndex = 0, domIndex = 0; 
     160     for (int idx = 0; idx < numElement; ++idx) 
     161     { 
     162       int eleDim = axis_domain_order(idx); 
     163       if (2 == eleDim) 
     164       { 
     165         tileGridSize *= domainListP[domIndex]->tile_ni(tileId); 
     166         tileGridSize *= domainListP[domIndex]->tile_nj(tileId); 
     167         ++domIndex; 
     168          } 
     169       else if (1 == eleDim)// So it's an axis 
     170       { 
     171         tileGridSize *= axisListP[axisIndex]->n.getValue(); 
     172         ++axisIndex; 
     173       } 
     174     } // loop over grid elements 
     175     return tileGridSize; 
     176   } 
     177   CATCH 
     178 
     179   //--------------------------------------------------------------- 
    104180 
    105181   /*! 
     
    561637          if (sendAtt) domListP[i]->sendCheckedAttributes(); 
    562638          else domListP[i]->checkAttributesOnClient(); 
     639          if (domListP[i]->isTiled()) this->isTiled_ = true; 
    563640        } 
    564641      } 
     
    902979     { 
    903980       computeClientIndex(); 
     981       if (this->isTiled_) computeTileIndex(); 
    904982       if (context->hasClient) 
    905983       { 
     
    10971175   } 
    10981176   CATCH_DUMP_ATTR 
     1177 
     1178   //--------------------------------------------------------------- 
     1179 
     1180   /* 
     1181   */ 
     1182   void CGrid::computeTileIndex() 
     1183   TRY 
     1184   { 
     1185     int numElement = axis_domain_order.numElements(); 
     1186     storeTileIndex.resize(nTiles_); 
     1187 
     1188     std::vector<CAxis*> axisListP = this->getAxis(); 
     1189     std::vector<CDomain*> domainListP = this->getDomains(); 
     1190 
     1191     // First, allocate storeTileIndex[0..ntiles] 
     1192     for (int iTile = 0; iTile < nTiles_; ++iTile) 
     1193     { 
     1194       int tileGridSize = 1; 
     1195       int axisIndex = 0, domIndex = 0; 
     1196       for (int idx = 0; idx < numElement; ++idx) 
     1197       { 
     1198         int eleDim = axis_domain_order(idx); 
     1199         if (2 == eleDim) 
     1200         { 
     1201           tileGridSize *= domainListP[domIndex]->getTileDataISize(iTile); 
     1202           tileGridSize *= domainListP[domIndex]->getTileDataJSize(iTile); 
     1203           ++domIndex; 
     1204         } 
     1205         else if (1 == eleDim)// So it's an axis 
     1206         { 
     1207           tileGridSize *= axisListP[axisIndex]->n.getValue(); 
     1208           ++axisIndex; 
     1209         } 
     1210       } // loop over grid elements 
     1211       storeTileIndex[iTile].resize(tileGridSize); 
     1212       storeTileIndex[iTile] = -1; 
     1213     } // loop over tiles 
     1214 
     1215     // Now fill in storeTileIndex 
     1216     // Currently assuming two possible situations : (1) domain x axis or (2) domain 
     1217     std::vector<int> tileIndexCount (nTiles_,0); 
     1218     int axisSize = 1; 
     1219     if (axisListP.size() != 0) axisSize = axisListP[0]->n.getValue(); 
     1220     int ni = domainListP[0]->ni.getValue(); 
     1221     int nj = domainListP[0]->nj.getValue(); 
     1222 
     1223     for (int idxAxis = 0; idxAxis < axisSize; ++idxAxis) 
     1224     { 
     1225       for (int jIdxDom = 0; jIdxDom < nj; ++jIdxDom) 
     1226       { 
     1227         for (int iIdxDom = 0; iIdxDom < ni; ++iIdxDom) 
     1228         { 
     1229           int tile = domainListP[0]->getTileId(iIdxDom, jIdxDom); 
     1230           int tileOffset =  domainListP[0]->tile_data_ibegin(tile);  // only sign of offset matters 
     1231 
     1232           // case 1: data size corresponds to tile size 
     1233           if (tileOffset == 0) 
     1234           { 
     1235             storeTileIndex[tile](tileIndexCount[tile]) = idxAxis*nj*ni + jIdxDom * ni + iIdxDom; 
     1236             ++tileIndexCount[tile]; 
     1237           } 
     1238           // case 2: masked data 
     1239           else if (tileOffset > 0) 
     1240           { 
     1241             int iBegin = domainListP[0]->tile_ibegin(tile) + domainListP[0]->tile_data_ibegin(tile); // tile data relative to domain 
     1242             int jBegin = domainListP[0]->tile_jbegin(tile) + domainListP[0]->tile_data_jbegin(tile); // tile data relative to domain 
     1243             int iEnd = iBegin + domainListP[0]->tile_data_ni(tile); 
     1244             int jEnd = jBegin + domainListP[0]->tile_data_nj(tile); 
     1245             if ((jIdxDom >= jBegin) && (jIdxDom < jEnd) && (iIdxDom >= iBegin) && (iIdxDom < iEnd)) 
     1246             { 
     1247               storeTileIndex[tile](tileIndexCount[tile]) = idxAxis*nj*ni + jIdxDom * ni + iIdxDom; 
     1248             } 
     1249             ++tileIndexCount[tile]; 
     1250           } 
     1251           // case 3: ghost zones 
     1252           else 
     1253           { 
     1254             int tileDataNi = domainListP[0]->tile_data_ni(tile); 
     1255             int tileDataNj = domainListP[0]->tile_data_nj(tile); 
     1256             int tileDomSize = tileDataNi * tileDataNj; 
     1257             int tileNi = domainListP[0]->tile_ni(tile); 
     1258             int iBegin = domainListP[0]->tile_data_ibegin(tile); 
     1259             int jBegin = domainListP[0]->tile_data_jbegin(tile); 
     1260 
     1261             // add the ghost zone at the beginning of a domain tile 
     1262             if (tileIndexCount[tile] % tileDomSize == 0) 
     1263               tileIndexCount[tile] += (abs(jBegin)*tileDataNi + abs(iBegin)); 
     1264 
     1265             storeTileIndex[tile](tileIndexCount[tile]) = idxAxis*nj*ni + jIdxDom*ni + iIdxDom; 
     1266              
     1267             // add two ghost zones at the right end of a tile 
     1268             if ( (iIdxDom+1) % tileNi == 0 ) 
     1269               tileIndexCount[tile] += (2*abs(iBegin)); 
     1270 
     1271             // add ghost zone at the end of a domain tile 
     1272             if ((tileIndexCount[tile] + abs(jBegin)*tileDataNi-abs(iBegin) + 1) % tileDomSize == 0) 
     1273               tileIndexCount[tile] += (abs(jBegin)*tileDataNi -abs(iBegin)); 
     1274 
     1275             ++tileIndexCount[tile]; 
     1276           } 
     1277         } // loop over domain first dimension 
     1278       } // loop over domain second dimension 
     1279     } // loop over axis dimension 
     1280 
     1281   } 
     1282   CATCH_DUMP_ATTR 
     1283 
    10991284//---------------------------------------------------------------- 
    11001285 
     
    13591544 
    13601545   void CGrid::maskField_arr(const double* const data, CArray<double, 1>& stored) const 
     1546   TRY 
    13611547   { 
    13621548      const StdSize size = storeIndex_client.numElements(); 
     
    13691555        for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; 
    13701556   } 
     1557   CATCH 
     1558 
     1559   void CGrid::copyTile_arr(const double* const tileData, CArray<double, 1>& stored, int tileId) 
     1560   TRY 
     1561   { 
     1562     StdSize tileSize = this->getTileSize(tileId); 
     1563     const StdSize tileDataSize = this->getTileDataSize(tileId); 
     1564 
     1565     // case 1: data correspond in size to a tile 
     1566     if (tileSize == tileDataSize) 
     1567     { 
     1568       for(StdSize i = 0; i < tileDataSize; i++) 
     1569         stored(storeTileIndex[tileId](i)) = tileData[i]; 
     1570     } 
     1571     // case 2: masked data 
     1572     else if (tileSize > tileDataSize) 
     1573     { 
     1574       int tileDataCount = 0; 
     1575       for(StdSize i = 0; i < tileSize; i++) 
     1576         if (storeTileIndex[tileId](i) >= 0) 
     1577         { 
     1578           stored(storeTileIndex[tileId](i)) = tileData[tileDataCount]; 
     1579           ++tileDataCount; 
     1580         } 
     1581     } 
     1582     // case 3: ghost zones 
     1583     else 
     1584     { 
     1585       for(StdSize i = 0; i < tileDataSize; i++) 
     1586         if (storeTileIndex[tileId](i) >= 0) 
     1587         { 
     1588           stored(storeTileIndex[tileId](i)) = tileData[i]; 
     1589         } 
     1590 
     1591     } 
     1592   } 
     1593   CATCH 
    13711594 
    13721595   void CGrid::uncompressField_arr(const double* const data, CArray<double, 1>& out) const 
     
    22532476        pDom->solveRefInheritance(apply); 
    22542477        pDom->solveInheritanceTransformation(); 
     2478        if (!pDom->ntiles.isEmpty() && pDom->ntiles.getValue()>0) nTiles_=pDom->ntiles.getValue(); 
    22552479      } 
    22562480    } 
     
    22792503      } 
    22802504    } 
     2505  } 
     2506  CATCH_DUMP_ATTR 
     2507 
     2508  int CGrid::getNTiles() 
     2509  TRY 
     2510  { 
     2511    return nTiles_; 
    22812512  } 
    22822513  CATCH_DUMP_ATTR 
  • XIOS/dev/dev_oa/src/node/grid.hpp

    r1927 r1966  
    9191         StdSize  getDataSize(void) const; 
    9292 
     93         StdSize  getTileDataSize(int tileId); 
     94 
     95         StdSize  getTileSize(int tileId); 
     96 
    9397         /// Entrees-sorties de champs 
    9498         template <int n> 
     
    100104         template <int n> 
    101105         void uncompressField(const CArray<double,n>& data, CArray<double,1>& outData) const;  
     106         template <int n> 
     107         void copyTile(const CArray<double,n>& tileData, CArray<double, 1>& stored, int tileId); 
    102108 
    103109         virtual void parse(xml::CXMLNode& node); 
     
    256262                                         const CArray<int,1>& axisDomainOrder); 
    257263 
     264         int getNTiles(); 
     265 
    258266      private: 
    259267       template<int N> 
     
    273281        void uncompressField_arr(const double* const data, CArray<double, 1>& outData) const; 
    274282        void maskField_arr(const double* const data, CArray<double, 1>& stored) const; 
     283        void copyTile_arr(const double* const tileData, CArray<double, 1>& stored, int tileId); 
    275284 
    276285        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup); 
     
    303312        void computeConnectedClientsScalarGrid();  
    304313 
     314        void computeTileIndex(); 
     315 
    305316      private: 
    306317 
     
    312323        bool isDomainAxisChecked; 
    313324        bool isIndexSent; 
     325 
     326        int nTiles_; 
     327        bool isTiled_; 
     328/** Vector containing local domain indexes for each tile */ 
     329        std::vector<CArray<int,1> > storeTileIndex; 
    314330 
    315331        CDomainGroup* vDomainGroup_; 
     
    387403 
    388404   template <int n> 
     405   void CGrid::copyTile(const CArray<double,n>& tileData, CArray<double,1>& storedData, int tileId) 
     406   { 
     407      this->copyTile_arr(tileData.dataFirst(), storedData, tileId); 
     408   } 
     409 
     410   template <int n> 
    389411   void CGrid::maskField(const CArray<double,n>& field, CArray<double,1>& stored) const 
    390412   { 
    391413//#ifdef __XIOS_DEBUG 
    392414      if (this->getDataSize() != field.numElements()) 
    393          ERROR("void CGrid::inputField(const  CArray<double,n>& field, CArray<double,1>& stored) const", 
     415         ERROR("void CGrid::maskField(const  CArray<double,n>& field, CArray<double,1>& stored) const", 
    394416                << "[ Awaiting data of size = " << this->getDataSize() << ", " 
    395417                << "Received data size = "      << field.numElements() << " ] " 
Note: See TracChangeset for help on using the changeset viewer.