Ignore:
Timestamp:
01/11/17 15:14:22 (7 years ago)
Author:
mhnguyen
Message:

Merging working version of coupler

+) Add some changes of domain and axis: Retransfer the atttributes in a generic ways for each level of client (or server)
+) Remove some spoiled files from the previous commits

Test
+) No test

File:
1 edited

Legend:

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

    r1009 r1025  
    3131      : CObjectTemplate<CDomain>(), CDomainAttributes() 
    3232      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() 
    33       , hasBounds(false), hasArea(false), isDistributed_(false), nGlobDomain_(), isCompressible_(false), isUnstructed_(false) 
     33      , hasBounds(false), hasArea(false), isDistributed_(false), isCompressible_(false), isUnstructed_(false) 
    3434      , isClientAfterTransformationChecked(false), hasLonLat(false) 
    35       , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client() 
    3635      , isRedistributed_(false), hasPole(false) 
    3736   { 
     
    4140      : CObjectTemplate<CDomain>(id), CDomainAttributes() 
    4241      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() 
    43       , hasBounds(false), hasArea(false), isDistributed_(false), nGlobDomain_(), isCompressible_(false), isUnstructed_(false) 
     42      , hasBounds(false), hasArea(false), isDistributed_(false), isCompressible_(false), isUnstructed_(false) 
    4443      , isClientAfterTransformationChecked(false), hasLonLat(false) 
    45       , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client() 
    4644      , isRedistributed_(false), hasPole(false) 
    4745   { 
     
    113111   { 
    114112     return offsetWrittenIndexes_; 
     113   } 
     114 
     115   /*! 
     116     Returns the start of indexes written by each server. 
     117     \return the start of indexes written by each server 
     118   */ 
     119   const std::vector<int>& CDomain::getStartWriteIndex() const 
     120   { 
     121     return start_write_index_; 
     122   } 
     123 
     124   /*! 
     125     Returns the count of indexes written by each server. 
     126     \return the count of indexes written by each server 
     127   */ 
     128   const std::vector<int>& CDomain::getCountWriteIndex() const 
     129   { 
     130     return count_write_index_; 
     131   } 
     132 
     133   /*! 
     134     Returns the local data written by each server.      
     135   */ 
     136   const std::vector<int>& CDomain::getLocalWriteSize() const 
     137   { 
     138     return local_write_size_; 
     139   } 
     140 
     141   /*! 
     142     Returns the global data written by all server.      
     143   */ 
     144   const std::vector<int>& CDomain::getGlobalWriteSize() const 
     145   { 
     146     return global_write_size_; 
    115147   } 
    116148 
     
    130162     if (client->isServerLeader()) 
    131163     { 
    132        // size estimation for sendServerAttribut 
     164       // size estimation for sendDistributionAttribut 
    133165       size_t size = 11 * sizeof(size_t); 
    134166 
     
    141173     } 
    142174 
    143      std::map<int, std::vector<size_t> >::const_iterator itIndexEnd = indSrv_.end(); 
     175     boost::unordered_map<int, vector<size_t> >::const_iterator itIndexEnd = indSrv_.end(); 
    144176     std::map<int, std::vector<int> >::const_iterator itWrittenIndexEnd = indWrittenSrv_.end(); 
    145177     for (size_t k = 0; k < connectedServerRank_.size(); ++k) 
    146178     { 
    147179       int rank = connectedServerRank_[k]; 
    148        std::map<int, std::vector<size_t> >::const_iterator it = indSrv_.find(rank); 
     180       boost::unordered_map<int, std::vector<size_t> >::const_iterator it = indSrv_.find(rank); 
    149181       size_t idxCount = (it != itIndexEnd) ? it->second.size() : 0; 
    150182 
     
    175207   bool CDomain::isEmpty(void) const 
    176208   { 
    177       return ((this->zoom_ni_srv == 0) || 
    178               (this->zoom_nj_srv == 0)); 
     209      return ((this->zoom_i_index.isEmpty()) || (0 == this->zoom_i_index.numElements())); 
     210      // return ((this->zoom_ni_srv == 0) || 
     211      //         (this->zoom_nj_srv == 0)); 
    179212   } 
    180213 
     
    695728       for (int j = 0; j < nj; ++j) 
    696729         for (int i = 0; i < ni; ++i) j_index(i+j*ni) = j+jbegin; 
    697      } 
    698      computeNGlobDomain(); 
     730     }      
    699731     checkZoom(); 
    700732 
     
    715747     if (global_zoom_nj.isEmpty()) 
    716748      global_zoom_nj.setValue(nj_glo); 
     749    if (zoom_i_index.isEmpty()) zoom_i_index.setValue(i_index.getValue()); 
     750    if (zoom_j_index.isEmpty()) zoom_j_index.setValue(j_index.getValue()); 
    717751   } 
    718752 
     
    9931027     localMask.resize(ni*nj) ; 
    9941028     localMask=false ; 
    995      size_t zoom_ibegin=global_zoom_ibegin ; 
    996      size_t zoom_iend=global_zoom_ibegin+global_zoom_ni-1 ; 
    997      size_t zoom_jbegin=global_zoom_jbegin ; 
    998      size_t zoom_jend=global_zoom_jbegin+global_zoom_nj-1 ; 
     1029     size_t zoom_ibegin= global_zoom_ibegin ; 
     1030     size_t zoom_iend= global_zoom_ibegin+global_zoom_ni-1 ; 
     1031     size_t zoom_jbegin= global_zoom_jbegin ; 
     1032     size_t zoom_jend= global_zoom_jbegin+global_zoom_nj-1 ; 
    9991033 
    10001034 
     
    10371071     if (!lonvalue_2d.isEmpty()) 
    10381072     { 
    1039        lonvalue_client.resize(ni * nj); 
    1040        latvalue_client.resize(ni * nj); 
     1073       lonvalue.resize(ni * nj); 
     1074       latvalue.resize(ni * nj); 
    10411075       if (hasBounds) 
    10421076       { 
    1043          bounds_lon_client.resize(nvertex, ni * nj); 
    1044          bounds_lat_client.resize(nvertex, ni * nj); 
     1077         bounds_lonvalue.resize(nvertex, ni * nj); 
     1078         bounds_latvalue.resize(nvertex, ni * nj); 
    10451079       } 
    10461080 
     
    10511085           int k = j * ni + i; 
    10521086 
    1053            lonvalue_client(k) = lonvalue_2d(i,j); 
    1054            latvalue_client(k) = latvalue_2d(i,j); 
     1087           lonvalue(k) = lonvalue_2d(i,j); 
     1088           latvalue(k) = latvalue_2d(i,j); 
    10551089 
    10561090           if (hasBounds) 
     
    10581092             for (int n = 0; n < nvertex; ++n) 
    10591093             { 
    1060                bounds_lon_client(n,k) = bounds_lon_2d(n,i,j); 
    1061                bounds_lat_client(n,k) = bounds_lat_2d(n,i,j); 
     1094               bounds_lonvalue(n,k) = bounds_lon_2d(n,i,j); 
     1095               bounds_latvalue(n,k) = bounds_lat_2d(n,i,j); 
    10621096             } 
    10631097           } 
     
    10711105         if (ni == lonvalue_1d.numElements() && nj == latvalue_1d.numElements()) 
    10721106         { 
    1073            lonvalue_client.resize(ni * nj); 
    1074            latvalue_client.resize(ni * nj); 
     1107           lonvalue.resize(ni * nj); 
     1108           latvalue.resize(ni * nj); 
    10751109           if (hasBounds) 
    10761110           { 
    1077              bounds_lon_client.resize(nvertex, ni * nj); 
    1078              bounds_lat_client.resize(nvertex, ni * nj); 
     1111             bounds_lonvalue.resize(nvertex, ni * nj); 
     1112             bounds_latvalue.resize(nvertex, ni * nj); 
    10791113           } 
    10801114 
     
    10851119               int k = j * ni + i; 
    10861120 
    1087                lonvalue_client(k) = lonvalue_1d(i); 
    1088                latvalue_client(k) = latvalue_1d(j); 
     1121               lonvalue(k) = lonvalue_1d(i); 
     1122               latvalue(k) = latvalue_1d(j); 
    10891123 
    10901124               if (hasBounds) 
     
    10921126                 for (int n = 0; n < nvertex; ++n) 
    10931127                 { 
    1094                    bounds_lon_client(n,k) = bounds_lon_1d(n,i); 
    1095                    bounds_lat_client(n,k) = bounds_lat_1d(n,j); 
     1128                   bounds_lonvalue(n,k) = bounds_lon_1d(n,i); 
     1129                   bounds_latvalue(n,k) = bounds_lat_1d(n,j); 
    10961130                 } 
    10971131               } 
     
    11011135         else if (i_index.numElements() == lonvalue_1d.numElements() && j_index.numElements() == latvalue_1d.numElements()) 
    11021136         { 
    1103            lonvalue_client.reference(lonvalue_1d); 
    1104            latvalue_client.reference(latvalue_1d); 
     1137           lonvalue.reference(lonvalue_1d); 
     1138           latvalue.reference(latvalue_1d); 
    11051139            if (hasBounds) 
    11061140           { 
    1107              bounds_lon_client.reference(bounds_lon_1d); 
    1108              bounds_lat_client.reference(bounds_lat_1d); 
     1141             bounds_lonvalue.reference(bounds_lon_1d); 
     1142             bounds_latvalue.reference(bounds_lat_1d); 
    11091143           } 
    11101144         } 
     
    11201154       else if (type == type_attr::curvilinear || type == type_attr::unstructured) 
    11211155       { 
    1122          lonvalue_client.reference(lonvalue_1d); 
    1123          latvalue_client.reference(latvalue_1d); 
     1156         lonvalue.reference(lonvalue_1d); 
     1157         latvalue.reference(latvalue_1d); 
    11241158         if (hasBounds) 
    11251159         { 
    1126            bounds_lon_client.reference(bounds_lon_1d); 
    1127            bounds_lat_client.reference(bounds_lat_1d); 
     1160           bounds_lonvalue.reference(bounds_lon_1d); 
     1161           bounds_latvalue.reference(bounds_lat_1d); 
    11281162         } 
    11291163       } 
     
    12211255   void CDomain::checkArea(void) 
    12221256   { 
    1223      hasArea = !area.isEmpty(); 
     1257     hasArea = !area.isEmpty() || !areavalue.isEmpty(); 
    12241258     if (hasArea) 
    12251259     { 
     
    12311265               << "Local size is " << ni.getValue() << " x " << nj.getValue() << "." << std::endl 
    12321266               << "Area size is " << area.extent(0) << " x " << area.extent(1) << "."); 
     1267       } 
     1268       if (areavalue.isEmpty()) 
     1269       { 
     1270          areavalue.resize(ni*nj); 
     1271         for (int j = 0; j < nj; ++j) 
     1272         { 
     1273           for (int i = 0; i < ni; ++i) 
     1274           { 
     1275             int k = j * ni + i; 
     1276             areavalue(k) = area(i,j); 
     1277           } 
     1278         } 
    12331279       } 
    12341280     } 
     
    13021348     if (context->hasClient) 
    13031349     { 
    1304        this->checkMask(); 
    1305        if (hasLonLat || hasArea || isCompressible_) this->computeConnectedServer(); 
     1350       // this->checkMask(); 
     1351      this->computeConnectedClients(); 
     1352       // if (hasLonLat || hasArea || isCompressible_) this->computeConnectedClients(); 
    13061353       if (hasLonLat) this->completeLonLatClient(); 
    13071354     } 
     
    13181365     CContext* context=CContext::getCurrent(); 
    13191366 
     1367      if (context->hasClient && !context->hasServer) 
     1368      { 
     1369        this->checkDomain(); 
     1370        this->checkBounds(); 
     1371        this->checkArea(); 
     1372        this->checkLonLat(); 
     1373      } 
     1374 
     1375      if (context->hasClient && !context->hasServer) 
     1376      { // CÃŽté client uniquement 
     1377         this->checkMask(); 
     1378         this->checkDomainData(); 
     1379         this->checkCompression(); 
     1380         this->computeLocalMask() ; 
     1381      } 
     1382      else 
     1383      { // CÃŽté serveur uniquement 
     1384      } 
     1385 
     1386      this->isClientChecked = true; 
     1387   } 
     1388 
     1389   // Send all checked attributes to server 
     1390   void CDomain::sendCheckedAttributes() 
     1391   { 
     1392     if (!this->isClientChecked) checkAttributesOnClient(); 
     1393     if (!this->isClientAfterTransformationChecked) checkAttributesOnClientAfterTransformation(); 
     1394     CContext* context=CContext::getCurrent() ; 
     1395 
     1396     if (this->isChecked) return; 
     1397     if (context->hasClient) 
     1398     { 
     1399       sendAttributes(); 
     1400     } 
     1401     this->isChecked = true; 
     1402   } 
     1403 
     1404   void CDomain::checkAttributes(void) 
     1405   { 
     1406      if (this->isChecked) return; 
     1407      CContext* context=CContext::getCurrent() ; 
     1408 
    13201409      this->checkDomain(); 
     1410      this->checkLonLat(); 
    13211411      this->checkBounds(); 
    13221412      this->checkArea(); 
    1323       this->checkLonLat(); 
    13241413 
    13251414      if (context->hasClient) 
     
    13291418         this->checkCompression(); 
    13301419         this->computeLocalMask() ; 
     1420 
    13311421      } 
    13321422      else 
     
    13341424      } 
    13351425 
    1336       this->isClientChecked = true; 
    1337    } 
    1338  
    1339    // Send all checked attributes to server 
    1340    void CDomain::sendCheckedAttributes() 
    1341    { 
    1342      if (!this->isClientChecked) checkAttributesOnClient(); 
    1343      if (!this->isClientAfterTransformationChecked) checkAttributesOnClientAfterTransformation(); 
    1344      CContext* context=CContext::getCurrent() ; 
    1345  
    1346      if (this->isChecked) return; 
    1347      if (context->hasClient) 
    1348      { 
    1349        sendServerAttribut(); 
    1350        if (hasLonLat || hasArea || isCompressible_) sendLonLatArea(); 
    1351      } 
    1352      this->isChecked = true; 
    1353    } 
    1354  
    1355    void CDomain::checkAttributes(void) 
    1356    { 
    1357       if (this->isChecked) return; 
    1358       CContext* context=CContext::getCurrent() ; 
    1359  
    1360       this->checkDomain(); 
    1361       this->checkLonLat(); 
    1362       this->checkBounds(); 
    1363       this->checkArea(); 
    1364  
    13651426      if (context->hasClient) 
    1366       { // CÃŽté client uniquement 
    1367          this->checkMask(); 
    1368          this->checkDomainData(); 
    1369          this->checkCompression(); 
    1370          this->computeLocalMask() ; 
    1371  
    1372       } 
    1373       else 
    1374       { // CÃŽté serveur uniquement 
    1375       } 
    1376  
    1377       if (context->hasClient) 
    1378       { 
    1379         this->computeConnectedServer(); 
     1427      { 
     1428        this->computeConnectedClients(); 
    13801429        this->completeLonLatClient(); 
    1381         this->sendServerAttribut(); 
    1382         this->sendLonLatArea(); 
    13831430      } 
    13841431 
     
    13861433   } 
    13871434 
    1388   void CDomain::sendServerAttribut(void) 
     1435  /*! 
     1436    Send distribution from client to other clients 
     1437    Because a client in a level knows correctly the grid distribution of client on the next level 
     1438    it calculates this distribution then sends it to the corresponding clients on the next level 
     1439  */ 
     1440  void CDomain::sendDistributionAttributes(void) 
    13891441  { 
    13901442    CContext* context = CContext::getCurrent(); 
     
    13941446    { 
    13951447       CContextClient* contextClientTmp = (context->hasServer) ? context->clientPrimServer[i] 
    1396                                                                            : context->client; 
    1397       // CContextClient* client = context->client; 
     1448                                                                         : context->client;     
    13981449      int nbServer = contextClientTmp->serverSize; 
    1399  
    1400       CServerDistributionDescription serverDescription(nGlobDomain_, nbServer); 
     1450    std::vector<int> nGlobDomain(2); 
     1451    nGlobDomain[0] = this->ni_glo; 
     1452    nGlobDomain[1] = this->nj_glo; 
     1453 
     1454    CServerDistributionDescription serverDescription(nGlobDomain, nbServer); 
    14011455      if (isUnstructed_) serverDescription.computeServerDistribution(false, 0); 
    14021456      else serverDescription.computeServerDistribution(false, 1); 
     
    14181472          const int ni_srv = serverDimensionSizes[*itRank][0]; 
    14191473          const int nj_srv = serverDimensionSizes[*itRank][1]; 
    1420           const int iend_srv = ibegin_srv + ni_srv - 1; 
    1421           const int jend_srv = jbegin_srv + nj_srv - 1; 
    14221474 
    14231475          msgs.push_back(CMessage()); 
    14241476          CMessage& msg = msgs.back(); 
    14251477          msg << this->getId() ; 
    1426           msg << ni_srv << ibegin_srv << iend_srv << nj_srv << jbegin_srv << jend_srv; 
    1427           msg << global_zoom_ni.getValue() << global_zoom_ibegin.getValue() << global_zoom_nj.getValue() << global_zoom_jbegin.getValue(); 
     1478        msg << ni_srv << ibegin_srv << nj_srv << jbegin_srv;         
    14281479          msg << isCompressible_; 
    14291480 
     
    14361487  } 
    14371488 
    1438   void CDomain::computeNGlobDomain() 
    1439   { 
    1440     nGlobDomain_.resize(2); 
    1441     nGlobDomain_[0] = ni_glo.getValue(); 
    1442     nGlobDomain_[1] = nj_glo.getValue(); 
    1443   } 
    1444  
    1445   void CDomain::computeConnectedServer(void) 
     1489  // void CDomain::computeConnectedClients(const std::vector<int>& globalDim, int orderPositionInGrid, 
     1490  //                                     CServerDistributionDescription::ServerDistributionType distType) 
     1491  /*! 
     1492     Compute the connection of a client to other clients to determine which clients to send attributes to 
     1493  */ 
     1494  void CDomain::computeConnectedClients() 
    14461495  { 
    14471496    CContext* context=CContext::getCurrent() ; 
    1448     CContextClient* client=context->client ; 
     1497    CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 
    14491498    int nbServer=client->serverSize; 
    14501499    int rank = client->clientRank; 
    14511500    bool doComputeGlobalIndexServer = true; 
    14521501 
    1453     int i,j,i_ind,j_ind, nbIndex; 
     1502    int i,j,i_ind,j_ind, nbIndex, nbIndexZoom; 
    14541503    int global_zoom_iend=global_zoom_ibegin+global_zoom_ni-1 ; 
    14551504    int global_zoom_jend=global_zoom_jbegin+global_zoom_nj-1 ; 
     
    14581507    int globalIndexCountZoom = 0; 
    14591508    nbIndex = i_index.numElements(); 
    1460     for (i = 0; i < nbIndex; ++i) 
    1461     { 
    1462       i_ind=i_index(i); 
    1463       j_ind=j_index(i); 
    1464  
    1465       if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
    1466       { 
    1467         ++globalIndexCountZoom; 
    1468       } 
    1469     } 
    1470  
    1471     int globalIndexWrittenCount = 0; 
    1472     if (isCompressible_) 
    1473     { 
    1474       for (i = 0; i < data_i_index.numElements(); ++i) 
    1475       { 
    1476         i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i), 
    1477                                                     data_ibegin, data_jbegin, data_dim, ni, 
    1478                                                     j_ind); 
    1479         if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni)) 
    1480         { 
    1481           i_ind += ibegin; 
    1482           j_ind += jbegin; 
    1483           if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
    1484             ++globalIndexWrittenCount; 
    1485         } 
    1486       } 
    1487     } 
     1509    // for (i = 0; i < nbIndex; ++i) 
     1510    // { 
     1511    //   i_ind=i_index(i); 
     1512    //   j_ind=j_index(i); 
     1513 
     1514    //   if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
     1515    //   { 
     1516    //     ++globalIndexCountZoom; 
     1517    //   } 
     1518    // } 
     1519 
     1520    // int globalIndexWrittenCount = 0; 
     1521    // if (isCompressible_) 
     1522    // { 
     1523    //   for (i = 0; i < data_i_index.numElements(); ++i) 
     1524    //   { 
     1525    //     i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i), 
     1526    //                                                 data_ibegin, data_jbegin, data_dim, ni, 
     1527    //                                                 j_ind); 
     1528    //     if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni)) 
     1529    //     { 
     1530    //       i_ind += ibegin; 
     1531    //       j_ind += jbegin; 
     1532    //       if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
     1533    //         ++globalIndexWrittenCount; 
     1534    //     } 
     1535    //   } 
     1536    // } 
    14881537 
    14891538    // Fill in index 
    1490     CArray<size_t,1> globalIndexDomainZoom(globalIndexCountZoom); 
     1539     
    14911540    CArray<size_t,1> localIndexDomainZoom(globalIndexCountZoom); 
    14921541    CArray<size_t,1> globalIndexDomain(nbIndex); 
    14931542    size_t globalIndex; 
    14941543    int globalIndexCount = 0; 
    1495     globalIndexCountZoom = 0; 
     1544     
    14961545 
    14971546    for (i = 0; i < nbIndex; ++i) 
     
    15011550      globalIndex = i_ind + j_ind * ni_glo; 
    15021551      globalIndexDomain(globalIndexCount) = globalIndex; 
     1552      globalLocalIndexMap_[globalIndex] = i; 
    15031553      ++globalIndexCount; 
    1504       if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
    1505       { 
    1506         globalIndexDomainZoom(globalIndexCountZoom) = globalIndex; 
    1507         localIndexDomainZoom(globalIndexCountZoom) = i; 
    1508         ++globalIndexCountZoom; 
    1509       } 
    1510     } 
    1511  
    1512     CArray<int,1> globalIndexWrittenDomain(globalIndexWrittenCount); 
    1513     if (isCompressible_) 
    1514     { 
    1515       globalIndexWrittenCount = 0; 
    1516       for (i = 0; i < data_i_index.numElements(); ++i) 
    1517       { 
    1518         i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i), 
    1519                                                     data_ibegin, data_jbegin, data_dim, ni, 
    1520                                                     j_ind); 
    1521         if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni)) 
    1522         { 
    1523           i_ind += ibegin; 
    1524           j_ind += jbegin; 
    1525           if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
    1526           { 
    1527             globalIndexWrittenDomain(globalIndexWrittenCount) = i_ind + j_ind * ni_glo; 
    1528             ++globalIndexWrittenCount; 
    1529           } 
    1530         } 
    1531       } 
    1532     } 
     1554    } 
     1555 
     1556    nbIndexZoom = zoom_i_index.numElements(); 
     1557    CArray<size_t,1> globalIndexDomainZoom(nbIndexZoom); 
     1558    globalIndexCountZoom = 0; 
     1559    for (i = 0; i < nbIndexZoom; ++i) 
     1560    { 
     1561      i_ind=zoom_i_index(i); 
     1562      j_ind=zoom_j_index(i); 
     1563      globalIndex = i_ind + j_ind * ni_glo; 
     1564      globalIndexDomainZoom(globalIndexCountZoom) = globalIndex; 
     1565 
     1566      ++globalIndexCountZoom; 
     1567      // if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
     1568      // { 
     1569      //   globalIndexDomainZoom(globalIndexCountZoom) = globalIndex; 
     1570      //   localIndexDomainZoom(globalIndexCountZoom) = i; 
     1571      //   ++globalIndexCountZoom; 
     1572      // } 
     1573    } 
     1574 
     1575    // CArray<int,1> globalIndexWrittenDomain(globalIndexWrittenCount); 
     1576    // if (isCompressible_) 
     1577    // { 
     1578    //   globalIndexWrittenCount = 0; 
     1579    //   for (i = 0; i < data_i_index.numElements(); ++i) 
     1580    //   { 
     1581    //     i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i), 
     1582    //                                                 data_ibegin, data_jbegin, data_dim, ni, 
     1583    //                                                 j_ind); 
     1584    //     if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni)) 
     1585    //     { 
     1586    //       i_ind += ibegin; 
     1587    //       j_ind += jbegin; 
     1588    //       if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 
     1589    //       { 
     1590    //         globalIndexWrittenDomain(globalIndexWrittenCount) = i_ind + j_ind * ni_glo; 
     1591    //         ++globalIndexWrittenCount; 
     1592    //       } 
     1593    //     } 
     1594    //   } 
     1595    // } 
    15331596 
    15341597    size_t globalSizeIndex = 1, indexBegin, indexEnd; 
    15351598    int range, clientSize = client->clientSize; 
    1536     for (int i = 0; i < nGlobDomain_.size(); ++i) globalSizeIndex *= nGlobDomain_[i]; 
     1599    std::vector<int> nGlobDomain(2); 
     1600    nGlobDomain[0] = this->ni_glo; 
     1601    nGlobDomain[1] = this->nj_glo; 
     1602    for (int i = 0; i < nGlobDomain.size(); ++i) globalSizeIndex *= nGlobDomain[i]; 
    15371603    indexBegin = 0; 
    15381604    if (globalSizeIndex <= clientSize) 
     
    15531619    } 
    15541620 
    1555     CServerDistributionDescription serverDescription(nGlobDomain_, nbServer); 
     1621    CServerDistributionDescription serverDescription(nGlobDomain, nbServer); 
    15561622    if (isUnstructed_) serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd), 0); 
    15571623    else serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd), 1); 
     
    15601626                                                                                client->intraComm); 
    15611627    clientServerMap->computeServerIndexMapping(globalIndexDomain); 
    1562     const CClientServerMapping::GlobalIndexMap& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer(); 
     1628    CClientServerMapping::GlobalIndexMap& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer(); 
    15631629 
    15641630    CClientServerMapping::GlobalIndexMap::const_iterator it  = globalIndexDomainOnServer.begin(), 
    15651631                                                         ite = globalIndexDomainOnServer.end(); 
    1566     typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 
    1567     std::vector<int>::iterator itVec; 
    1568  
    1569     indSrv_.clear(); 
    1570     indWrittenSrv_.clear(); 
    1571     for (; it != ite; ++it) 
    1572     { 
    1573       int rank = it->first; 
    1574       int indexSize = it->second.size(); 
    1575       std::vector<int> permutIndex(indexSize); 
    1576       XIOSAlgorithms::fillInIndex(indexSize, permutIndex); 
    1577       XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(it->second, permutIndex); 
    1578       BinarySearch binSearch(it->second); 
    1579       int nb = globalIndexDomainZoom.numElements(); 
    1580       for (int i = 0; i < nb; ++i) 
    1581       { 
    1582         if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexDomainZoom(i), itVec)) 
    1583         { 
    1584           indSrv_[rank].push_back(localIndexDomainZoom(i)); 
    1585         } 
    1586       } 
    1587       for (int i = 0; i < globalIndexWrittenDomain.numElements(); ++i) 
    1588       { 
    1589         if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexWrittenDomain(i), itVec)) 
    1590         { 
    1591           indWrittenSrv_[rank].push_back(globalIndexWrittenDomain(i)); 
    1592         } 
    1593       } 
    1594     } 
     1632    // typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 
     1633    // std::vector<int>::iterator itVec; 
     1634     
     1635    // indSrv_.clear(); 
     1636    // indWrittenSrv_.clear(); 
     1637    // for (; it != ite; ++it) 
     1638    // { 
     1639    //   int rank = it->first; 
     1640    //   int indexSize = it->second.size(); 
     1641    //   std::vector<int> permutIndex(indexSize); 
     1642    //   XIOSAlgorithms::fillInIndex(indexSize, permutIndex); 
     1643    //   XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(it->second, permutIndex); 
     1644    //   BinarySearch binSearch(it->second); 
     1645    //   int nb = globalIndexDomainZoom.numElements(); 
     1646    //   for (int i = 0; i < nb; ++i) 
     1647    //   { 
     1648    //     if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexDomainZoom(i), itVec)) 
     1649    //     { 
     1650    //       indSrv_[rank].push_back(localIndexDomainZoom(i)); 
     1651    //     } 
     1652    //   } 
     1653    //   for (int i = 0; i < globalIndexWrittenDomain.numElements(); ++i) 
     1654    //   { 
     1655    //     if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexWrittenDomain(i), itVec)) 
     1656    //     { 
     1657    //       indWrittenSrv_[rank].push_back(globalIndexWrittenDomain(i)); 
     1658    //     } 
     1659    //   } 
     1660    // } 
    15951661 
    15961662    connectedServerRank_.clear(); 
     
    15991665    } 
    16001666 
     1667    indSrv_.swap(globalIndexDomainOnServer); 
    16011668    nbConnectedClients_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 
    16021669 
     1670    clientServerMap->computeServerIndexMapping(globalIndexDomainZoom); 
     1671    CClientServerMapping::GlobalIndexMap& globalIndexDomainZoomOnServer = clientServerMap->getGlobalIndexOnServer(); 
     1672    indZoomSrv_.swap(globalIndexDomainZoomOnServer); 
     1673    std::vector<int> connectedServerZoomRank(indZoomSrv_.size()); 
     1674    for (it = indZoomSrv_.begin(); it != indZoomSrv_.end(); ++it) 
     1675      connectedServerZoomRank.push_back(it->first); 
     1676    nbConnectedClientsZoom_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerZoomRank);        
     1677 
    16031678    delete clientServerMap; 
    16041679  } 
    16051680 
    1606   const std::map<int, vector<size_t> >& CDomain::getIndexServer() const 
     1681  const boost::unordered_map<int, vector<size_t> >& CDomain::getIndexServer() const 
    16071682  { 
    16081683    return indSrv_; 
     
    16101685 
    16111686  /*! 
    1612     Send index from client to server(s) 
     1687    Send all attributes from client to connected clients 
     1688    The attributes will be rebuilt on receiving side 
     1689  */ 
     1690  void CDomain::sendAttributes() 
     1691  { 
     1692    sendIndex(); 
     1693    sendDistributionAttributes(); 
     1694    sendMask(); 
     1695    sendLonLat(); 
     1696    sendArea();     
     1697    sendDataIndex(); 
     1698  } 
     1699 
     1700  /*! 
     1701    Send global index and zoom index from client to connected client(s) 
     1702    zoom index can be smaller than global index 
    16131703  */ 
    16141704  void CDomain::sendIndex() 
     
    16161706    int ns, n, i, j, ind, nv, idx; 
    16171707    CContext* context = CContext::getCurrent(); 
    1618     CContextClient* client=context->client; 
     1708    CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 
    16191709 
    16201710    CEventClient eventIndex(getType(), EVENT_ID_INDEX); 
    16211711 
    16221712    list<CMessage> list_msgsIndex; 
    1623     list<CArray<int,1> > list_indi, list_indj, list_writtenInd; 
    1624  
    1625     std::map<int, std::vector<size_t> >::const_iterator it, iteMap; 
     1713    list<CArray<int,1> > list_indZoom, list_writtenInd, list_indGlob; 
     1714 
     1715    boost::unordered_map<int, vector<size_t> >::const_iterator itIndex, iteIndex, itZoom, iteZoom; 
     1716    iteIndex = indSrv_.end(); iteZoom = indZoomSrv_.end(); 
     1717    for (int k = 0; k < connectedServerRank_.size(); ++k) 
     1718    { 
     1719      int nbIndGlob = 0; 
     1720      int rank = connectedServerRank_[k]; 
     1721      itIndex = indSrv_.find(rank); 
     1722      if (iteIndex != itIndex) 
     1723        nbIndGlob = itIndex->second.size(); 
     1724      int nbIndZoom = 0; 
     1725      itZoom = indZoomSrv_.find(rank); 
     1726      if (iteZoom != itZoom) 
     1727        nbIndZoom = itZoom->second.size();  
     1728 
     1729      list_indGlob.push_back(CArray<int,1>(nbIndGlob)); 
     1730      list_indZoom.push_back(CArray<int,1>(nbIndZoom)); 
     1731 
     1732      CArray<int,1>& indZoom = list_indZoom.back(); 
     1733      CArray<int,1>& indGlob = list_indGlob.back();       
     1734      for (n = 0; n < nbIndGlob; ++n) 
     1735      { 
     1736        indGlob(n) = static_cast<int>(itIndex->second[n]);         
     1737      } 
     1738 
     1739      for (n = 0; n < nbIndZoom; ++n) 
     1740      { 
     1741        indZoom(n) = static_cast<int>(itZoom->second[n]);         
     1742      } 
     1743 
     1744      list_msgsIndex.push_back(CMessage()); 
     1745      list_msgsIndex.back() << this->getId() << (int)type; // enum ne fonctionne pour les message => ToFix 
     1746      list_msgsIndex.back() << isCurvilinear; 
     1747      list_msgsIndex.back() << list_indGlob.back() << list_indZoom.back(); //list_indi.back() << list_indj.back(); 
     1748 
     1749      // if (isCompressible_) 
     1750      // { 
     1751      //   std::vector<int>& writtenIndSrc = indWrittenSrv_[rank]; 
     1752      //   list_writtenInd.push_back(CArray<int,1>(writtenIndSrc.size())); 
     1753      //   CArray<int,1>& writtenInd = list_writtenInd.back(); 
     1754 
     1755      //   for (n = 0; n < writtenInd.numElements(); ++n) 
     1756      //     writtenInd(n) = writtenIndSrc[n]; 
     1757 
     1758      //   list_msgsIndex.back() << writtenInd; 
     1759      // } 
     1760 
     1761      eventIndex.push(rank, nbConnectedClients_[rank], list_msgsIndex.back()); 
     1762    } 
     1763 
     1764    client->sendEvent(eventIndex); 
     1765  } 
     1766 
     1767  /*! 
     1768    Send mask index from client to connected(s) 
     1769  */ 
     1770  void CDomain::sendMask() 
     1771  { 
     1772    int ns, n, i, j, ind, nv, idx; 
     1773    CContext* context = CContext::getCurrent(); 
     1774    CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 
     1775 
     1776    // send area for each connected server 
     1777    CEventClient eventMask(getType(), EVENT_ID_MASK); 
     1778 
     1779    list<CMessage> list_msgsMask; 
     1780    list<CArray<bool,1> > list_mask; 
     1781 
     1782    boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 
    16261783    iteMap = indSrv_.end(); 
    16271784    for (int k = 0; k < connectedServerRank_.size(); ++k) 
     
    16321789      if (iteMap != it) 
    16331790        nbData = it->second.size(); 
    1634  
    1635       list_indi.push_back(CArray<int,1>(nbData)); 
    1636       list_indj.push_back(CArray<int,1>(nbData)); 
    1637  
    1638       CArray<int,1>& indi = list_indi.back(); 
    1639       CArray<int,1>& indj = list_indj.back(); 
     1791      list_mask.push_back(CArray<bool,1>(nbData)); 
     1792 
    16401793      const std::vector<size_t>& temp = it->second; 
    16411794      for (n = 0; n < nbData; ++n) 
    16421795      { 
    16431796        idx = static_cast<int>(it->second[n]); 
    1644         indi(n) = i_index(idx); 
    1645         indj(n) = j_index(idx); 
    1646       } 
    1647  
    1648       list_msgsIndex.push_back(CMessage()); 
    1649  
    1650       list_msgsIndex.back() << this->getId() << (int)type; // enum ne fonctionne pour les message => ToFix 
    1651       list_msgsIndex.back() << isCurvilinear; 
    1652       list_msgsIndex.back() << list_indi.back() << list_indj.back(); 
    1653  
    1654       if (isCompressible_) 
    1655       { 
    1656         std::vector<int>& writtenIndSrc = indWrittenSrv_[rank]; 
    1657         list_writtenInd.push_back(CArray<int,1>(writtenIndSrc.size())); 
    1658         CArray<int,1>& writtenInd = list_writtenInd.back(); 
    1659  
    1660         for (n = 0; n < writtenInd.numElements(); ++n) 
    1661           writtenInd(n) = writtenIndSrc[n]; 
    1662  
    1663         list_msgsIndex.back() << writtenInd; 
    1664       } 
    1665  
    1666       eventIndex.push(rank, nbConnectedClients_[rank], list_msgsIndex.back()); 
    1667     } 
    1668  
    1669     client->sendEvent(eventIndex); 
     1797        list_mask.back()(n) = mask_1d(globalLocalIndexMap_[idx]);           
     1798      } 
     1799 
     1800      list_msgsMask.push_back(CMessage()); 
     1801      list_msgsMask.back() << this->getId() << list_mask.back(); 
     1802      eventMask.push(rank, nbConnectedClients_[rank], list_msgsMask.back()); 
     1803    } 
     1804    client->sendEvent(eventMask); 
    16701805  } 
    16711806 
    16721807  /*! 
    1673     Send area from client to server(s) 
     1808    Send area from client to connected client(s) 
    16741809  */ 
    16751810  void CDomain::sendArea() 
     
    16791814    int ns, n, i, j, ind, nv, idx; 
    16801815    CContext* context = CContext::getCurrent(); 
    1681     CContextClient* client=context->client; 
     1816    CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 
    16821817 
    16831818    // send area for each connected server 
     
    16871822    list<CArray<double,1> > list_area; 
    16881823 
    1689     std::map<int, std::vector<size_t> >::const_iterator it, iteMap; 
     1824    boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 
    16901825    iteMap = indSrv_.end(); 
    16911826    for (int k = 0; k < connectedServerRank_.size(); ++k) 
     
    17021837      { 
    17031838        idx = static_cast<int>(it->second[n]); 
    1704         i = i_index(idx); 
    1705         j = j_index(idx); 
    1706         if (hasArea) 
    1707           list_area.back()(n) = area(i - ibegin, j - jbegin); 
     1839        list_area.back()(n) = areavalue(globalLocalIndexMap_[idx]);  
    17081840      } 
    17091841 
    17101842      list_msgsArea.push_back(CMessage()); 
    1711       list_msgsArea.back() << this->getId() << list_area.back(); 
     1843      list_msgsArea.back() << this->getId() << hasArea; 
     1844      list_msgsArea.back() << list_area.back(); 
    17121845      eventArea.push(rank, nbConnectedClients_[rank], list_msgsArea.back()); 
    17131846    } 
     
    17261859    int ns, n, i, j, ind, nv, idx; 
    17271860    CContext* context = CContext::getCurrent(); 
    1728     CContextClient* client=context->client; 
     1861    CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 
    17291862 
    17301863    // send lon lat for each connected server 
     
    17361869    list<CArray<double,2> > list_boundslon, list_boundslat; 
    17371870 
    1738     std::map<int, std::vector<size_t> >::const_iterator it, iteMap; 
     1871    boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 
    17391872    iteMap = indSrv_.end(); 
    17401873    for (int k = 0; k < connectedServerRank_.size(); ++k) 
     
    17611894      { 
    17621895        idx = static_cast<int>(it->second[n]); 
    1763         lon(n) = lonvalue_client(idx); 
    1764         lat(n) = latvalue_client(idx); 
     1896        int localInd = globalLocalIndexMap_[idx]; 
     1897        lon(n) = lonvalue(localInd); 
     1898        lat(n) = latvalue(localInd); 
    17651899 
    17661900        if (hasBounds) 
     
    17711905          for (nv = 0; nv < nvertex; ++nv) 
    17721906          { 
    1773             boundslon(nv, n) = bounds_lon_client(nv, idx); 
    1774             boundslat(nv, n) = bounds_lat_client(nv, idx); 
     1907            boundslon(nv, n) = bounds_lonvalue(nv, localInd); 
     1908            boundslat(nv, n) = bounds_latvalue(nv, localInd); 
    17751909          } 
    17761910        } 
     
    17801914      list_msgsLat.push_back(CMessage()); 
    17811915 
    1782       list_msgsLon.back() << this->getId() << list_lon.back(); 
    1783       list_msgsLat.back() << this->getId() << list_lat.back(); 
     1916      list_msgsLon.back() << this->getId() << hasLonLat << list_lon.back() << hasBounds; 
     1917      list_msgsLat.back() << this->getId() << hasLonLat << list_lat.back() << hasBounds; 
    17841918 
    17851919      if (hasBounds) 
     
    17981932 
    17991933  /*! 
    1800     Send some optional information to server(s) 
    1801     In the future, this function can be extended with more optional information to send 
     1934    Send data index to corresponding connected clients. 
     1935    Data index can be compressed however, we always send decompressed data index 
     1936    and they will be compressed on receiving. 
    18021937  */ 
    1803   void CDomain::sendLonLatArea(void) 
    1804   { 
    1805     sendIndex(); 
    1806     sendLonLat(); 
    1807     sendArea(); 
    1808   } 
    1809  
     1938  void CDomain::sendDataIndex() 
     1939  { 
     1940    int ns, n, i, j, ind, nv, idx; 
     1941    CContext* context = CContext::getCurrent(); 
     1942    CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 
     1943 
     1944    // send area for each connected server 
     1945    CEventClient eventDataIndex(getType(), EVENT_ID_DATA_INDEX); 
     1946 
     1947    list<CMessage> list_msgsDataIndex; 
     1948    list<CArray<int,1> > list_data_i_index, list_data_j_index; 
     1949 
     1950    int nbIndex = i_index.numElements(); 
     1951    CArray<int,1> dataIIndex(nbIndex), dataJIndex(nbIndex); 
     1952    dataIIndex = -1; dataJIndex = -1, ind = 0; 
     1953    for (idx = 0; idx < data_i_index.numElements(); ++idx) 
     1954    { 
     1955      if ((0 <= data_i_index(idx)) && (data_i_index(idx) < ni) && (ind < nbIndex)) 
     1956      { 
     1957        dataIIndex(ind) = data_i_index(idx); 
     1958        dataJIndex(ind) = data_j_index(idx); 
     1959        ++ind; 
     1960      } 
     1961    } 
     1962 
     1963    boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 
     1964    iteMap = indSrv_.end(); 
     1965    for (int k = 0; k < connectedServerRank_.size(); ++k) 
     1966    { 
     1967      int nbData = 0; 
     1968      int rank = connectedServerRank_[k]; 
     1969      it = indSrv_.find(rank); 
     1970      if (iteMap != it) 
     1971        nbData = it->second.size(); 
     1972      list_data_i_index.push_back(CArray<int,1>(nbData)); 
     1973      list_data_j_index.push_back(CArray<int,1>(nbData)); 
     1974 
     1975      const std::vector<size_t>& temp = it->second; 
     1976      for (n = 0; n < nbData; ++n) 
     1977      { 
     1978        idx = static_cast<int>(it->second[n]); 
     1979        i = globalLocalIndexMap_[idx]; 
     1980        list_data_i_index.back()(n) = dataIIndex(i); 
     1981        list_data_j_index.back()(n) = dataJIndex(i);           
     1982      } 
     1983 
     1984      list_msgsDataIndex.push_back(CMessage()); 
     1985      list_msgsDataIndex.back() << this->getId(); 
     1986      list_msgsDataIndex.back() << list_data_i_index.back() << list_data_j_index.back(); 
     1987      eventDataIndex.push(rank, nbConnectedClients_[rank], list_msgsDataIndex.back()); 
     1988    } 
     1989    client->sendEvent(eventDataIndex); 
     1990  } 
     1991   
    18101992  bool CDomain::dispatchEvent(CEventServer& event) 
    18111993  { 
     
    18161998      { 
    18171999        case EVENT_ID_SERVER_ATTRIBUT: 
    1818           recvServerAttribut(event); 
     2000          recvDistributionAttributes(event); 
    18192001          return true; 
    18202002          break; 
    18212003        case EVENT_ID_INDEX: 
    18222004          recvIndex(event); 
     2005          return true; 
     2006          break; 
     2007        case EVENT_ID_MASK: 
     2008          recvMask(event); 
    18232009          return true; 
    18242010          break; 
     
    18342020          recvArea(event); 
    18352021          return true; 
     2022          break;   
     2023        case EVENT_ID_DATA_INDEX: 
     2024          recvDataIndex(event); 
     2025          return true; 
    18362026          break; 
    18372027        default: 
     
    18472037    \param[in] event event contain info about rank and associated attributes 
    18482038  */ 
    1849   void CDomain::recvServerAttribut(CEventServer& event) 
     2039  void CDomain::recvDistributionAttributes(CEventServer& event) 
    18502040  { 
    18512041    CBufferIn* buffer=event.subEvents.begin()->buffer; 
    18522042    string domainId ; 
    18532043    *buffer>>domainId ; 
    1854     get(domainId)->recvServerAttribut(*buffer) ; 
    1855      
    1856     CContext* context = CContext::getCurrent(); 
    1857     if (context->hasClient && context->hasServer) 
    1858     { 
    1859       get(domainId)->sendServerAttribut(); 
    1860     } 
    1861  
     2044    get(domainId)->recvDistributionAttributes(*buffer) ; 
    18622045  } 
    18632046 
     
    18672050    \param[in] buffer message containing attributes info 
    18682051  */ 
    1869   void CDomain::recvServerAttribut(CBufferIn& buffer) 
    1870   { 
    1871     int global_zoom_ni_tmp, global_zoom_ibegin_tmp, global_zoom_nj_tmp, global_zoom_jbegin_tmp; 
    1872     buffer >> ni_srv >> ibegin_srv >> iend_srv >> nj_srv >> jbegin_srv >> jend_srv 
    1873            >> global_zoom_ni_tmp >> global_zoom_ibegin_tmp >> global_zoom_nj_tmp >> global_zoom_jbegin_tmp 
     2052  void CDomain::recvDistributionAttributes(CBufferIn& buffer) 
     2053  { 
     2054    int ni_tmp, ibegin_tmp, nj_tmp, jbegin_tmp; 
     2055    buffer >> ni_tmp >> ibegin_tmp >> nj_tmp >> jbegin_tmp            
    18742056           >> isCompressible_; 
    1875  
    1876     global_zoom_ni.setValue(global_zoom_ni_tmp); 
    1877     global_zoom_ibegin.setValue(global_zoom_ibegin_tmp); 
    1878     global_zoom_nj.setValue(global_zoom_nj_tmp); 
    1879     global_zoom_jbegin.setValue(global_zoom_jbegin_tmp); 
    1880  
    1881     int zoom_iend = global_zoom_ibegin + global_zoom_ni - 1; 
    1882     int zoom_jend = global_zoom_jbegin + global_zoom_nj - 1; 
    1883  
    1884     zoom_ibegin_srv = global_zoom_ibegin > ibegin_srv ? global_zoom_ibegin : ibegin_srv ; 
    1885     zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 
    1886     zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 
    1887  
    1888     zoom_jbegin_srv = global_zoom_jbegin > jbegin_srv ? global_zoom_jbegin : jbegin_srv ; 
    1889     zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 
    1890     zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 
    1891  
    1892     if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 
    1893     { 
    1894       zoom_ibegin_srv=0 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; 
    1895       zoom_jbegin_srv=0 ; zoom_jend_srv=0 ; zoom_nj_srv=0 ; 
    1896     } 
    1897     lonvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 
    1898     lonvalue_srv = 0. ; 
    1899     latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 
    1900     latvalue_srv = 0. ; 
    1901     if (hasBounds) 
    1902     { 
    1903       bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; 
    1904       bounds_lon_srv = 0. ; 
    1905       bounds_lat_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; 
    1906       bounds_lat_srv = 0. ; 
    1907     } 
    1908  
    1909     if (hasArea) 
    1910     { 
    1911       area_srv.resize(zoom_ni_srv * zoom_nj_srv); 
    1912       area_srv = 0.; 
    1913     } 
    1914  
     2057    ni.setValue(ni_tmp); 
     2058    ibegin.setValue(ibegin_tmp); 
     2059    nj.setValue(nj_tmp); 
     2060    jbegin.setValue(jbegin_tmp); 
    19152061  } 
    19162062 
     
    19212067  void CDomain::recvIndex(CEventServer& event) 
    19222068  { 
    1923     CDomain* domain; 
     2069    string domainId; 
     2070    std::map<int, CBufferIn*> rankBuffers; 
    19242071 
    19252072    list<CEventServer::SSubEvent>::iterator it; 
    19262073    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
    1927     { 
     2074    {       
    19282075      CBufferIn* buffer = it->buffer; 
    1929       string domainId; 
    19302076      *buffer >> domainId; 
    1931       domain = get(domainId); 
    1932       domain->recvIndex(it->rank, *buffer); 
    1933     } 
    1934  
    1935     if (domain->isCompressible_) 
    1936     { 
    1937       std::sort(domain->indexesToWrite.begin(), domain->indexesToWrite.end()); 
    1938  
    1939       CContextServer* server = CContext::getCurrent()->server; 
    1940       domain->numberWrittenIndexes_ = domain->indexesToWrite.size(); 
    1941       MPI_Allreduce(&domain->numberWrittenIndexes_, &domain->totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
    1942       MPI_Scan(&domain->numberWrittenIndexes_, &domain->offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
    1943       domain->offsetWrittenIndexes_ -= domain->numberWrittenIndexes_; 
    1944     } 
     2077      rankBuffers[it->rank] = buffer;         
     2078    } 
     2079    get(domainId)->recvIndex(rankBuffers); 
     2080 
     2081    // if (domain->isCompressible_) 
     2082    // { 
     2083    //   std::sort(domain->indexesToWrite.begin(), domain->indexesToWrite.end()); 
     2084 
     2085    //   CContextServer* server = CContext::getCurrent()->server; 
     2086    //   domain->numberWrittenIndexes_ = domain->indexesToWrite.size(); 
     2087    //   MPI_Allreduce(&domain->numberWrittenIndexes_, &domain->totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
     2088    //   MPI_Scan(&domain->numberWrittenIndexes_, &domain->offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
     2089    //   domain->offsetWrittenIndexes_ -= domain->numberWrittenIndexes_; 
     2090    // } 
    19452091  } 
    19462092 
    19472093  /*! 
    19482094    Receive index information from client(s) 
    1949     \param[in] rank rank of client source 
    1950     \param[in] buffer message containing index info 
     2095    \param[in] rankBuffers rank of sending client and the corresponding receive buffer   
    19512096  */ 
    1952   void CDomain::recvIndex(int rank, CBufferIn& buffer) 
    1953   { 
    1954     int type_int; 
    1955     buffer >> type_int >> isCurvilinear >> indiSrv[rank] >> indjSrv[rank]; 
    1956     type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix 
    1957  
    1958     if (isCompressible_) 
    1959     { 
    1960       CArray<int, 1> writtenIndexes; 
    1961       buffer >> writtenIndexes; 
    1962       indexesToWrite.reserve(indexesToWrite.size() + writtenIndexes.numElements()); 
    1963       for (int i = 0; i < writtenIndexes.numElements(); ++i) 
    1964         indexesToWrite.push_back(writtenIndexes(i)); 
    1965     } 
     2097  void CDomain::recvIndex(std::map<int, CBufferIn*>& rankBuffers) 
     2098  { 
     2099    int nbReceived = rankBuffers.size(), i, ind, index, type_int; 
     2100    recvClientRanks_.resize(nbReceived); 
     2101    vector<CArray<int,1> > recvZoomInd(nbReceived); 
     2102 
     2103    std::map<int, CBufferIn*>::iterator it = rankBuffers.begin(), ite = rankBuffers.end(); 
     2104    ind = 0; 
     2105    for (ind = 0; it != ite; ++it, ++ind) 
     2106    {        
     2107       recvClientRanks_[ind] = it->first; 
     2108       CBufferIn& buffer = *(it->second); 
     2109       buffer >> type_int >> isCurvilinear >> indGlob_[it->first] >> recvZoomInd[ind]; //recvIndGlob[ind]; 
     2110       type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix 
     2111    } 
     2112    int nbIndGlob = 0; 
     2113    for (i = 0; i < nbReceived; ++i) 
     2114    { 
     2115      nbIndGlob += indGlob_[recvClientRanks_[i]].numElements(); 
     2116    } 
     2117     
     2118    i_index.resize(nbIndGlob); 
     2119    j_index.resize(nbIndGlob); 
     2120 
     2121    nbIndGlob = 0; 
     2122    for (i = 0; i < nbReceived; ++i) 
     2123    { 
     2124      CArray<int,1>& tmp = indGlob_[recvClientRanks_[i]]; 
     2125      for (ind = 0; ind < tmp.numElements(); ++ind) 
     2126      { 
     2127         index = tmp(ind); 
     2128         i_index(nbIndGlob) = index / ni_glo; 
     2129         j_index(nbIndGlob) = index % ni_glo; 
     2130         ++nbIndGlob; 
     2131      }  
     2132    } 
     2133 
     2134    int nbZoomInd = 0; 
     2135    for (i = 0; i < nbReceived; ++i) 
     2136    { 
     2137      nbZoomInd += recvZoomInd[i].numElements(); 
     2138    } 
     2139 
     2140    zoom_i_index.resize(nbZoomInd); 
     2141    zoom_j_index.resize(nbZoomInd); 
     2142     
     2143    nbZoomInd = 0; 
     2144    for (i = 0; i < nbReceived; ++i) 
     2145    { 
     2146      CArray<int,1>& tmp = recvZoomInd[i]; 
     2147      for (ind = 0; ind < tmp.numElements(); ++ind) 
     2148      { 
     2149         index = tmp(ind); 
     2150         zoom_i_index(nbZoomInd) = index / ni_glo; 
     2151         zoom_j_index(nbZoomInd) = index % ni_glo; 
     2152         ++nbZoomInd; 
     2153      }  
     2154    }     
     2155 
     2156    { 
     2157      CContextServer* server = CContext::getCurrent()->server; 
     2158      count_write_index_.resize(2); 
     2159      start_write_index_.resize(2); 
     2160      local_write_size_.resize(2); 
     2161      global_write_size_.resize(2); 
     2162      if ((this->type) == CDomain::type_attr::unstructured) 
     2163      { 
     2164        count_write_index_[0] = zoom_i_index.numElements(); 
     2165        count_write_index_[1] = 0; 
     2166      } 
     2167      else 
     2168      { 
     2169        int ni_zoom = zoom_i_index.numElements(), idx, nbIZoom = 0, nbJZoom = 0; 
     2170        for (idx =0; idx < ni_zoom; ++idx) 
     2171        { 
     2172           if ((ibegin <= zoom_i_index(idx)) && (zoom_i_index(idx) < ibegin+ni) && (nbIZoom < ni)) 
     2173            ++nbIZoom; 
     2174           if ((jbegin <= zoom_j_index(idx)) && (zoom_j_index(idx) < jbegin+nj) && (nbJZoom < nj)) 
     2175            ++nbJZoom; 
     2176        } 
     2177        count_write_index_[0] = nbIZoom; 
     2178        count_write_index_[1] = nbJZoom; 
     2179      } 
     2180             
     2181      MPI_Scan(&count_write_index_[0], &start_write_index_[0], 2, MPI_INT, MPI_SUM, server->intraComm);       
     2182      start_write_index_[0] = 0;  
     2183      start_write_index_[1] -= count_write_index_[1]; 
     2184      local_write_size_[0] = count_write_index_[0]; 
     2185      local_write_size_[1] = count_write_index_[1]; 
     2186      MPI_Allreduce(&count_write_index_[0], &global_write_size_[0], 2, MPI_INT, MPI_SUM, server->intraComm); 
     2187      global_write_size_[0] = count_write_index_[0]; 
     2188      global_write_size_[1] = (global_write_size_[1] > nj_glo) ? nj_glo : global_write_size_[1]; 
     2189          
     2190    } 
     2191 
     2192    // int type_int; 
     2193    // buffer >> type_int >> isCurvilinear >> indiSrv[rank] >> indjSrv[rank]; 
     2194    // type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix 
     2195 
     2196    // if (isCompressible_) 
     2197    // { 
     2198    //   CArray<int, 1> writtenIndexes; 
     2199    //   buffer >> writtenIndexes; 
     2200    //   indexesToWrite.reserve(indexesToWrite.size() + writtenIndexes.numElements()); 
     2201    //   for (int i = 0; i < writtenIndexes.numElements(); ++i) 
     2202    //     indexesToWrite.push_back(writtenIndexes(i)); 
     2203    // } 
     2204  } 
     2205 
     2206  /*! 
     2207    Receive area event from clients(s) 
     2208    \param[in] event event contain info about rank and associated area 
     2209  */ 
     2210  void CDomain::recvMask(CEventServer& event) 
     2211  { 
     2212    string domainId; 
     2213    std::map<int, CBufferIn*> rankBuffers; 
     2214 
     2215    list<CEventServer::SSubEvent>::iterator it; 
     2216    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
     2217    {       
     2218      CBufferIn* buffer = it->buffer; 
     2219      *buffer >> domainId; 
     2220      rankBuffers[it->rank] = buffer;      
     2221    } 
     2222    get(domainId)->recvMask(rankBuffers); 
     2223  } 
     2224 
     2225 
     2226  /*! 
     2227    Receive mask information from client(s) 
     2228    \param[in] rankBuffers rank of sending client and the corresponding receive buffer   
     2229  */ 
     2230  void CDomain::recvMask(std::map<int, CBufferIn*>& rankBuffers) 
     2231  { 
     2232    int nbReceived = rankBuffers.size(), i, ind, index; 
     2233    if (nbReceived != recvClientRanks_.size()) 
     2234      ERROR("void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers)", 
     2235           << "The number of sending clients is not correct." 
     2236           << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 
     2237 
     2238    vector<CArray<bool,1> > recvMaskValue(nbReceived);       
     2239    for (i = 0; i < recvClientRanks_.size(); ++i) 
     2240    { 
     2241      int rank = recvClientRanks_[i]; 
     2242      CBufferIn& buffer = *(rankBuffers[rank]);       
     2243      buffer >> recvMaskValue[i]; 
     2244    } 
     2245 
     2246    int nbMaskInd = 0; 
     2247    for (i = 0; i < nbReceived; ++i) 
     2248    { 
     2249      nbMaskInd += recvMaskValue[i].numElements(); 
     2250    } 
     2251   
     2252    mask_1d.resize(nbMaskInd); 
     2253    nbMaskInd = 0; 
     2254    for (i = 0; i < nbReceived; ++i) 
     2255    { 
     2256      CArray<bool,1>& tmp = recvMaskValue[i]; 
     2257      for (ind = 0; ind < tmp.numElements(); ++ind) 
     2258      { 
     2259        mask_1d(nbMaskInd) = tmp(ind);       
     2260        ++nbMaskInd; 
     2261      } 
     2262    }     
    19662263  } 
    19672264 
     
    19722269  void CDomain::recvLon(CEventServer& event) 
    19732270  { 
     2271    string domainId; 
     2272    std::map<int, CBufferIn*> rankBuffers; 
     2273 
    19742274    list<CEventServer::SSubEvent>::iterator it; 
    19752275    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
    1976     { 
     2276    {       
    19772277      CBufferIn* buffer = it->buffer; 
    1978       string domainId; 
    19792278      *buffer >> domainId; 
    1980       get(domainId)->recvLon(it->rank, *buffer); 
    1981     } 
     2279      rankBuffers[it->rank] = buffer;         
     2280    } 
     2281    get(domainId)->recvLon(rankBuffers); 
    19822282  } 
    19832283 
    19842284  /*! 
    19852285    Receive longitude information from client(s) 
    1986     \param[in] rank rank of client source 
    1987     \param[in] buffer message containing longitude info 
     2286    \param[in] rankBuffers rank of sending client and the corresponding receive buffer   
    19882287  */ 
    1989   void CDomain::recvLon(int rank, CBufferIn& buffer) 
    1990   { 
    1991     CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; 
    1992     CArray<double,1> lon; 
    1993     CArray<double,2> boundslon; 
    1994  
    1995     buffer >> lon; 
    1996  
    1997     if (hasBounds) buffer >> boundslon; 
    1998  
    1999     int i, j, ind_srv; 
    2000     for (int ind = 0; ind < indi.numElements(); ind++) 
    2001     { 
    2002       i = indi(ind); j = indj(ind); 
    2003       ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; 
    2004       lonvalue_srv(ind_srv) = lon(ind); 
     2288  void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers) 
     2289  { 
     2290    int nbReceived = rankBuffers.size(), i, ind, index; 
     2291    if (nbReceived != recvClientRanks_.size()) 
     2292      ERROR("void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers)", 
     2293           << "The number of sending clients is not correct." 
     2294           << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 
     2295 
     2296    vector<CArray<double,1> > recvLonValue(nbReceived); 
     2297    vector<CArray<double,2> > recvBoundsLonValue(nbReceived);     
     2298    for (i = 0; i < recvClientRanks_.size(); ++i) 
     2299    { 
     2300      int rank = recvClientRanks_[i]; 
     2301      CBufferIn& buffer = *(rankBuffers[rank]); 
     2302      buffer >> hasLonLat; 
     2303      buffer >> recvLonValue[i]; 
     2304      buffer >> hasBounds; 
    20052305      if (hasBounds) 
    2006       { 
    2007         for (int nv = 0; nv < nvertex; ++nv) 
    2008           bounds_lon_srv(nv, ind_srv) = boundslon(nv, ind); 
     2306        buffer >> recvBoundsLonValue[i]; 
     2307    } 
     2308 
     2309    int nbLonInd = 0; 
     2310    for (i = 0; i < nbReceived; ++i) 
     2311    { 
     2312      nbLonInd += recvLonValue[i].numElements(); 
     2313    } 
     2314 
     2315    lonvalue.resize(nbLonInd); 
     2316    if (hasBounds) 
     2317    { 
     2318      bounds_lonvalue.resize(nvertex, nbLonInd); 
     2319    } 
     2320 
     2321    nbLonInd = 0; 
     2322    for (i = 0; i < nbReceived; ++i) 
     2323    { 
     2324      CArray<double,1>& tmp = recvLonValue[i]; 
     2325      for (ind = 0; ind < tmp.numElements(); ++ind) 
     2326      { 
     2327         lonvalue(nbLonInd) = tmp(ind); 
     2328         if (hasBounds) 
     2329         { 
     2330          CArray<double,2>& tmpBnds = recvBoundsLonValue[i]; 
     2331          for (int nv = 0; nv < nvertex; ++nv) 
     2332            bounds_lonvalue(nv, nbLonInd) = tmpBnds(nv, ind); 
     2333         }        
     2334         ++nbLonInd; 
    20092335      } 
    20102336    } 
     
    20172343  void CDomain::recvLat(CEventServer& event) 
    20182344  { 
     2345    string domainId; 
     2346    std::map<int, CBufferIn*> rankBuffers; 
     2347 
    20192348    list<CEventServer::SSubEvent>::iterator it; 
    20202349    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
    2021     { 
     2350    {       
    20222351      CBufferIn* buffer = it->buffer; 
    2023       string domainId; 
    20242352      *buffer >> domainId; 
    2025       get(domainId)->recvLat(it->rank, *buffer); 
    2026     } 
     2353      rankBuffers[it->rank] = buffer;     
     2354    } 
     2355    get(domainId)->recvLat(rankBuffers); 
    20272356  } 
    20282357 
    20292358  /*! 
    20302359    Receive latitude information from client(s) 
    2031     \param[in] rank rank of client source 
    2032     \param[in] buffer message containing latitude info 
     2360    \param[in] rankBuffers rank of sending client and the corresponding receive buffer   
    20332361  */ 
    2034   void CDomain::recvLat(int rank, CBufferIn& buffer) 
    2035   { 
    2036     CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; 
    2037     CArray<double,1> lat; 
    2038     CArray<double,2> boundslat; 
    2039  
    2040     buffer >> lat; 
    2041     if (hasBounds) buffer >> boundslat; 
    2042  
    2043     int i, j, ind_srv; 
    2044     for (int ind = 0; ind < indi.numElements(); ind++) 
    2045     { 
    2046       i = indi(ind); j = indj(ind); 
    2047       ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; 
    2048       latvalue_srv(ind_srv) = lat(ind); 
     2362  void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers) 
     2363  { 
     2364    int nbReceived = rankBuffers.size(), i, ind, index; 
     2365    if (nbReceived != recvClientRanks_.size()) 
     2366      ERROR("void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)", 
     2367           << "The number of sending clients is not correct." 
     2368           << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 
     2369 
     2370    vector<CArray<double,1> > recvLatValue(nbReceived); 
     2371    vector<CArray<double,2> > recvBoundsLatValue(nbReceived);     
     2372    for (i = 0; i < recvClientRanks_.size(); ++i) 
     2373    { 
     2374      int rank = recvClientRanks_[i]; 
     2375      CBufferIn& buffer = *(rankBuffers[rank]); 
     2376      buffer >> hasLonLat; 
     2377      buffer >> recvLatValue[i]; 
     2378      buffer >> hasBounds; 
    20492379      if (hasBounds) 
    2050       { 
    2051         for (int nv = 0; nv < nvertex; nv++) 
    2052           bounds_lat_srv(nv, ind_srv) = boundslat(nv, ind); 
     2380        buffer >> recvBoundsLatValue[i]; 
     2381    } 
     2382 
     2383    int nbLatInd = 0; 
     2384    for (i = 0; i < nbReceived; ++i) 
     2385    { 
     2386      nbLatInd += recvLatValue[i].numElements(); 
     2387    } 
     2388 
     2389    latvalue.resize(nbLatInd); 
     2390    if (hasBounds) 
     2391    { 
     2392      bounds_latvalue.resize(nvertex, nbLatInd); 
     2393    } 
     2394     
     2395    nbLatInd = 0; 
     2396    for (i = 0; i < nbReceived; ++i) 
     2397    { 
     2398      CArray<double,1>& tmp = recvLatValue[i]; 
     2399      for (ind = 0; ind < tmp.numElements(); ++ind) 
     2400      {          
     2401         latvalue(nbLatInd) = tmp(ind); 
     2402         if (hasBounds) 
     2403         { 
     2404          CArray<double,2>& tmpBnds = recvBoundsLatValue[i]; 
     2405          for (int nv = 0; nv < nvertex; ++nv) 
     2406            bounds_latvalue(nv, nbLatInd) = tmpBnds(nv, ind); 
     2407         }        
     2408         ++nbLatInd; 
    20532409      } 
    20542410    } 
     
    20612417  void CDomain::recvArea(CEventServer& event) 
    20622418  { 
     2419    string domainId; 
     2420    std::map<int, CBufferIn*> rankBuffers; 
     2421 
    20632422    list<CEventServer::SSubEvent>::iterator it; 
    20642423    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
    2065     { 
     2424    {       
    20662425      CBufferIn* buffer = it->buffer; 
    2067       string domainId; 
    20682426      *buffer >> domainId; 
    2069       get(domainId)->recvArea(it->rank, *buffer); 
    2070     } 
    2071   } 
     2427      rankBuffers[it->rank] = buffer;      
     2428    } 
     2429    get(domainId)->recvArea(rankBuffers); 
     2430  } 
     2431 
    20722432 
    20732433  /*! 
    20742434    Receive area information from client(s) 
    2075     \param[in] rank rank of client source 
    2076     \param[in] buffer message containing area info 
     2435    \param[in] rankBuffers rank of sending client and the corresponding receive buffer      
    20772436  */ 
    2078   void CDomain::recvArea(int rank, CBufferIn& buffer) 
    2079   { 
    2080     CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; 
    2081     CArray<double,1> clientArea; 
    2082  
    2083     buffer >> clientArea; 
    2084  
    2085     int i, j, ind_srv; 
    2086     for (int ind = 0; ind < indi.numElements(); ind++) 
    2087     { 
    2088       i = indi(ind); j = indj(ind); 
    2089       ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; 
    2090       area_srv(ind_srv) = clientArea(ind); 
     2437  void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers) 
     2438  { 
     2439    int nbReceived = rankBuffers.size(), i, ind, index; 
     2440    if (nbReceived != recvClientRanks_.size()) 
     2441      ERROR("void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers)", 
     2442           << "The number of sending clients is not correct." 
     2443           << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 
     2444 
     2445    vector<CArray<double,1> > recvAreaValue(nbReceived);       
     2446    for (i = 0; i < recvClientRanks_.size(); ++i) 
     2447    { 
     2448      int rank = recvClientRanks_[i]; 
     2449      CBufferIn& buffer = *(rankBuffers[rank]);       
     2450      buffer >> hasArea; 
     2451      if (hasArea) 
     2452        buffer >> recvAreaValue[i]; 
     2453    } 
     2454 
     2455    int nbAreaInd = 0; 
     2456    for (i = 0; i < nbReceived; ++i) 
     2457    { 
     2458      if (hasArea) 
     2459        nbAreaInd += recvAreaValue[i].numElements(); 
     2460    } 
     2461   
     2462    areavalue.resize(nbAreaInd); 
     2463    nbAreaInd = 0; 
     2464    if (hasArea) 
     2465    { 
     2466      for (i = 0; i < nbReceived; ++i) 
     2467      { 
     2468        CArray<double,1>& tmp = recvAreaValue[i]; 
     2469        for (ind = 0; ind < tmp.numElements(); ++ind) 
     2470        { 
     2471          area(nbAreaInd) = tmp(ind);       
     2472          ++nbAreaInd; 
     2473        } 
     2474      } 
     2475    } 
     2476  } 
     2477 
     2478  /*! 
     2479    Receive data index event from clients(s) 
     2480    \param[in] event event contain info about rank and associated index 
     2481  */ 
     2482  void CDomain::recvDataIndex(CEventServer& event) 
     2483  { 
     2484    string domainId; 
     2485    std::map<int, CBufferIn*> rankBuffers; 
     2486 
     2487    list<CEventServer::SSubEvent>::iterator it; 
     2488    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
     2489    {       
     2490      CBufferIn* buffer = it->buffer; 
     2491      *buffer >> domainId; 
     2492      rankBuffers[it->rank] = buffer;         
     2493    } 
     2494    get(domainId)->recvDataIndex(rankBuffers); 
     2495 
     2496    // if (domain->isCompressible_) 
     2497    // { 
     2498    //   std::sort(domain->indexesToWrite.begin(), domain->indexesToWrite.end()); 
     2499 
     2500    //   CContextServer* server = CContext::getCurrent()->server; 
     2501    //   domain->numberWrittenIndexes_ = domain->indexesToWrite.size(); 
     2502    //   MPI_Allreduce(&domain->numberWrittenIndexes_, &domain->totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
     2503    //   MPI_Scan(&domain->numberWrittenIndexes_, &domain->offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
     2504    //   domain->offsetWrittenIndexes_ -= domain->numberWrittenIndexes_; 
     2505    // } 
     2506  } 
     2507 
     2508  /*! 
     2509    Receive data index information from client(s) 
     2510    A client receives data index from different clients to rebuild its own data index. 
     2511    Because the data index is local, to rebuild data index of received client, we should use global index along with.  
     2512    \param[in] rankBuffers rank of sending client and the corresponding receive buffer      
     2513  */ 
     2514  void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers) 
     2515  { 
     2516    int nbReceived = rankBuffers.size(), i, ind, index, indexI, type_int;     
     2517    if (nbReceived != recvClientRanks_.size()) 
     2518      ERROR("void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)", 
     2519           << "The number of sending clients is not correct." 
     2520           << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 
     2521 
     2522    vector<CArray<int,1> > recvDataIIndex(nbReceived),recvDataJIndex(nbReceived);      
     2523    for (i = 0; i < recvClientRanks_.size(); ++i) 
     2524    { 
     2525      int rank = recvClientRanks_[i]; 
     2526      CBufferIn& buffer = *(rankBuffers[rank]); 
     2527      buffer >> recvDataIIndex[i]; 
     2528      buffer >> recvDataJIndex[i]; 
     2529    } 
     2530    
     2531    int nbCompressedData = 0;  
     2532    for (i = 0; i < nbReceived; ++i) 
     2533    { 
     2534      CArray<int,1>& tmp = recvDataIIndex[i]; 
     2535      for (ind = 0; ind < tmp.numElements(); ++ind) 
     2536      { 
     2537         index = tmp(ind); 
     2538         if (0 <= index) 
     2539           ++nbCompressedData; 
     2540      }         
     2541    } 
     2542 
     2543    data_i_index.resize(nbCompressedData); 
     2544    data_j_index.resize(nbCompressedData); 
     2545 
     2546    nbCompressedData = 0; 
     2547    for (i = 0; i < nbReceived; ++i) 
     2548    { 
     2549      CArray<int,1>& tmpI = recvDataIIndex[i];       
     2550      CArray<int,1>& tmpIndex = indGlob_[recvClientRanks_[i]]; 
     2551      for (ind = 0; ind < tmpI.numElements(); ++ind) 
     2552      { 
     2553         indexI = tmpI(ind); 
     2554         index  = tmpIndex(ind); 
     2555         if (0 <= indexI) 
     2556         { 
     2557          data_i_index(nbCompressedData) = index % ni_glo - ibegin; 
     2558          data_j_index(nbCompressedData) = index / ni_glo - jbegin; 
     2559          ++nbCompressedData; 
     2560         }          
     2561      }  
    20912562    } 
    20922563  } 
     
    21232594  { 
    21242595    return transformationMap_; 
    2125   } 
    2126  
    2127   /*! 
    2128     Check the validity of all transformations applied on domain 
    2129   This functions is called AFTER all inherited attributes are solved 
    2130   */ 
    2131   void CDomain::checkTransformations() 
    2132   { 
    2133     TransMapTypes::const_iterator itb = transformationMap_.begin(), it, 
    2134                                   ite = transformationMap_.end(); 
    2135 //    for (it = itb; it != ite; ++it) 
    2136 //    { 
    2137 //      (it->second)->checkValid(this); 
    2138 //    } 
    21392596  } 
    21402597 
Note: See TracChangeset for help on using the changeset viewer.