Ignore:
Timestamp:
05/11/17 18:25:20 (7 years ago)
Author:
mhnguyen
Message:

Updating two-level server.
Each client now can play the role of server: It can forward data to other clients or write data like a server.
Each client must combine all data received from other client(s) before forward them or write them on files

+) Correct some bugs of exchange data_index in domain and axis
+) Reorder some functions in context.cpp to make sure that all necessary attributes are available before computing index
+) Add the mapping index for client to write data.

Test
+) On Curie
+) test_client and test_complete
+) Mode:

  • Only one level: Correct
  • Two levels: Work if using ddt (bug)

+) Only zoom is tested but other transformations should work
+) No reading test

File:
1 edited

Legend:

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

    r1099 r1129  
    2626namespace xios { 
    2727 
    28    /// ////////////////////// Définitions ////////////////////// /// 
     28   /// ////////////////////// Dfinitions ////////////////////// /// 
    2929 
    3030   CDomain::CDomain(void) 
    3131      : CObjectTemplate<CDomain>(), CDomainAttributes() 
    32       , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() 
     32      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_(), connectedServerZoomRank_() 
    3333      , hasBounds(false), hasArea(false), isDistributed_(false), isCompressible_(false), isUnstructed_(false) 
    3434      , isClientAfterTransformationChecked(false), hasLonLat(false) 
    3535      , isRedistributed_(false), hasPole(false), doZoomByIndex_(false) 
    3636      , lonvalue(), latvalue(), bounds_lonvalue(), bounds_latvalue() 
    37       , globalLocalIndexMap_() 
     37      , globalLocalIndexMap_(), computedWrittenIndex_(false) 
    3838   { 
    3939   } 
     
    4141   CDomain::CDomain(const StdString & id) 
    4242      : CObjectTemplate<CDomain>(id), CDomainAttributes() 
    43       , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() 
     43      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_(), connectedServerZoomRank_() 
    4444      , hasBounds(false), hasArea(false), isDistributed_(false), isCompressible_(false), isUnstructed_(false) 
    4545      , isClientAfterTransformationChecked(false), hasLonLat(false) 
    4646      , isRedistributed_(false), hasPole(false), doZoomByIndex_(false) 
    4747      , lonvalue(), latvalue(), bounds_lonvalue(), bounds_latvalue() 
    48       , globalLocalIndexMap_() 
     48      , globalLocalIndexMap_(), computedWrittenIndex_(false) 
    4949   { 
    5050         } 
     
    10821082   //---------------------------------------------------------------- 
    10831083 
     1084   /* 
     1085     Fill in longitude and latitude value from clients (or models) into internal values lonvalue, latvalue which 
     1086     will be used by XIOS. 
     1087   */ 
    10841088   void CDomain::completeLonLatClient(void) 
    10851089   { 
     
    11811185   } 
    11821186 
     1187   /* 
     1188     Convert internal longitude latitude value used by XIOS to "lonvalue_*" which can be retrieved with Fortran interface 
     1189   */ 
     1190   void CDomain::convertLonLatValue(void) 
     1191   { 
     1192     bool lonlatValueExisted = (0 != lonvalue.numElements()) || (0 != latvalue.numElements()); 
     1193     if (!lonvalue_2d.isEmpty() && lonlatValueExisted) 
     1194     { 
     1195       lonvalue_2d.resize(ni,nj); 
     1196       latvalue_2d.resize(ni,nj); 
     1197       if (hasBounds) 
     1198       { 
     1199         bounds_lon_2d.resize(nvertex, ni, nj); 
     1200         bounds_lat_2d.resize(nvertex, ni, nj); 
     1201       } 
     1202 
     1203       for (int j = 0; j < nj; ++j) 
     1204       { 
     1205         for (int i = 0; i < ni; ++i) 
     1206         { 
     1207           int k = j * ni + i; 
     1208 
     1209           lonvalue_2d(i,j) = lonvalue(k); 
     1210           latvalue_2d(i,j) = latvalue(k); 
     1211 
     1212           if (hasBounds) 
     1213           { 
     1214             for (int n = 0; n < nvertex; ++n) 
     1215             { 
     1216               bounds_lon_2d(n,i,j) = bounds_lonvalue(n,k); 
     1217               bounds_lat_2d(n,i,j) = bounds_latvalue(n,k); 
     1218             } 
     1219           } 
     1220         } 
     1221       } 
     1222     } 
     1223     else if (!lonvalue_1d.isEmpty()  && lonlatValueExisted) 
     1224     { 
     1225       if (type_attr::rectilinear == type) 
     1226       { 
     1227         if (ni == lonvalue_1d.numElements() && nj == latvalue_1d.numElements()) 
     1228         { 
     1229           lonvalue.resize(ni * nj); 
     1230           latvalue.resize(ni * nj); 
     1231           if (hasBounds) 
     1232           { 
     1233             bounds_lonvalue.resize(nvertex, ni * nj); 
     1234             bounds_latvalue.resize(nvertex, ni * nj); 
     1235           } 
     1236 
     1237           for (int j = 0; j < nj; ++j) 
     1238           { 
     1239             for (int i = 0; i < ni; ++i) 
     1240             { 
     1241               int k = j * ni + i; 
     1242 
     1243               lonvalue(k) = lonvalue_1d(i); 
     1244               latvalue(k) = latvalue_1d(j); 
     1245 
     1246               if (hasBounds) 
     1247               { 
     1248                 for (int n = 0; n < nvertex; ++n) 
     1249                 { 
     1250                   bounds_lonvalue(n,k) = bounds_lon_1d(n,i); 
     1251                   bounds_latvalue(n,k) = bounds_lat_1d(n,j); 
     1252                 } 
     1253               } 
     1254             } 
     1255           } 
     1256         } 
     1257         else if (i_index.numElements() == lonvalue_1d.numElements() && j_index.numElements() == latvalue_1d.numElements()  && !lonlatValueExisted) 
     1258         { 
     1259           lonvalue.reference(lonvalue_1d); 
     1260           latvalue.reference(latvalue_1d); 
     1261            if (hasBounds) 
     1262           { 
     1263             bounds_lonvalue.reference(bounds_lon_1d); 
     1264             bounds_latvalue.reference(bounds_lat_1d); 
     1265           } 
     1266         } 
     1267         else 
     1268           ERROR("CDomain::completeLonClient(void)", 
     1269                 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 
     1270                 << "'lonvalue_1d' and 'latvalue_1d' does not have the same size as the local domain." << std::endl 
     1271                 << "'lonvalue_1d' size is " << lonvalue_1d.numElements()  
     1272                 << " and 'latvalue_1d' size is " << latvalue_1d.numElements() << std::endl  
     1273                 << " They should be correspondingly " << ni.getValue() << " and "  << nj.getValue() << " or " << std::endl 
     1274                 << i_index.numElements() << " and "  << j_index.numElements() << "."); 
     1275       } 
     1276       else if (type == type_attr::curvilinear || type == type_attr::unstructured  && !lonlatValueExisted) 
     1277       { 
     1278         lonvalue.reference(lonvalue_1d); 
     1279         latvalue.reference(latvalue_1d); 
     1280         if (hasBounds) 
     1281         { 
     1282           bounds_lonvalue.reference(bounds_lon_1d); 
     1283           bounds_latvalue.reference(bounds_lat_1d); 
     1284         } 
     1285       } 
     1286     } 
     1287   } 
     1288 
     1289 
    11831290   void CDomain::checkBounds(void) 
    11841291   { 
     
    13951502 
    13961503      if (context->hasClient && !context->hasServer) 
    1397       { // CÃŽté client uniquement 
     1504      { // Ct client uniquement 
    13981505         this->checkMask(); 
    13991506         this->checkDomainData(); 
     
    14021509      } 
    14031510      else 
    1404       { // CÃŽté serveur uniquement 
     1511      { // Ct serveur uniquement 
    14051512      } 
    14061513 
     
    14351542 
    14361543      if (context->hasClient) 
    1437       { // CÃŽté client uniquement 
     1544      { // Ct client uniquement 
    14381545         this->checkMask(); 
    14391546         this->checkDomainData(); 
     
    14431550      } 
    14441551      else 
    1445       { // CÃŽté serveur uniquement 
     1552      { // Ct serveur uniquement 
    14461553      } 
    14471554 
     
    15491656        for (i = 0; i < nbIndex; ++i) 
    15501657          globalLocalIndexMap_[globalIndexDomain(i)] = i; 
    1551  
    15521658      } 
    15531659 
     
    15981704          zoom_nj     = zoom_jend-zoom_jbegin+1; 
    15991705      } 
     1706 
     1707      // if (globalLocalIndexZoomMap_.empty()) 
     1708      // { 
     1709      //   int nbIndexZoom = globalIndexDomainZoom.numElements(); 
     1710      //   for (i = 0; i < nbIndex; ++i) 
     1711      //     globalLocalIndexZoomMap_[globalIndexDomainZoom(i)] = i; 
     1712      // } 
    16001713 
    16011714 
     
    16901803      for (it = globalIndexDomainOnServer.begin(); it != ite; ++it) { 
    16911804        connectedServerRank_.push_back(it->first); 
    1692         // std::vector<size_t> vec = it->second; 
    1693         // std::sort(vec.begin(), vec.end()); 
    1694         // indSrv_[it->first] = vec; 
    16951805      } 
    16961806 
     
    17001810      clientServerMap->computeServerIndexMapping(globalIndexDomainZoom); 
    17011811      CClientServerMapping::GlobalIndexMap& globalIndexDomainZoomOnServer = clientServerMap->getGlobalIndexOnServer(); 
    1702 //      indZoomSrv_.swap(globalIndexDomainZoomOnServer); 
    1703       std::vector<int> connectedServerZoomRank; //(indZoomSrv_.size()); 
    1704 //      for (it = indZoomSrv_.begin(); it != indZoomSrv_.end(); ++it) 
    1705 //        connectedServerZoomRank.push_back(it->first); 
    1706       for (it = globalIndexDomainZoomOnServer.begin(); it != globalIndexDomainZoomOnServer.end(); ++it) 
    1707       { 
    1708         connectedServerZoomRank.push_back(it->first); 
    1709         std::vector<size_t> vec = it->second; 
    1710         std::sort(vec.begin(), vec.end()); 
    1711         indZoomSrv_[it->first] = vec; 
    1712       } 
    1713       nbConnectedClientsZoom_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerZoomRank); 
     1812      indZoomSrv_.swap(globalIndexDomainZoomOnServer); 
     1813       
     1814     for (it = indZoomSrv_.begin(); it != indZoomSrv_.end(); ++it) 
     1815       connectedServerZoomRank_.push_back(it->first); 
     1816 
     1817      nbConnectedClientsZoom_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerZoomRank_); 
    17141818 
    17151819      delete clientServerMap; 
     
    17211825    return indSrv_; 
    17221826  } 
     1827 
     1828   void CDomain::computeWrittenIndex() 
     1829   {   
     1830      if (computedWrittenIndex_) return; 
     1831      computedWrittenIndex_ = true; 
     1832 
     1833      CContext* context=CContext::getCurrent() ; 
     1834      CContextClient* client = context->client;  
     1835 
     1836      std::vector<int> nBegin(2), nSize(2), nBeginGlobal(2), nGlob(2); 
     1837      nBegin[0]       = zoom_ibegin;  nBegin[1] = zoom_jbegin; 
     1838      nSize[0]        = zoom_ni;      nSize[1]  = zoom_nj; 
     1839      nBeginGlobal[0] = 0; nBeginGlobal[1] = 0; 
     1840      nGlob[0]        = ni_glo;   nGlob[1] = nj_glo; 
     1841      CDistributionServer srvDist(client->clientSize, nBegin, nSize, nBeginGlobal, nGlob);  
     1842      const CArray<size_t,1>& writtenGlobalIndex  = srvDist.getGlobalIndex(); 
     1843 
     1844      size_t nbWritten = 0, indGlo;       
     1845      boost::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(), 
     1846                                                          ite = globalLocalIndexMap_.end(), it;           
     1847      CArray<size_t,1>::const_iterator itSrvb = writtenGlobalIndex.begin(), 
     1848                                       itSrve = writtenGlobalIndex.end(), itSrv; 
     1849      localIndexToWriteOnServer.resize(writtenGlobalIndex.numElements()); 
     1850      for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 
     1851      { 
     1852        indGlo = *itSrv; 
     1853        if (ite != globalLocalIndexMap_.find(indGlo)) 
     1854        { 
     1855          localIndexToWriteOnServer(nbWritten) = globalLocalIndexMap_[indGlo]; 
     1856          ++nbWritten; 
     1857        }                  
     1858      } 
     1859   } 
    17231860 
    17241861  /*! 
     
    17291866  { 
    17301867    sendDistributionAttributes(); 
    1731     sendIndex(); 
    1732     sendIndex();     
     1868    sendIndex();    
     1869    // sendIndexZoom();  
    17331870    sendMask(); 
    17341871    sendLonLat(); 
     
    17571894      list<CArray<int,1> > list_indZoom, list_writtenInd, list_indGlob; 
    17581895 
    1759       boost::unordered_map<int, vector<size_t> >::const_iterator itIndex, iteIndex, itZoom, iteZoom; 
    1760       iteIndex = indSrv_.end(); iteZoom = indZoomSrv_.end(); 
     1896      boost::unordered_map<int, vector<size_t> >::const_iterator itIndex, iteIndex; 
     1897      iteIndex = indSrv_.end(); 
    17611898      for (int k = 0; k < connectedServerRank_.size(); ++k) 
    17621899      { 
     
    17661903        if (iteIndex != itIndex) 
    17671904          nbIndGlob = itIndex->second.size(); 
    1768         int nbIndZoom = 0; 
    1769         itZoom = indZoomSrv_.find(rank); 
    1770         if (iteZoom != itZoom) 
    1771           nbIndZoom = itZoom->second.size(); 
    1772  
    1773         list_indGlob.push_back(CArray<int,1>(nbIndGlob)); 
    1774         list_indZoom.push_back(CArray<int,1>(nbIndZoom)); 
    1775  
    1776         CArray<int,1>& indZoom = list_indZoom.back(); 
     1905 
     1906        list_indGlob.push_back(CArray<int,1>(nbIndGlob));         
     1907 
    17771908        CArray<int,1>& indGlob = list_indGlob.back(); 
    17781909        for (n = 0; n < nbIndGlob; ++n) 
    17791910        { 
    17801911          indGlob(n) = static_cast<int>(itIndex->second[n]); 
    1781         } 
    1782  
    1783         for (n = 0; n < nbIndZoom; ++n) 
    1784         { 
    1785           indZoom(n) = static_cast<int>(itZoom->second[n]); 
    17861912        } 
    17871913 
     
    17891915        list_msgsIndex.back() << this->getId() << (int)type; // enum ne fonctionne pour les message => ToFix 
    17901916        list_msgsIndex.back() << isCurvilinear; 
    1791         list_msgsIndex.back() << list_indGlob.back() << list_indZoom.back() << doZoomByIndex_; //list_indi.back() << list_indj.back(); 
    1792         if (!doZoomByIndex_)  
    1793         { 
    1794           //list_msgsIndex.back() << zoom_ni.getValue() << zoom_ibegin.getValue() << zoom_nj.getValue() << zoom_jbegin.getValue(); 
    1795         } 
     1917        list_msgsIndex.back() << list_indGlob.back(); //list_indi.back() << list_indj.back(); 
    17961918        
    17971919        // if (isCompressible_) 
     
    18111933 
    18121934      client->sendEvent(eventIndex); 
     1935    } 
     1936  } 
     1937 
     1938  /*! 
     1939    Send global index and zoom index from client to connected client(s) 
     1940    zoom index can be smaller than global index 
     1941  */ 
     1942  void CDomain::sendIndexZoom() 
     1943  { 
     1944    int ns, n, i, j, ind, nv, idx; 
     1945    CContext* context = CContext::getCurrent(); 
     1946 
     1947    // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 
     1948    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1; 
     1949    for (int p = 0; p < nbSrvPools; ++p) 
     1950    { 
     1951      CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[p] : context->client; 
     1952      CEventClient eventIndexZoom(getType(), EVENT_ID_INDEX_ZOOM); 
     1953 
     1954      list<CMessage> list_msgsIndex; 
     1955      list<CArray<int,1> > list_indZoom; 
     1956 
     1957      boost::unordered_map<int, vector<size_t> >::const_iterator itZoom, iteZoom; 
     1958      iteZoom = indZoomSrv_.end(); 
     1959      for (int k = 0; k < connectedServerZoomRank_.size(); ++k) 
     1960      { 
     1961        int nbIndGlob = 0; 
     1962        int rank = connectedServerZoomRank_[k]; 
     1963        int nbIndZoom = 0; 
     1964        itZoom = indZoomSrv_.find(rank); 
     1965        if (iteZoom != itZoom) 
     1966          nbIndZoom = itZoom->second.size(); 
     1967         
     1968        list_indZoom.push_back(CArray<int,1>(nbIndZoom)); 
     1969        CArray<int,1>& indZoom = list_indZoom.back(); 
     1970        for (n = 0; n < nbIndZoom; ++n) 
     1971        { 
     1972          indZoom(n) = static_cast<int>(itZoom->second[n]); 
     1973        } 
     1974 
     1975        list_msgsIndex.push_back(CMessage()); 
     1976        list_msgsIndex.back() << this->getId(); // enum ne fonctionne pour les message => ToFix         
     1977        list_msgsIndex.back() << list_indZoom.back() << doZoomByIndex_; //list_indi.back() << list_indj.back       
     1978 
     1979        eventIndexZoom.push(rank, nbConnectedClientsZoom_[rank], list_msgsIndex.back()); 
     1980      } 
     1981 
     1982      client->sendEvent(eventIndexZoom); 
    18131983    } 
    18141984  } 
     
    20362206        list_msgsLat.push_back(CMessage()); 
    20372207 
    2038         list_msgsLon.back() << this->getId() << hasLonLat << list_lon.back() << hasBounds; 
    2039         list_msgsLat.back() << this->getId() << hasLonLat << list_lat.back() << hasBounds; 
    2040  
     2208        list_msgsLon.back() << this->getId() << hasLonLat; 
     2209        if (hasLonLat)  
     2210          list_msgsLon.back() << list_lon.back(); 
     2211        list_msgsLon.back()  << hasBounds; 
    20412212        if (hasBounds) 
    20422213        { 
    20432214          list_msgsLon.back() << list_boundslon.back(); 
     2215        } 
     2216 
     2217        list_msgsLat.back() << this->getId() << hasLonLat; 
     2218        if (hasLonLat) 
     2219          list_msgsLat.back() << list_lat.back(); 
     2220        list_msgsLat.back() << hasBounds; 
     2221        if (hasBounds) 
     2222        {           
    20442223          list_msgsLat.back() << list_boundslat.back(); 
    20452224        } 
     
    20762255 
    20772256      int nbIndex = i_index.numElements(); 
     2257      int niByIndex = max(i_index) - min(i_index) + 1; 
     2258      int njByIndex = max(j_index) - min(j_index) + 1;  
     2259      int dataIindexBound = (1 == data_dim) ? (niByIndex * njByIndex) : niByIndex; 
     2260      int dataJindexBound = (1 == data_dim) ? (niByIndex * njByIndex) : njByIndex; 
     2261 
     2262       
    20782263      CArray<int,1> dataIIndex(nbIndex), dataJIndex(nbIndex); 
    2079       dataIIndex = -1; dataJIndex = -1, ind = 0; 
     2264      dataIIndex = -1;  
     2265      dataJIndex = -1; 
     2266      ind = 0; 
     2267 
    20802268      for (idx = 0; idx < data_i_index.numElements(); ++idx) 
    20812269      { 
    2082         if ((0 <= data_i_index(idx)) && (data_i_index(idx) < ni) && (ind < nbIndex)) 
    2083         { 
    2084           dataIIndex(ind) = data_i_index(idx); 
    2085           dataJIndex(ind) = data_j_index(idx); 
    2086           ++ind; 
     2270        int dataIidx = data_i_index(idx) + data_ibegin; 
     2271        int dataJidx = data_j_index(idx) + data_jbegin; 
     2272        if ((0 <= dataIidx) && (dataIidx < dataIindexBound) && 
     2273            (0 <= dataJidx) && (dataJidx < dataJindexBound)) 
     2274        { 
     2275          dataIIndex((1 == data_dim) ? dataIidx : dataJidx * ni + dataIidx) = 1; //i_index(dataIidx);//dataIidx; 
     2276          dataJIndex((1 == data_dim) ? dataIidx : dataJidx * ni + dataIidx) = 1; //j_index(dataJidx);//           
    20872277        } 
    20882278      } 
     
    21312321        case EVENT_ID_INDEX: 
    21322322          recvIndex(event); 
     2323          return true; 
     2324          break; 
     2325        case EVENT_ID_INDEX_ZOOM: 
     2326          recvIndexZoom(event); 
    21332327          return true; 
    21342328          break; 
     
    21982392  { 
    21992393    int nbReceived = rankBuffers.size(), i, ind, index, type_int; 
    2200     recvClientRanks_.resize(nbReceived); 
    2201     vector<CArray<int,1> > recvZoomInd(nbReceived); 
    2202     int ni_zoom_tmp, ibegin_zoom_tmp, nj_zoom_tmp, jbegin_zoom_tmp; 
     2394    recvClientRanks_.resize(nbReceived);         
    22032395 
    22042396    std::map<int, CBufferIn*>::iterator it = rankBuffers.begin(), ite = rankBuffers.end(); 
     
    22082400       recvClientRanks_[ind] = it->first; 
    22092401       CBufferIn& buffer = *(it->second); 
    2210        buffer >> type_int >> isCurvilinear >> indGlob_[it->first] >> recvZoomInd[ind] >> doZoomByIndex_;  
    2211        if (!doZoomByIndex_) 
    2212        { 
    2213         //buffer >> ni_zoom_tmp >> ibegin_zoom_tmp >> nj_zoom_tmp >> jbegin_zoom_tmp; 
    2214        } 
     2402       buffer >> type_int >> isCurvilinear >> indGlob_[it->first];  
    22152403       type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix 
    22162404    } 
     
    22242412    j_index.resize(nbIndGlob); 
    22252413 
     2414    globalLocalIndexMap_.rehash(std::ceil(nbIndGlob/globalLocalIndexMap_.max_load_factor())); 
    22262415    nbIndGlob = 0; 
    22272416    for (i = 0; i < nbReceived; ++i) 
     
    22332422         i_index(nbIndGlob) = index % ni_glo; 
    22342423         j_index(nbIndGlob) = index / ni_glo; 
     2424         globalLocalIndexMap_[index] = nbIndGlob;   
    22352425         ++nbIndGlob; 
    22362426      }  
    2237     } 
    2238  
    2239     int nbZoomInd = 0; 
    2240     for (i = 0; i < nbReceived; ++i) 
    2241     { 
    2242       nbZoomInd += recvZoomInd[i].numElements(); 
    2243     } 
    2244  
    2245     if (doZoomByIndex_) 
    2246     { 
    2247       zoom_i_index.resize(nbZoomInd); 
    2248       zoom_j_index.resize(nbZoomInd); 
    2249        
    2250       nbZoomInd = 0; 
    2251       for (i = 0; i < nbReceived; ++i) 
    2252       { 
    2253         CArray<int,1>& tmp = recvZoomInd[i]; 
    2254         for (ind = 0; ind < tmp.numElements(); ++ind) 
    2255         { 
    2256            index = tmp(ind); 
    2257            zoom_i_index(nbZoomInd) = index % ni_glo; 
    2258            zoom_j_index(nbZoomInd) = index / ni_glo; 
    2259            ++nbZoomInd; 
    2260         }  
    2261       }       
    2262     } 
    2263     else  
    2264     { 
    2265       // zoom_ni.setValue(ni_zoom_tmp); 
    2266       // zoom_ibegin.setValue(ibegin_zoom_tmp); 
    2267       // zoom_nj.setValue(nj_zoom_tmp); 
    2268       // zoom_jbegin.setValue(jbegin_zoom_tmp); 
    2269       // int nbZoom = ni_zoom_tmp * nj_zoom_tmp; 
    2270       // zoom_i_index.resize(nbZoom); 
    2271       // zoom_j_index.resize(nbZoom); 
    2272       // nbZoom = 0; 
    2273       // for (int j = 0; j < nj_zoom_tmp; ++j)  
    2274       //   for (int i = 0; i < ni_zoom_tmp; ++i) 
    2275       //   { 
    2276       //     zoom_i_index(nbZoom) = ibegin_zoom_tmp + i; 
    2277       //     zoom_j_index(nbZoom) = jbegin_zoom_tmp + j; 
    2278       //     ++nbZoom; 
    2279       //   } 
    2280     } 
    2281  
    2282     globalLocalIndexMap_.rehash(std::ceil(nbIndGlob/globalLocalIndexMap_.max_load_factor())); 
    2283     nbIndGlob = 0; 
    2284     for (int j = 0; j < nj; ++j)  
    2285       for (int i = 0; i < ni; ++i) 
    2286       { 
    2287         globalLocalIndexMap_[(i + ibegin) + (j + jbegin) * ni_glo] = nbIndGlob; 
    2288         ++nbIndGlob; 
    2289       } 
    2290  
    2291  
     2427    }    
    22922428     
    22932429    // { 
     
    23682504 
    23692505  /*! 
     2506    Receive index event from clients(s) 
     2507    \param[in] event event contain info about rank and associated index 
     2508  */ 
     2509  void CDomain::recvIndexZoom(CEventServer& event) 
     2510  { 
     2511    string domainId; 
     2512    std::map<int, CBufferIn*> rankBuffers; 
     2513 
     2514    list<CEventServer::SSubEvent>::iterator it; 
     2515    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
     2516    {       
     2517      CBufferIn* buffer = it->buffer; 
     2518      *buffer >> domainId; 
     2519      rankBuffers[it->rank] = buffer;         
     2520    } 
     2521    get(domainId)->recvIndexZoom(rankBuffers); 
     2522  } 
     2523 
     2524  /*! 
     2525    Receive index information from client(s) 
     2526    \param[in] rankBuffers rank of sending client and the corresponding receive buffer   
     2527  */ 
     2528  void CDomain::recvIndexZoom(std::map<int, CBufferIn*>& rankBuffers) 
     2529  { 
     2530    int nbReceived = rankBuffers.size(), i, ind, index, type_int; 
     2531    recvClientZoomRanks_.resize(nbReceived);     
     2532    int ni_zoom_tmp, ibegin_zoom_tmp, nj_zoom_tmp, jbegin_zoom_tmp; 
     2533 
     2534    std::map<int, CBufferIn*>::iterator it = rankBuffers.begin(), ite = rankBuffers.end(); 
     2535    ind = 0; 
     2536    for (ind = 0; it != ite; ++it, ++ind) 
     2537    {        
     2538       recvClientZoomRanks_[ind] = it->first; 
     2539       CBufferIn& buffer = *(it->second); 
     2540       buffer >> indGlobZoom_[it->first] >> doZoomByIndex_;         
     2541    } 
     2542 
     2543    int nbZoomInd = 0; 
     2544    for (i = 0; i < nbReceived; ++i) 
     2545    { 
     2546      nbZoomInd += indGlobZoom_[recvClientZoomRanks_[i]].numElements(); 
     2547    } 
     2548 
     2549    if (doZoomByIndex_) 
     2550    { 
     2551      zoom_i_index.resize(nbZoomInd); 
     2552      zoom_j_index.resize(nbZoomInd); 
     2553       
     2554      nbZoomInd = 0; 
     2555      for (i = 0; i < nbReceived; ++i) 
     2556      { 
     2557        CArray<int,1>& tmp = indGlobZoom_[recvClientRanks_[i]]; 
     2558        for (ind = 0; ind < tmp.numElements(); ++ind) 
     2559        { 
     2560           index = tmp(ind); 
     2561           zoom_i_index(nbZoomInd) = index % ni_glo; 
     2562           zoom_j_index(nbZoomInd) = index / ni_glo; 
     2563           ++nbZoomInd; 
     2564        }  
     2565      }       
     2566    } 
     2567    else  
     2568    { 
     2569    } 
     2570 
     2571    // globalLocalIndexZoomMap_.rehash(std::ceil(nbZoomInd/globalLocalIndexZoomMap_.max_load_factor())); 
     2572    // nbZoomInd = 0; 
     2573    // for (int j = 0; j < zoom_nj; ++j)  
     2574    //   for (int i = 0; i < zoom_ni; ++i) 
     2575    //   { 
     2576    //     globalLocalIndexZoomMap_[(i + zoom_ibegin) + (j + zoom_jbegin) * ni_glo] = nbZoomInd; 
     2577    //     ++nbZoomInd; 
     2578    //   } 
     2579  } 
     2580 
     2581  /*! 
    23702582    Receive attributes event from clients(s) 
    23712583    \param[in] event event contain info about rank and associated attributes 
     
    25062718  void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers) 
    25072719  { 
    2508     int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex; 
     2720    int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex, lInd; 
    25092721    if (nbReceived != recvClientRanks_.size()) 
    25102722      ERROR("void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers)", 
     
    25192731      CBufferIn& buffer = *(rankBuffers[rank]); 
    25202732      buffer >> hasLonLat; 
    2521       buffer >> recvLonValue[i]; 
     2733      if (hasLonLat) 
     2734        buffer >> recvLonValue[i]; 
    25222735      buffer >> hasBounds; 
    25232736      if (hasBounds) 
     
    25252738    } 
    25262739 
    2527     lonvalue.resize(zoom_ni*zoom_nj); 
    2528     lonvalue = 0; 
    2529  
    2530     if (hasBounds) 
     2740    if (hasLonLat) 
    25312741    { 
    2532       bounds_lonvalue.resize(nvertex,zoom_ni*zoom_nj); 
    2533       bounds_lonvalue = 0.; 
    2534     } 
     2742      int nbLonInd = 0; 
     2743      for (i = 0; i < nbReceived; ++i) 
     2744      { 
     2745        nbLonInd += recvLonValue[i].numElements(); 
     2746      } 
    25352747     
    2536     for (i = 0; i < nbReceived; ++i) 
    2537     { 
    2538       int rank = recvClientRanks_[i]; 
    2539       CArray<int,1> &indi = indGlob_[rank], &indj = indGlob_[rank];       
    2540       for (ind = 0; ind < indi.numElements(); ++ind) 
    2541       { 
    2542          iindex = indi(ind) % ni_glo; jindex = indj(ind) / ni_glo; 
    2543          index = (iindex - zoom_ibegin) + (jindex - zoom_jbegin) * zoom_ni; 
    2544          lonvalue(index) = recvLonValue[i](ind); 
    2545          if (hasBounds) 
    2546          {           
    2547           for (int nv = 0; nv < nvertex; ++nv) 
    2548             bounds_lonvalue(nv, index) = recvBoundsLonValue[i](nv, ind); 
    2549          }          
    2550       } 
    2551     } 
     2748      if (nbLonInd != globalLocalIndexMap_.size()) 
     2749        info (0) << "Something wrong with longitude index "<< std::endl; 
     2750 
     2751      lonvalue.resize(nbLonInd); 
     2752      if (hasBounds) 
     2753      { 
     2754        bounds_lonvalue.resize(nvertex,nbLonInd); 
     2755        bounds_lonvalue = 0.; 
     2756      } 
     2757 
     2758      nbLonInd = 0; 
     2759      for (i = 0; i < nbReceived; ++i) 
     2760      { 
     2761        CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; 
     2762        CArray<double,1>& tmp = recvLonValue[i]; 
     2763        for (ind = 0; ind < tmp.numElements(); ++ind) 
     2764        { 
     2765          lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; 
     2766          lonvalue(lInd) = tmp(ind);  
     2767           if (hasBounds) 
     2768           {           
     2769            for (int nv = 0; nv < nvertex; ++nv) 
     2770              bounds_lonvalue(nv, lInd) = recvBoundsLonValue[i](nv, ind); 
     2771           }                   
     2772        } 
     2773      }        
     2774    } 
     2775 
     2776 
     2777 
     2778    // lonvalue.resize(zoom_ni*zoom_nj); 
     2779    // lonvalue = 0; 
     2780 
     2781    // if (hasBounds) 
     2782    // { 
     2783    //   bounds_lonvalue.resize(nvertex,zoom_ni*zoom_nj); 
     2784    //   bounds_lonvalue = 0.; 
     2785    // } 
     2786     
     2787    // if (0 == lonvalue.numElements()) return; 
     2788 
     2789    // for (i = 0; i < nbReceived; ++i) 
     2790    // { 
     2791    //   int rank = recvClientRanks_[i]; 
     2792    //   CArray<int,1> &indi = indGlob_[rank], &indj = indGlob_[rank];       
     2793    //   for (ind = 0; ind < indi.numElements(); ++ind) 
     2794    //   { 
     2795    //      iindex = indi(ind) % ni_glo; jindex = indj(ind) / ni_glo; 
     2796    //      index = (iindex - zoom_ibegin) + (jindex - zoom_jbegin) * zoom_ni; 
     2797    //      lonvalue(index) = recvLonValue[i](ind); 
     2798    //      if (hasBounds) 
     2799    //      {           
     2800    //       for (int nv = 0; nv < nvertex; ++nv) 
     2801    //         bounds_lonvalue(nv, index) = recvBoundsLonValue[i](nv, ind); 
     2802    //      }          
     2803    //   } 
     2804    // } 
    25522805  } 
    25532806 
     
    25772830  void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers) 
    25782831  { 
    2579     int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex; 
     2832    int nbReceived = rankBuffers.size(), i, ind, index, iindex, jindex, lInd; 
    25802833    if (nbReceived != recvClientRanks_.size()) 
    25812834      ERROR("void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)", 
     
    25902843      CBufferIn& buffer = *(rankBuffers[rank]); 
    25912844      buffer >> hasLonLat; 
    2592       buffer >> recvLatValue[i]; 
     2845      if (hasLonLat) 
     2846        buffer >> recvLatValue[i]; 
    25932847      buffer >> hasBounds; 
    25942848      if (hasBounds) 
     
    25962850    } 
    25972851 
    2598     latvalue.resize(zoom_ni*zoom_nj); 
    2599     latvalue = 0; 
    2600  
    2601     if (hasBounds) 
     2852    if (hasLonLat) 
    26022853    { 
    2603       bounds_latvalue.resize(nvertex,zoom_ni*zoom_nj); 
    2604       bounds_latvalue = 0. ; 
    2605     } 
     2854      int nbLatInd = 0; 
     2855      for (i = 0; i < nbReceived; ++i) 
     2856      { 
     2857        nbLatInd += recvLatValue[i].numElements(); 
     2858      } 
    26062859     
    2607     for (i = 0; i < nbReceived; ++i) 
    2608     { 
    2609       int rank = recvClientRanks_[i]; 
    2610       CArray<int,1> &indi = indGlob_[rank], &indj = indGlob_[rank]; 
    2611       CArray<double,1>& lat = recvLatValue[i]; 
    2612       for (ind = 0; ind < indi.numElements(); ++ind) 
    2613       { 
    2614          iindex = indi(ind) % ni_glo; jindex = indj(ind) / ni_glo; 
    2615          index = (iindex - zoom_ibegin) + (jindex - zoom_jbegin) * zoom_ni; 
    2616          latvalue(index) = lat(ind); 
    2617          if (hasBounds) 
    2618          { 
    2619           CArray<double,2>& boundslat = recvBoundsLatValue[i]; 
    2620           for (int nv = 0; nv < nvertex; ++nv) 
    2621             bounds_latvalue(nv, index) = boundslat(nv, ind); 
    2622          }          
    2623       } 
     2860      if (nbLatInd != globalLocalIndexMap_.size()) 
     2861        info (0) << "Something wrong with latitude index "<< std::endl; 
     2862 
     2863      latvalue.resize(nbLatInd); 
     2864      if (hasBounds) 
     2865      { 
     2866        bounds_latvalue.resize(nvertex,nbLatInd); 
     2867        bounds_latvalue = 0. ; 
     2868      } 
     2869 
     2870      nbLatInd = 0; 
     2871      for (i = 0; i < nbReceived; ++i) 
     2872      { 
     2873        CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; 
     2874        CArray<double,1>& tmp = recvLatValue[i]; 
     2875        for (ind = 0; ind < tmp.numElements(); ++ind) 
     2876        { 
     2877          lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; 
     2878          latvalue(lInd) = tmp(ind);     
     2879           if (hasBounds) 
     2880           { 
     2881            CArray<double,2>& boundslat = recvBoundsLatValue[i]; 
     2882            for (int nv = 0; nv < nvertex; ++nv) 
     2883              bounds_latvalue(nv, lInd) = boundslat(nv, ind); 
     2884           }    
     2885          ++nbLatInd; 
     2886        } 
     2887      }        
    26242888    } 
    26252889  } 
     
    26512915  void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers) 
    26522916  { 
    2653     int nbReceived = rankBuffers.size(), i, ind, index; 
     2917    int nbReceived = rankBuffers.size(), i, ind, index, lInd; 
    26542918    if (nbReceived != recvClientRanks_.size()) 
    26552919      ERROR("void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers)", 
     
    26692933    int nbAreaInd = 0; 
    26702934    for (i = 0; i < nbReceived; ++i) 
    2671     { 
    2672       if (hasArea) 
    2673         nbAreaInd += recvAreaValue[i].numElements(); 
     2935    {       
     2936      nbAreaInd += recvAreaValue[i].numElements(); 
    26742937    } 
    26752938   
    2676     areavalue.resize(nbAreaInd); 
    2677     nbAreaInd = 0; 
     2939    if (nbAreaInd != globalLocalIndexMap_.size()) 
     2940      info (0) << "Something wrong with latitude index "<< std::endl; 
     2941 
    26782942    if (hasArea) 
    26792943    { 
     2944      areavalue.resize(nbAreaInd); 
     2945      nbAreaInd = 0;       
    26802946      for (i = 0; i < nbReceived; ++i) 
    26812947      { 
     2948        CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; 
    26822949        CArray<double,1>& tmp = recvAreaValue[i]; 
    26832950        for (ind = 0; ind < tmp.numElements(); ++ind) 
    26842951        { 
    2685           area(nbAreaInd) = tmp(ind);       
    2686           ++nbAreaInd; 
    2687         } 
    2688       } 
     2952          lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; 
     2953          areavalue(lInd) = tmp(ind);           
     2954        } 
     2955      } 
     2956       
    26892957    } 
    26902958  } 
     
    27282996  void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers) 
    27292997  { 
    2730     int nbReceived = rankBuffers.size(), i, ind, index, indexI, type_int;     
     2998    int nbReceived = rankBuffers.size(), i, ind, index, indexI, indexJ, type_int, lInd;     
    27312999    if (nbReceived != recvClientRanks_.size()) 
    2732       ERROR("void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)", 
     3000      ERROR("void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers)", 
    27333001           << "The number of sending clients is not correct." 
    27343002           << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 
     
    27433011    } 
    27443012    
    2745     int nbCompressedData = 0;  
     3013    int nbIndex = i_index.numElements(); 
     3014    CArray<int,1> dataIIndex(nbIndex), dataJIndex(nbIndex); 
     3015    dataIIndex = -1; dataJIndex = -1; 
     3016 
     3017    nbIndex = 0; 
    27463018    for (i = 0; i < nbReceived; ++i) 
     3019    {       
     3020      CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; 
     3021      CArray<int,1>& tmpI = recvDataIIndex[i];     
     3022      CArray<int,1>& tmpJ = recvDataJIndex[i];      
     3023      if ((tmpI.numElements() != tmpInd.numElements()) || (tmpJ.numElements() != tmpInd.numElements())) 
     3024          ERROR("void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers)", 
     3025             << "The number of global received index is not coherent with the number of received data index." 
     3026             << "Expected number of global index: " << tmpI.numElements() << " but received " << tmpInd.numElements()); 
     3027 
     3028      for (ind = 0; ind < tmpI.numElements(); ++ind) 
     3029      { 
     3030         lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; 
     3031         dataIIndex(lInd) = tmpI(ind); 
     3032         dataJIndex(lInd) = tmpJ(ind);          
     3033      }  
     3034    } 
     3035 
     3036    int nbCompressedData = 0;   
     3037    for (ind = 0; ind < dataIIndex.numElements(); ++ind) 
    27473038    { 
    2748       CArray<int,1>& tmp = recvDataIIndex[i]; 
    2749       for (ind = 0; ind < tmp.numElements(); ++ind) 
    2750       { 
    2751          index = tmp(ind); 
    2752          if (0 <= index) 
    2753            ++nbCompressedData; 
    2754       }         
    2755     } 
    2756  
     3039       indexI = dataIIndex(ind); indexJ = dataJIndex(ind); 
     3040       if ((0 <= indexI) && (0 <= indexJ)) 
     3041         ++nbCompressedData; 
     3042    }         
     3043   
    27573044    data_i_index.resize(nbCompressedData); 
    27583045    data_j_index.resize(nbCompressedData); 
    27593046 
    2760     nbCompressedData = 0; 
    2761     for (i = 0; i < nbReceived; ++i) 
     3047    nbCompressedData = 0;   
     3048    for (ind = 0; ind < dataIIndex.numElements(); ++ind) 
    27623049    { 
    2763       CArray<int,1>& tmpI = recvDataIIndex[i];       
    2764       CArray<int,1>& tmpIndex = indGlob_[recvClientRanks_[i]]; 
    2765       for (ind = 0; ind < tmpI.numElements(); ++ind) 
    2766       { 
    2767          indexI = tmpI(ind); 
    2768          index  = tmpIndex(ind); 
    2769          if (0 <= indexI) 
    2770          { 
    2771           data_i_index(nbCompressedData) = index % ni_glo - ibegin; 
    2772           data_j_index(nbCompressedData) = index / ni_glo - jbegin; 
    2773           ++nbCompressedData; 
    2774          }          
    2775       }  
    2776     } 
     3050       indexI = dataIIndex(ind); indexJ = dataJIndex(ind); 
     3051       if ((0 <= indexI) && (0 <= indexJ)) 
     3052       { 
     3053          data_i_index(nbCompressedData) = (1 == data_dim) ? ind : i_index(ind) - i_index(0); 
     3054          data_j_index(nbCompressedData) = (1 == data_dim) ? 0   : j_index(ind) - j_index(0);   
     3055         ++nbCompressedData; 
     3056       } 
     3057    } 
     3058 
     3059    // Reset data_ibegin, data_jbegin 
     3060    data_ibegin.setValue(0); 
     3061    data_jbegin.setValue(0); 
    27773062  } 
    27783063 
Note: See TracChangeset for help on using the changeset viewer.