Changeset 815


Ignore:
Timestamp:
01/26/16 18:18:58 (9 years ago)
Author:
mhnguyen
Message:

Fixing the bug in ticket 72

+) The distributed axis on client side send info to correct corresponding server
+) Improve serverdistributiondescription class to make it more flexible
+) Create new test_basic_2D only for test cases of 2-d grid

Test
+) On Curie
+) All tests pass

Location:
XIOS/trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/axis.cpp

    r786 r815  
    351351     { 
    352352       sendServerAttribut(globalDim, orderPositionInGrid, distType); 
    353        sendValue(); 
     353       sendValue(globalDim, orderPositionInGrid, distType); 
    354354     } 
    355355 
     
    357357   } 
    358358 
    359   void CAxis::sendValue() 
     359  void CAxis::sendValue(const std::vector<int>& globalDim, int orderPositionInGrid, 
     360                        CServerDistributionDescription::ServerDistributionType distType) 
    360361  { 
    361362     if (n.getValue() == n_glo.getValue()) 
     
    365366     else 
    366367     { 
    367        computeConnectedServer(); 
     368       computeConnectedServer(globalDim, orderPositionInGrid, distType); 
    368369       sendDistributedValue(); 
    369370     } 
    370371  } 
    371372 
    372   void CAxis::computeConnectedServer() 
     373  void CAxis::computeConnectedServer(const std::vector<int>& globalDim, int orderPositionInGrid, 
     374                                     CServerDistributionDescription::ServerDistributionType distType) 
    373375  { 
    374376    CContext* context = CContext::getCurrent(); 
     
    418420    } 
    419421 
    420     std::vector<int> nGlobDomain(1); 
    421     nGlobDomain[0] = n_glo.getValue(); 
    422  
    423     size_t globalSizeIndex = 1, indexBegin, indexEnd; 
    424     for (int i = 0; i < nGlobDomain.size(); ++i) globalSizeIndex *= nGlobDomain[i]; 
    425     indexBegin = 0; 
    426     for (int i = 0; i < clientSize; ++i) 
    427     { 
    428       range = globalSizeIndex / clientSize; 
    429       if (i < (globalSizeIndex%clientSize)) ++range; 
    430       if (i == client->clientRank) break; 
    431       indexBegin += range; 
    432     } 
    433     indexEnd = indexBegin + range - 1; 
    434  
    435     CServerDistributionDescription serverDescription(nGlobDomain); 
    436     serverDescription.computeServerGlobalIndexInRange(nbServer, std::make_pair<size_t,size_t>(indexBegin, indexEnd), 0); 
    437     CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); 
    438     clientServerMap->computeServerIndexMapping(globalIndexAxis); 
    439     const std::map<int, std::vector<size_t> >& globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); 
     422    CServerDistributionDescription serverDescriptionGlobal(globalDim, nbServer); 
     423    int distributedDimensionOnServer = serverDescriptionGlobal.getDimensionDistributed(); 
     424    std::map<int, std::vector<size_t> > globalIndexAxisOnServer; 
     425    if (distributedDimensionOnServer == orderPositionInGrid) // So we have distributed axis on client side and also on server side* 
     426    { 
     427      std::vector<int> nGlobAxis(1); 
     428      nGlobAxis[0] = n_glo.getValue(); 
     429 
     430      size_t globalSizeIndex = 1, indexBegin, indexEnd; 
     431      for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; 
     432      indexBegin = 0; 
     433      for (int i = 0; i < clientSize; ++i) 
     434      { 
     435        range = globalSizeIndex / clientSize; 
     436        if (i < (globalSizeIndex%clientSize)) ++range; 
     437        if (i == client->clientRank) break; 
     438        indexBegin += range; 
     439      } 
     440      indexEnd = indexBegin + range - 1; 
     441 
     442      CServerDistributionDescription serverDescription(nGlobAxis, nbServer); 
     443      serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd)); 
     444      CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); 
     445      clientServerMap->computeServerIndexMapping(globalIndexAxis); 
     446      globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); 
     447      delete clientServerMap; 
     448    } 
     449    else 
     450    { 
     451      std::vector<size_t> globalIndexServer(n_glo.getValue()); 
     452      for (size_t idx = 0; idx < n_glo.getValue(); ++idx) 
     453      { 
     454        globalIndexServer[idx] = idx; 
     455      } 
     456 
     457      for (int idx = 0; idx < nbServer; ++idx) 
     458      { 
     459        globalIndexAxisOnServer[idx] = globalIndexServer; 
     460      } 
     461    } 
    440462 
    441463    std::map<int, std::vector<size_t> >::const_iterator it = globalIndexAxisOnServer.begin(), 
     
    476498        connectedServerRank_.push_back(it->first); 
    477499    } 
    478     nbConnectedClients_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 
    479     delete clientServerMap; 
     500    nbConnectedClients_ = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 
    480501  } 
    481502 
     
    774795    CContext* context = CContext::getCurrent(); 
    775796    CContextClient* client = context->client; 
    776  
    777     CServerDistributionDescription serverDescription(globalDim); 
    778  
    779797    int nbServer = client->serverSize; 
    780798 
    781     serverDescription.computeServerDistribution(nbServer, false, distType); 
     799    CServerDistributionDescription serverDescription(globalDim, nbServer); 
     800    serverDescription.computeServerDistribution(); 
     801 
    782802    std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); 
    783803    std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); 
  • XIOS/trunk/src/node/axis.hpp

    r775 r815  
    128128         void computeServerIndex(const std::vector<int>& globalDim, int orderPositionInGrid, 
    129129                                 CServerDistributionDescription::ServerDistributionType disType); 
    130          void sendValue(); 
    131          void computeConnectedServer(void); 
     130         void sendValue(const std::vector<int>& globalDim, int orderPositionInGrid, 
     131                        CServerDistributionDescription::ServerDistributionType distType); 
     132         void computeConnectedServer(const std::vector<int>& globalDim, int orderPositionInGrid, 
     133                                     CServerDistributionDescription::ServerDistributionType distType); 
    132134         void sendDistributedValue(); 
    133135         void sendNonDistributedValue(); 
  • XIOS/trunk/src/node/domain.cpp

    r813 r815  
    465465          lon_g.resize(ni_glo) ; 
    466466          lat_g.resize(nj_glo) ; 
    467            
    468            
     467 
     468 
    469469          int* ibegin_g = new int[client->clientSize] ; 
    470470          int* jbegin_g = new int[client->clientSize] ; 
     
    480480          v=nj ; 
    481481          MPI_Allgather(&v,1,MPI_INT,nj_g,1,MPI_INT,client->intraComm) ; 
    482            
     482 
    483483          MPI_Allgatherv(lon.dataFirst(),ni,MPI_DOUBLE,lon_g.dataFirst(),ni_g, ibegin_g,MPI_DOUBLE,client->intraComm) ; 
    484484          MPI_Allgatherv(lat.dataFirst(),nj,MPI_DOUBLE,lat_g.dataFirst(),nj_g, jbegin_g,MPI_DOUBLE,client->intraComm) ; 
    485     
     485 
    486486      delete[] ibegin_g ; 
    487487      delete[] jbegin_g ; 
     
    494494   { 
    495495     int i,j,k; 
    496       
     496 
    497497     const int nvertexValue = 4; 
    498498     boundsLon.resize(nvertexValue,ni*nj); 
     
    510510       bounds_lon_end= (lon(0) +360 + lon(ni_glo-1))/2 ; 
    511511     } 
    512         
     512 
    513513     for(j=0;j<nj;++j) 
    514514       for(i=0;i<ni;++i) 
     
    520520                                                                        : (lon(ibegin + i + 1)+lon(ibegin + i))/2; 
    521521       } 
    522      
     522 
    523523 
    524524    boundsLat.resize(nvertexValue,nj*ni); 
     
    546546      } 
    547547    } 
    548      
     548 
    549549    double latStepEnd = lat(nj_glo-1)-lat(nj_glo-2); 
    550550    if (isSouthPole) bounds_lat_end=lat(nj_glo-1); 
     
    563563        if ( -90 + bounds_lat_end <= 0.1*std::abs(latStepEnd)) bounds_lat_end=-90 ; 
    564564      } 
    565     }       
    566        
     565    } 
     566 
    567567    for(j=0;j<nj;++j) 
    568568      for(i=0;i<ni;++i) 
     
    12221222  void CDomain::sendServerAttribut(void) 
    12231223  { 
    1224     CServerDistributionDescription serverDescription(nGlobDomain_); 
    1225  
    12261224    CContext* context = CContext::getCurrent(); 
    12271225    CContextClient* client = context->client; 
    12281226    int nbServer = client->serverSize; 
    12291227 
    1230     if (isUnstructed_) serverDescription.computeServerDistribution(nbServer,0); 
    1231     else serverDescription.computeServerDistribution(nbServer,1); 
     1228    CServerDistributionDescription serverDescription(nGlobDomain_, nbServer); 
     1229    if (isUnstructed_) serverDescription.computeServerDistribution(false, 0); 
     1230    else serverDescription.computeServerDistribution(false, 1); 
    12321231 
    12331232    std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); 
     
    13721371    indexEnd = indexBegin + range - 1; 
    13731372 
    1374     CServerDistributionDescription serverDescription(nGlobDomain_); 
    1375     if (isUnstructed_) serverDescription.computeServerGlobalIndexInRange(nbServer, std::make_pair<size_t,size_t>(indexBegin, indexEnd), 0); 
    1376     else serverDescription.computeServerGlobalIndexInRange(nbServer, std::make_pair<size_t,size_t>(indexBegin, indexEnd), 1); 
     1373    CServerDistributionDescription serverDescription(nGlobDomain_, nbServer); 
     1374    if (isUnstructed_) serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd), 0); 
     1375    else serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd), 1); 
    13771376 
    13781377    CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), 
  • XIOS/trunk/src/node/grid.cpp

    r803 r815  
    419419 
    420420     // Then compute distribution on server side 
    421      CServerDistributionDescription serverDistributionDescription(globalDim_); 
    422      serverDistributionDescription.computeServerGlobalIndexInRange(client->serverSize, 
    423                                                                    std::make_pair<size_t,size_t>(indexBegin, indexEnd), 
    424                                                                    positionDimensionDistributed_); 
     421     CServerDistributionDescription serverDistributionDescription(globalDim_, client->serverSize); 
     422     serverDistributionDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd), positionDimensionDistributed_); 
    425423 
    426424     // Finally, compute index mapping between client(s) and server(s) 
  • XIOS/trunk/src/server_distribution_description.cpp

    r657 r815  
    33   \author Ha NGUYEN 
    44   \since 04 Jan 2015 
    5    \date 24 Jul 2015 
     5   \date 11 Jan 2016 
    66 
    77   \brief Description of index distribution on server(s). 
     
    1313namespace xios 
    1414{ 
    15 CServerDistributionDescription::CServerDistributionDescription(const std::vector<int>& globalDimensionSize) 
    16   : nGlobal_(globalDimensionSize), indexBegin_(), dimensionSizes_(), globalIndex_(), vecGlobalIndex_() 
     15  /*! 
     16  \param [in] globalDimensionSize global dimension of grid 
     17  \param [in] nServer number of server 
     18  \param [in] serType type of server distribution. For now, we can distribute server by band or plan 
     19  */ 
     20CServerDistributionDescription::CServerDistributionDescription(const std::vector<int>& globalDimensionSize, 
     21                                                               int nServer, 
     22                                                               ServerDistributionType serType) 
     23  : nGlobal_(globalDimensionSize), indexBegin_(), dimensionSizes_(), globalIndex_(), 
     24    vecGlobalIndex_(), serverType_(serType), nServer_(nServer), positionDimensionDistributed_(1) 
    1725{ 
    1826} 
     
    2331/*! 
    2432  Compute pre-defined global index distribution of server(s). 
    25   \param [in] nServer number of server 
    2633  \param [in] doComputeGlobalIndex flag to compute global index on each server. By default, false 
    27   \param [in] serType type of server distribution. For now, we can distribute server by band or plan 
    28 */ 
    29 void CServerDistributionDescription::computeServerDistribution(int nServer, 
    30                                                                int positionDimensionDistributed, 
    31                                                                bool doComputeGlobalIndex, 
    32                                                                ServerDistributionType serType) 
    33 { 
    34   switch (serType) { 
     34 
     35*/ 
     36void CServerDistributionDescription::computeServerDistribution(bool doComputeGlobalIndex, 
     37                                                               int positionDimensionDistributed) 
     38{ 
     39  switch (serverType_) { 
    3540    case BAND_DISTRIBUTION: 
    36       computeBandDistribution(nServer, positionDimensionDistributed); 
     41      computeBandDistribution(nServer_, positionDimensionDistributed); 
    3742      break; 
    3843    default: 
     
    4247  if (doComputeGlobalIndex) 
    4348  { 
    44     vecGlobalIndex_.resize(nServer); 
     49    vecGlobalIndex_.resize(nServer_); 
    4550    int dim = nGlobal_.size(); 
    4651    std::vector<int> currentIndex(dim); 
    4752 
    48     for (int idxServer = 0; idxServer < nServer; ++idxServer) 
     53    for (int idxServer = 0; idxServer < nServer_; ++idxServer) 
    4954    { 
    5055      size_t ssize = 1, idx = 0; 
     
    9297  Compute global index assigned to a server with a range.E.g: if a grid has 100 points and 
    9398  there are 2 servers, the first one takes index from 0 to 49, the second has index from 50 to 99 
    94   \param [in] nServer number of server 
     99 
    95100  \param [in] indexBeginEnd begining and ending index of range 
    96   \param [in] serType type of server distribution. For now, we can distribute server by band or plan 
    97 */ 
    98 void CServerDistributionDescription::computeServerGlobalIndexInRange(int nServer, 
    99                                                                      const std::pair<size_t, size_t>& indexBeginEnd, 
    100                                                                      int positionDimensionDistributed, 
    101                                                                      ServerDistributionType distributionType) 
    102 { 
    103   switch (distributionType) { 
     101*/ 
     102void CServerDistributionDescription::computeServerGlobalIndexInRange(const std::pair<size_t, size_t>& indexBeginEnd, 
     103                                                                     int positionDimensionDistributed) 
     104{ 
     105  switch (serverType_) { 
    104106    case BAND_DISTRIBUTION: 
    105       computeBandDistribution(nServer, positionDimensionDistributed); 
     107      computeBandDistribution(nServer_, positionDimensionDistributed); 
    106108      break; 
    107109    default: 
     
    118120  std::vector<int> currentIndex(dim); 
    119121 
    120   for (int idxServer = 0; idxServer < nServer; ++idxServer) 
     122  for (int idxServer = 0; idxServer < nServer_; ++idxServer) 
    121123  { 
    122124    size_t ssize = 1, idx = 0; 
     
    167169{ 
    168170  int dim = nGlobal_.size(); 
    169   if (positionDimensionDistributed > dim) 
     171  positionDimensionDistributed_ = positionDimensionDistributed; 
     172  if (1 == dim) positionDimensionDistributed_ = 0; 
     173  if (positionDimensionDistributed_ > dim) 
    170174    ERROR("CServerDistributionDescription::computeBandDistribution(int nServer, int positionDimensionDistributed)", 
    171175          << "Position of distributed dimension is invalid" << std::endl 
    172           << "Position of distributed dimension is " << positionDimensionDistributed 
     176          << "Position of distributed dimension is " << positionDimensionDistributed_ 
    173177          << "Dimension " << dim) 
    174178 
     
    187191  std::vector<int> njRangeEnd(nServer,0); 
    188192 
    189   int positionDistributed = (1<dim) ? positionDimensionDistributed : 0; 
     193  int positionDistributed = (1<dim) ? positionDimensionDistributed_ : 0; 
    190194  nGlobTemp = nGlobal_[positionDistributed]; 
    191195 
     
    259263  return globalIndex_; 
    260264} 
     265 
     266int CServerDistributionDescription::getDimensionDistributed() 
     267{ 
     268  return ((1<nGlobal_.size()) ? positionDimensionDistributed_ : 0); 
     269} 
     270 
    261271} // namespace xios 
  • XIOS/trunk/src/server_distribution_description.hpp

    r657 r815  
    33   \author Ha NGUYEN 
    44   \since 04 Jan 2015 
    5    \date 24 Jul 2015 
     5   \date 11 Jan 2016 
    66 
    77   \brief Description of index distribution on server(s). 
     
    3030 
    3131    /** Default constructor */ 
    32     CServerDistributionDescription(const std::vector<int>& globalDimensionSize); 
     32    CServerDistributionDescription(const std::vector<int>& globalDimensionSize, 
     33                                   int nServer, 
     34                                   ServerDistributionType serType=BAND_DISTRIBUTION); 
     35 
    3336    /** Default destructor */ 
    3437    virtual ~CServerDistributionDescription(); 
    3538 
    36     void computeServerDistribution(int nServer, int positionDimensionDistributed = 1, 
    37                                    bool doComputeGlobalIndex = false, 
    38                                    ServerDistributionType type = BAND_DISTRIBUTION); 
    39  
    40     void computeServerGlobalIndexInRange(int nServer, 
    41                                          const std::pair<size_t, size_t>& indexBeginEnd, 
    42                                          int positionDimensionDistributed = 1, 
    43                                          ServerDistributionType = BAND_DISTRIBUTION); 
     39    void computeServerDistribution(bool doComputeGlobalIndex = false, int positionDimensionDistributed = 1); 
     40    void computeServerGlobalIndexInRange(const std::pair<size_t, size_t>& indexBeginEnd, int positionDimensionDistributed = 1); 
    4441 
    4542    std::vector<std::vector<int> > getServerIndexBegin() const; 
     
    4744    const std::vector<CArray<size_t,1> >& getGlobalIndex() const; 
    4845    const boost::unordered_map<size_t,int>& getGlobalIndexRange() const; 
     46    int getDimensionDistributed(); 
    4947 
    5048  protected: 
     
    6260    //!< In case we need only global index of one server with specific rank 
    6361    boost::unordered_map<size_t,int> globalIndex_; 
     62 
     63    //!< Type of distribution on server side 
     64    ServerDistributionType serverType_; 
     65 
     66    //!< Number of server 
     67    int nServer_; 
     68 
     69    //!< Position of dimension distributed on server side (by default, the second dimension) 
     70    int positionDimensionDistributed_; 
    6471}; 
    6572 
Note: See TracChangeset for help on using the changeset viewer.