Changeset 568


Ignore:
Timestamp:
03/10/15 10:49:09 (9 years ago)
Author:
mhnguyen
Message:

Implementing discovering algorithm of server index

+) Implement the algorithm with only one level
+) Remove some redundant functions, corrects some interface

Test
+) On Curie
+) Test passed and results are correct

Location:
XIOS/trunk/src
Files:
2 added
7 edited

Legend:

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

    r567 r568  
    2121 
    2222void CClientServerMapping::computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 
     23                                                     const CArray<int,1>& localIndexOnClient) 
     24{ 
     25//  defaultComputeServerIndexMapping(globalIndexOnClient, globalIndexServer); 
     26} 
     27 
     28 
     29void CClientServerMapping::computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 
    2330                                                     const std::vector<CArray<size_t,1>* >& globalIndexServer) 
    2431{ 
     
    2633} 
    2734 
    28 void CClientServerMapping::computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 
    29                                                      const CArray<int,1>& localIndexOnClient, 
    30                                                      const std::vector<CArray<size_t,1>* >& globalIndexOnServer) 
    31 { 
    32   defaultComputeServerIndexMapping(globalIndexOnClient, globalIndexOnServer, &localIndexOnClient); 
    33 } 
     35//void CClientServerMapping::computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 
     36//                                                     const CArray<int,1>& localIndexOnClient, 
     37//                                                     const std::vector<CArray<size_t,1>* >& globalIndexOfServer) 
     38//{ 
     39//  defaultComputeServerIndexMapping(globalIndexOnClient, globalIndexOfServer, &localIndexOnClient); 
     40//} 
    3441 
    3542/*! 
     
    6875  } 
    6976} 
    70  
    7177 
    7278/*! 
  • XIOS/trunk/src/client_server_mapping.hpp

    r567 r568  
    1313#include "array_new.hpp" 
    1414#include "mpi.hpp" 
     15#include <boost/unordered_map.hpp> 
    1516 
    1617namespace xios { 
     
    3435 
    3536    virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 
    36                                            const CArray<int,1>& localIndexOnClient, 
    37                                            const std::vector<CArray<size_t,1>* >& globalIndexOnServer); 
     37                                           const CArray<int,1>& localIndexOnClient); 
     38 
     39//    virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 
     40//                                           const CArray<int,1>& localIndexOnClient, 
     41//                                           const std::vector<CArray<size_t,1>* >& globalIndexOnServer); 
    3842 
    3943    std::map<int,int> computeConnectedClients(int nbServer, int nbClient, 
     
    4953                                          const CArray<int,1>* localIndexOnClient = 0); 
    5054 
    51   private: 
     55  protected: 
    5256    //! Global index of data on SERVER, which are calculated by client(s) 
    5357    std::map<int, std::vector<size_t> > indexGlobalOnServer_; 
  • XIOS/trunk/src/node/axis.cpp

    r567 r568  
    109109   void CAxis::checkZoom(void) 
    110110   { 
    111       StdSize zoom_begin,zoom_end, zoom_size; 
     111      StdSize zoom_begin,zoom_end, zoom_size, axisSize; 
    112112 
    113113      zoom_begin = (this->zoom_begin.isEmpty()) ?  0 : this->zoom_begin.getValue() ; 
     
    118118      if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1 ; 
    119119      if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1 ; 
    120  
    121       if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end)) 
     120      axisSize = size.getValue(); 
     121 
     122      if ( (zoom_begin < 0) || (zoom_begin > axisSize-1) || (zoom_end<0) || (zoom_end>axisSize-1) || (zoom_size<1) || (zoom_size>axisSize) || (zoom_begin>zoom_end)) 
    122123        ERROR("CAxis::checkAttributes(void)",<< "One or more attribut of <zoom_begin>, <zoom_end>, <zoom_size>, are not well specified") ; 
    123124 
  • XIOS/trunk/src/node/grid.cpp

    r567 r568  
    1313#include "context_server.hpp" 
    1414#include "array_new.hpp" 
     15#include "client_server_mapping_distributed.hpp" 
    1516 
    1617namespace xios { 
     
    2223      , isChecked(false), isDomainAxisChecked(false), storeIndex(1) 
    2324      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    24       , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(), writtenDataSize_(0), globalDim_() 
     25      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() 
    2526   { 
    2627     setVirtualDomainGroup(); 
     
    3233      , isChecked(false), isDomainAxisChecked(false), storeIndex(1) 
    3334      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    34       , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(), writtenDataSize_(0), globalDim_() 
     35      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() 
    3536   { 
    3637     setVirtualDomainGroup(); 
     
    174175     StdSize retVal; 
    175176     std::map<int, StdSize> ret; 
    176      const std::map<int, std::vector<int> >& distribution = clientServerMap_.getLocalIndexSendToServer(); 
     177     const std::map<int, std::vector<int> >& distribution = clientServerMap_->getLocalIndexSendToServer(); 
    177178     std::map<int, std::vector<int> >::const_iterator it = distribution.begin(), itE = distribution.end(); 
    178179     for (; it != itE; ++it) 
     
    280281      { 
    281282        int idx = 0; 
     283        std::vector<int> axisPositionMap; 
     284        for (int i = 0; i < axisDomainOrder.numElements(); ++i) 
     285        { 
     286          if (false == axisDomainOrder(i)) 
     287          { 
     288            axisPositionMap.push_back(idx); 
     289            ++idx; 
     290          } 
     291          else idx += 2; 
     292        } 
     293 
    282294        computeGridGlobalDimension(getDomains(), getAxis(), axisDomainOrder); 
    283295        for (int i = 0; i < axisListP.size(); ++i) 
    284296        { 
    285           while (this->axisDomainOrder(idx)) idx += 2; 
    286297          if (sendAtt) 
    287             axisListP[i]->sendCheckedAttributes(globalDim_,idx); 
     298            axisListP[i]->sendCheckedAttributes(globalDim_,axisPositionMap[i]); 
    288299          else 
    289             axisListP[i]->checkAttributesOnClient(globalDim_,idx); 
     300            axisListP[i]->checkAttributesOnClient(globalDim_,axisPositionMap[i]); 
    290301          ++idx; 
    291302        } 
     
    303314     // First of all, compute distribution on client side 
    304315     clientDistribution_ = new CDistributionClient(client->clientRank, this); 
     316     size_t globalSizeIndex = 1, indexBegin, indexEnd; 
     317     int range, clientSize = client->clientSize; 
     318     for (int i = 0; i < globalDim_.size(); ++i) globalSizeIndex *= globalDim_[i]; 
     319     indexBegin = 0; 
     320     for (int i = 0; i < clientSize; ++i) 
     321     { 
     322       range = globalSizeIndex / clientSize; 
     323       if (i < (globalSizeIndex%clientSize)) ++range; 
     324       if (i == client->clientRank) break; 
     325       indexBegin += range; 
     326     } 
     327     indexEnd = indexBegin + range - 1; 
    305328 
    306329     // Then compute distribution on server side 
    307330     serverDistributionDescription_ = new CServerDistributionDescription(clientDistribution_->getNGlob()); 
    308331     serverDistributionDescription_->computeServerDistribution(client->serverSize, true); 
     332     serverDistributionDescription_->computeServerGlobalIndexInRange(client->serverSize, 
     333                                                                     std::make_pair<size_t,size_t>(indexBegin, indexEnd)); 
    309334 
    310335     // Finally, compute index mapping between client(s) and server(s) 
    311      clientServerMap_.computeServerIndexMapping(clientDistribution_->getGlobalIndex(), 
    312                                                 clientDistribution_->getLocalDataIndexSendToServerOnClient(), 
    313                                                 serverDistributionDescription_->getGlobalIndex()); 
    314      const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_.getGlobalIndexOnServer(); 
     336     clientServerMap_ = new CClientServerMappingDistributed(serverDistributionDescription_->getGlobalIndexRange(), 
     337                                                            client->intraComm); 
     338 
     339     clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex(), 
     340                                                 clientDistribution_->getLocalDataIndexSendToServerOnClient()); 
     341 
     342//     clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex(), 
     343//                                                 clientDistribution_->getLocalDataIndexSendToServerOnClient(), 
     344//                                                 serverDistributionDescription_->getGlobalIndex()); 
     345     const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 
    315346     std::vector<int> connectedServerRank; 
    316347     for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) { 
    317348       connectedServerRank.push_back(it->first); 
    318349     } 
    319      nbSenders = clientServerMap_.computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank); 
     350     nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank); 
    320351 
    321352     // Get local data index on client 
     
    415446    list<shared_ptr<CMessage> > list_msg ; 
    416447    list< CArray<size_t,1>* > listOutIndex; 
    417     const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_.getGlobalIndexOnServer(); 
    418     const std::map<int, std::vector<int> >& localIndexSendToServer  = clientServerMap_.getLocalIndexSendToServer(); 
     448    const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 
     449    const std::map<int, std::vector<int> >& localIndexSendToServer  = clientServerMap_->getLocalIndexSendToServer(); 
    419450 
    420451    std::map<int, std::vector<size_t> >::const_iterator iteMap, itbMap, itGlobal; 
  • XIOS/trunk/src/node/grid.hpp

    r567 r568  
    221221        CDistributionServer* serverDistribution_; 
    222222        CServerDistributionDescription* serverDistributionDescription_; 
    223         CClientServerMapping clientServerMap_; 
     223        CClientServerMapping* clientServerMap_; 
    224224        size_t writtenDataSize_; 
    225225   }; // class CGrid 
  • XIOS/trunk/src/server_distribution_description.cpp

    r557 r568  
    1313{ 
    1414CServerDistributionDescription::CServerDistributionDescription(const std::vector<int>& globalDimensionSize) 
    15   : nGlobal_(globalDimensionSize), indexBegin_(), dimensionSizes_(), globalIndex_(0), vecGlobalIndex_() 
     15  : nGlobal_(globalDimensionSize), indexBegin_(), dimensionSizes_(), globalIndex_(), vecGlobalIndex_() 
    1616{ 
    1717 
     
    2020CServerDistributionDescription::~CServerDistributionDescription() 
    2121{ 
    22   if (0 != globalIndex_) delete globalIndex_; 
     22//  if (0 != globalIndex_) delete globalIndex_; 
    2323  if (!vecGlobalIndex_.empty()) 
    2424    for (int i = 0; i < vecGlobalIndex_.size(); ++i) delete vecGlobalIndex_[i]; 
     
    9292} 
    9393 
     94void CServerDistributionDescription::computeServerGlobalIndexInRange(int nServer, 
     95                                        const std::pair<size_t, size_t>& indexBeginEnd, 
     96                                        ServerDistributionType distributionType) 
     97{ 
     98  switch (distributionType) { 
     99    case BAND_DISTRIBUTION: 
     100      computeBandDistribution(nServer); 
     101      break; 
     102    default: 
     103      break; 
     104  } 
     105 
     106  size_t indexBegin = indexBeginEnd.first; 
     107  size_t indexEnd   = indexBeginEnd.second; 
     108  if (indexBegin > indexEnd) 
     109     ERROR("CServerDistributionDescription::computeServerGlobalIndexInRange", 
     110           << "Index begin is larger than index end"); 
     111 
     112  int dim = nGlobal_.size(); 
     113  std::vector<int> currentIndex(dim); 
     114 
     115  for (int idxServer = 0; idxServer < nServer; ++idxServer) 
     116  { 
     117    size_t ssize = 1, idx = 0; 
     118    for (int j = 0; j < dim; ++j) ssize *= dimensionSizes_[idxServer][j]; 
     119    vecGlobalIndex_[idxServer] = new CArray<size_t,1>(ssize); 
     120 
     121    std::vector<int> idxLoop(dim,0); 
     122 
     123    int innerLoopSize = dimensionSizes_[idxServer][0]; 
     124 
     125    while (idx<ssize) 
     126    { 
     127      for (int idxDim = 0; idxDim < dim-1; ++idxDim) 
     128      { 
     129        if (idxLoop[idxDim] == dimensionSizes_[idxServer][idxDim]) 
     130        { 
     131          idxLoop[idxDim] = 0; 
     132          ++idxLoop[idxDim+1]; 
     133        } 
     134      } 
     135 
     136      for (int idxDim = 1; idxDim < dim; ++idxDim)  currentIndex[idxDim] = idxLoop[idxDim] + indexBegin_[idxServer][idxDim]; 
     137 
     138      size_t mulDim, globalIndex; 
     139      for (int j = 0; j < innerLoopSize; ++j) 
     140      { 
     141        mulDim = 1; 
     142        globalIndex = j + indexBegin_[idxServer][0]; 
     143 
     144        for (int k = 1; k < dim; ++k) 
     145        { 
     146          mulDim *= nGlobal_[k-1]; 
     147          globalIndex += (currentIndex[k])*mulDim; 
     148        } 
     149        if ((indexBegin <= globalIndex) && (globalIndex <= indexEnd)) 
     150          globalIndex_.insert(std::make_pair<size_t,int>(globalIndex, idxServer)); 
     151        ++idx; 
     152      } 
     153      idxLoop[0] += innerLoopSize; 
     154    } 
     155  } 
     156 
     157} 
     158 
    94159/*! 
    95160  Compute global index of servers with band distribution 
     
    178243} 
    179244 
     245const boost::unordered_map<size_t,int>& CServerDistributionDescription::getGlobalIndexRange() const 
     246{ 
     247  return globalIndex_; 
     248} 
    180249} // namespace xios 
  • XIOS/trunk/src/server_distribution_description.hpp

    r554 r568  
    1313#include "xmlioserver_spl.hpp" 
    1414#include "array_new.hpp" 
     15#include <boost/unordered_map.hpp> 
    1516 
    1617namespace xios 
     
    3637                                   ServerDistributionType type = BAND_DISTRIBUTION); 
    3738 
    38     const CArray<size_t,1>& computeServerGlobalIndex(int nServer, int serverRank, 
    39                                                      ServerDistributionType = BAND_DISTRIBUTION); 
     39    void computeServerGlobalIndexInRange(int nServer, 
     40                                         const std::pair<size_t, size_t>& indexBeginEnd, 
     41                                         ServerDistributionType = BAND_DISTRIBUTION); 
    4042 
    4143    std::vector<std::vector<int> > getServerIndexBegin() const; 
    4244    std::vector<std::vector<int> > getServerDimensionSizes() const; 
    4345    const std::vector<CArray<size_t,1>* >& getGlobalIndex() const; 
     46    const boost::unordered_map<size_t,int>& getGlobalIndexRange() const; 
    4447 
    4548  protected: 
     
    5659 
    5760    //!< In case we need only global index of one server with specific rank 
    58     CArray<size_t,1>* globalIndex_; 
     61    boost::unordered_map<size_t,int> globalIndex_; 
    5962}; 
    6063 
Note: See TracChangeset for help on using the changeset viewer.