Ignore:
Timestamp:
06/09/16 11:33:08 (5 years ago)
Author:
mhnguyen
Message:

Optimizing codes: Change the way to compute distribution of grid

+) Instead of using DHT on grid, we make use of it only for elements of grid
+) Make change to calculation of server distribution.

Test
+) On Curie
+) Two times faster than the precedent commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/server_distribution_description.cpp

    r843 r865  
    9797  Compute global index assigned to a server with a range.E.g: if a grid has 100 points and 
    9898  there are 2 servers, the first one takes index from 0 to 49, the second has index from 50 to 99 
    99  
    10099  \param [in] indexBeginEnd begining and ending index of range 
     100  \param [in] positionDimensionDistributed dimension of server on which we make the cut. 
    101101*/ 
    102102void CServerDistributionDescription::computeServerGlobalIndexInRange(const std::pair<size_t, size_t>& indexBeginEnd, 
     
    161161    } 
    162162  } 
    163  
     163} 
     164 
     165/*! 
     166  Compute the global index of grid elements (domain, axis) and their associated server rank. 
     167  Each client knows the general distribution of servers and from which they can compute the pieces of information to hold 
     168  \param [out] indexServerOnElement global index of each element as well as the corresponding server which contains these indices 
     169  \param [in] clientRank rank of client 
     170  \param [in] clientSize number of client 
     171  \param [in] axisDomainOrder the order of element in grid (true for domain, false for axis) 
     172  \param [in] positionDimensionDistributed dimension of server on which we make the cut. 
     173*/ 
     174void CServerDistributionDescription::computeServerGlobalByElement(std::vector<boost::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, 
     175                                                                  int clientRank, 
     176                                                                  int clientSize, 
     177                                                                  const CArray<bool,1>& axisDomainOrder, 
     178                                                                  int positionDimensionDistributed) 
     179{ 
     180  switch (serverType_) { 
     181    case BAND_DISTRIBUTION: 
     182      computeBandDistribution(nServer_, positionDimensionDistributed); 
     183      break; 
     184    default: 
     185      break; 
     186  } 
     187 
     188  int nbElement = axisDomainOrder.numElements(); 
     189  indexServerOnElement.resize(nbElement); 
     190  int idx = 0; 
     191  std::vector<int> idxMap(nbElement); 
     192  for (int i = 0; i < nbElement; ++i) 
     193  { 
     194    idxMap[i] = idx; 
     195    if (true == axisDomainOrder(i)) idx += 2; 
     196    else ++idx; 
     197  } 
     198 
     199  for (int idxServer = 0; idxServer < nServer_; ++idxServer) 
     200  { 
     201    std::vector<int> elementDimension(4); 
     202    for (int i = 0; i < nbElement; ++i) 
     203    { 
     204      int elementSize = 1; 
     205      if (axisDomainOrder(i)) 
     206      { 
     207        elementSize *= dimensionSizes_[idxServer][idxMap[i]] * dimensionSizes_[idxServer][idxMap[i]+1]; 
     208        elementDimension[0] = indexBegin_[idxServer][idxMap[i]]; 
     209        elementDimension[1] = indexBegin_[idxServer][idxMap[i]+1]; 
     210        elementDimension[2] = dimensionSizes_[idxServer][idxMap[i]]; 
     211        elementDimension[3] = dimensionSizes_[idxServer][idxMap[i]+1]; 
     212      } 
     213 
     214      else 
     215      { 
     216        elementSize *= dimensionSizes_[idxServer][idxMap[i]]; 
     217        elementDimension[0] = indexBegin_[idxServer][idxMap[i]]; 
     218        elementDimension[1] = 0; 
     219        elementDimension[2] = dimensionSizes_[idxServer][idxMap[i]]; 
     220        elementDimension[3] = 1; 
     221      } 
     222 
     223      int rangeBegin, rangeSize; 
     224      computeRangeProcIndex(clientRank, clientSize, elementSize, rangeBegin, rangeSize); 
     225 
     226      size_t globalIndexElement; 
     227      idx = 0; int idxRange = 0; 
     228      for (int k = 0; k < elementDimension[3]; ++k) 
     229        for (int l = 0; l < elementDimension[2]; ++l) 
     230        { 
     231          globalIndexElement = (l+elementDimension[0]) + (k+elementDimension[1])*elementDimension[2]; 
     232          if ((rangeBegin <= idx) && (idxRange < rangeSize)) 
     233          { 
     234            indexServerOnElement[i][globalIndexElement].push_back(idxServer); 
     235            ++idxRange; 
     236          } 
     237          ++idx; 
     238        } 
     239    } 
     240  } 
     241} 
     242 
     243/*! 
     244  Compute a range of index on server which a client holds 
     245  For a range of index on a specific server, each client can hold a piece of the index range 
     246  If the range size is smaller than the number of client, there are some clients holding the same index 
     247  \param [in] clientRank rank of client 
     248  \param [in] clientSize number of client 
     249  \param [in] rangeProcSize index range size 
     250  \param [out] rangeBegin begin of range index a client holds 
     251  \param [out] rangeSize size of range index a client holds 
     252*/ 
     253void CServerDistributionDescription::computeRangeProcIndex(int clientRank, 
     254                                                           int clientSize, 
     255                                                           int rangeProcSize, 
     256                                                           int& rangeBegin, 
     257                                                           int& rangeSize) 
     258{ 
     259  if (rangeProcSize < clientSize) 
     260  { 
     261    int rangeIndex = 0; 
     262    for (int idx = 0; idx < clientSize; ++idx) 
     263    { 
     264      if (idx == clientRank) 
     265      { 
     266        rangeBegin = rangeIndex; 
     267        rangeSize = 1; 
     268      } 
     269      ++rangeIndex; 
     270      if (rangeIndex == rangeProcSize) rangeIndex = 0; 
     271    } 
     272    return; 
     273  } 
     274 
     275  int range, indexBegin = 0; 
     276  for (int i = 0; i < clientSize; ++i) 
     277  { 
     278    range = rangeProcSize / clientSize; 
     279    if (i < (rangeProcSize%clientSize)) ++range; 
     280    if (i == clientRank) break; 
     281    indexBegin += range; 
     282  } 
     283  rangeBegin = indexBegin; 
     284  rangeSize = range; 
    164285} 
    165286 
Note: See TracChangeset for help on using the changeset viewer.