- Timestamp:
- 02/11/15 16:23:07 (10 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/distribution.cpp
r551 r552 15 15 CDistribution::~CDistribution() 16 16 { 17 if (0 != globalIndex_) delete globalIndex_; 17 18 } 18 19 19 const CArray<size_t,1>* CDistribution::getGlobalIndex() const20 {21 return globalIndex_;22 }20 //const CArray<size_t,1>* CDistribution::getGlobalIndex() const 21 //{ 22 // return globalIndex_; 23 //} 23 24 24 25 int CDistribution::getDims() const -
XIOS/trunk/src/distribution.hpp
r551 r552 14 14 /** Default destructor */ 15 15 virtual ~CDistribution(); 16 const CArray<size_t,1>* getGlobalIndex() const;17 16 18 17 int getDims() const; 19 18 int getRank() const; 20 19 protected: 21 virtual void createGlobalIndex() = 0; // Maybe change to pure ? = 0;20 virtual void createGlobalIndex() = 0; 22 21 protected: 23 22 CArray<size_t,1>* globalIndex_; -
XIOS/trunk/src/node/distribution_client.cpp
r551 r552 5 5 CDistributionClient::CDistributionClient(int rank, int dims, CArray<size_t,1>* globalIndex) 6 6 : CDistribution(rank, dims, globalIndex), 7 axisDomainOrder_(), indexGlobalOnServer_(), isConnectedServerComputed_(false) 7 localDataIndex_(0), indexGlobalOnServer_(), localIndexSend2Server_(), axisDomainOrder_(), 8 nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 9 dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 10 gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), connectedClients_(), 11 isConnectedServerComputed_(false), indexDomainData_() 8 12 { 9 13 } 10 14 11 15 CDistributionClient::CDistributionClient(int rank, CGrid* grid) 12 : CDistribution(rank, 0, 0), isConnectedServerComputed_(false) 16 : CDistribution(rank, 0, 0), 17 localDataIndex_(0), indexGlobalOnServer_(), localIndexSend2Server_(), axisDomainOrder_(), 18 nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 19 dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 20 gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), connectedClients_(), 21 isConnectedServerComputed_(false), indexDomainData_() 13 22 { 14 23 readDistributionInfo(grid); … … 18 27 CDistributionClient::~CDistributionClient() 19 28 { 20 if (0 != this->globalIndex_) delete globalIndex_;21 29 if (0 != localDataIndex_) delete localDataIndex_; 22 30 } … … 625 633 626 634 std::vector<CArray<size_t,1>::const_iterator> itBegin(nServer), itEnd(nServer), it(nServer); 627 628 635 for (int i = 0; i < nServer; ++i) 629 636 { 630 itBegin[i] = globalIndexServer[i]->begin();637 itBegin[i] = it[i] = globalIndexServer[i]->begin(); 631 638 itEnd[i] = globalIndexServer[i]->end(); 632 639 } … … 637 644 for (int j = 0; j < nServer; ++j) 638 645 { 639 // Just temporarily, it's so so bad. 640 // if (std::binary_search(itBegin[j], itEnd[j], (*this->globalIndex_)(i))) 641 // if (itEnd[j] != std::find(itBegin[j], itEnd[j], (*this->globalIndex_)(i))) 642 it[j] = std::find(itBegin[j], itEnd[j], (*this->globalIndex_)(i)); 643 if (itEnd[j] != it[j]) 644 { 645 // (indexGlobalOnServer_[j]).push_back((*this->globalIndex_)(i)); 646 // Just temporarily, it's bad. 647 648 if (std::binary_search(itBegin[j], itEnd[j], (*this->globalIndex_)(i))) 649 { 646 650 // Just try to calculate local index server on client side 647 (indexGlobalOnServer_[j]).push_back( std::distance(itBegin[j], it[j]));651 (indexGlobalOnServer_[j]).push_back((*this->globalIndex_)(i)); 648 652 (localIndexSend2Server_[j]).push_back(i); 649 653 continue; 650 654 } 651 655 } 652 }653 654 655 for (int i = 0; i < nServer; ++i)656 {657 if (indexGlobalOnServer_[i].empty()) indexGlobalOnServer_.erase(i);658 if (localIndexSend2Server_[i].empty()) localIndexSend2Server_.erase(i);659 656 } 660 657 -
XIOS/trunk/src/node/distribution_client.hpp
r551 r552 65 65 std::vector<CArray<size_t,1>* > computeServerBandDistribution(int nServer); 66 66 private: 67 CArray<int,1>* localDataIndex_;//!< LocalData index on client68 CArray< size_t,1>* globalIndex_; //!< Global index on client67 //!< LocalData index on client 68 CArray<int,1>* localDataIndex_; 69 69 70 //! Index of the local data which will be sent to the corresponding server(s) 71 std::map<int, std::vector<int> > localIndexSend2Server_; 72 73 //! Global index of data on SERVER, which are calculated by client(s) 70 74 std::map<int, std::vector<size_t> > indexGlobalOnServer_; 71 std::map<int, std::vector<int> > localIndexSend2Server_;72 75 private: 73 76 /*! Domains and axis are considered elements. … … 75 78 int numElement_; 76 79 CArray<bool,1> axisDomainOrder_; //!< 77 78 80 79 81 std::vector<int> nLocal_; //!< Local size of each dimension (ni, nj, etc, ...) -
XIOS/trunk/src/node/distribution_server.cpp
r551 r552 2 2 3 3 namespace xios { 4 CDistributionServer::CDistributionServer(int rank, int dims, int nServer,CArray<size_t,1>* globalIndex)5 : CDistribution(rank, dims, globalIndex), n Server_(nServer), nGlobal_()4 CDistributionServer::CDistributionServer(int rank, int dims, CArray<size_t,1>* globalIndex) 5 : CDistribution(rank, dims, globalIndex), nGlobal_(), nZoomSize_(), nZoomBegin_() 6 6 { 7 8 7 } 9 8 10 CDistributionServer::CDistributionServer(int rank, int nServer, const std::vector<int>& nGlobal) 11 : CDistribution(rank, nGlobal.size()), nServer_(nServer) 9 CDistributionServer::CDistributionServer(int rank, const std::vector<int>& nZoomBegin, 10 const std::vector<int>& nZoomSize, const std::vector<int>& nGlobal) 11 : CDistribution(rank, nGlobal.size()), nGlobal_(nGlobal), nZoomSize_(nZoomSize), nZoomBegin_(nZoomBegin) 12 12 { 13 readDistributionInfo(nGlobal);14 13 createGlobalIndex(); 15 14 } … … 17 16 CDistributionServer::~CDistributionServer() 18 17 { 19 if (0 != this->globalIndex_) delete globalIndex_;20 18 } 21 19 22 void CDistributionServer::readDistributionInfo(const std::vector<int>& nGlobal) 20 /*! 21 Create global index on server side 22 Like the similar function on client side, this function serves on creating global index 23 for data written by the server. The global index is used to calculating local index of data 24 written on each server 25 */ 26 void CDistributionServer::createGlobalIndex() 23 27 { 24 if (nGlobal.empty()) 28 size_t idx = 0, ssize = 1; 29 for (int i = 0; i < nZoomSize_.size(); ++i) ssize *= nZoomSize_[i]; 30 31 this->globalIndex_ = new CArray<size_t,1>(ssize); 32 std::vector<int> idxLoop(this->getDims(),0); 33 std::vector<int> currentIndex(this->getDims()); 34 int innerLoopSize = nZoomSize_[0]; 35 36 while (idx<ssize) 25 37 { 26 //! TODO: This error must be replaced a call to function processing scalar value 27 ERROR("CDistributionServer::readDistributionInfo(const std::vector<int>& nGlobal)", 28 << "At least one dimension must be defined for this field."); 38 for (int i = 0; i < this->dims_-1; ++i) 39 { 40 if (idxLoop[i] == nZoomSize_[i]) 41 { 42 idxLoop[i] = 0; 43 ++idxLoop[i+1]; 44 } 45 } 46 47 for (int i = 1; i < this->dims_; ++i) currentIndex[i] = idxLoop[i] + nZoomBegin_[i]; 48 49 size_t mulDim, globalIndex; 50 for (int i = 0; i < innerLoopSize; ++i) 51 { 52 mulDim = 1; 53 globalIndex = i + nZoomBegin_[0]; 54 55 for (int k = 1; k < this->dims_; ++k) 56 { 57 mulDim *= nGlobal_[k-1]; 58 globalIndex += (currentIndex[k])*mulDim; 59 } 60 (*this->globalIndex_)(idx) = globalIndex; 61 ++idx; 62 } 63 idxLoop[0] += innerLoopSize; 29 64 } 30 nGlobal_ = nGlobal;31 this->dims_ = nGlobal.size();32 65 } 33 66 34 void CDistributionServer::createGlobalIndex() 67 /*! 68 Compute local index for writing data on server 69 \param [in] globalIndex global index received from client 70 \return local index of written data 71 */ 72 CArray<size_t,1> CDistributionServer::computeLocalIndex(const CArray<size_t,1>& globalIndex) 35 73 { 36 size_t globalIndexSize = 1; 37 for (int i = 0; i < nGlobal_.size(); ++i) 38 globalIndexSize *= nGlobal_[i]; 39 size_t rangeSize = globalIndexSize / nServer_; 40 size_t modulusSize = globalIndexSize % nServer_; 74 CArray<size_t,1>::const_iterator itBegin = (this->globalIndex_)->begin(), 75 itEnd = (this->globalIndex_)->end(), it; 41 76 42 if ((this->rank_ == (nServer_-1)) && (0 != modulusSize)) 77 int ssize = globalIndex.numElements(), idx = 0; 78 CArray<size_t,1> localIndex(ssize); 79 it = itBegin; 80 for (int i = 0; i < ssize; ++i) 43 81 { 44 this->globalIndex_ = new CArray<size_t,1>(modulusSize); 45 globalIndexSize = modulusSize; 46 } 47 else 48 { 49 this->globalIndex_ = new CArray<size_t,1>(rangeSize); 50 globalIndexSize = rangeSize; 82 it = std::lower_bound(it, itEnd, globalIndex(i)); 83 if (itEnd != it) 84 { 85 localIndex(idx) = std::distance(itBegin, it); 86 ++idx; 87 } 51 88 } 52 89 53 size_t idxBegin = this->rank_ * rangeSize; 54 for (size_t i = 0; i < globalIndexSize;++i) 55 (*this->globalIndex_)(i) = i+idxBegin; 90 return localIndex; 56 91 } 57 92 93 /*! 94 Compute local index for writing data on server 95 \param [in] globalIndex Global index received from client 96 */ 97 void CDistributionServer::computeLocalIndex(CArray<size_t,1>& globalIndex) 98 { 99 CArray<size_t,1>::const_iterator itBegin = (this->globalIndex_)->begin(), 100 itEnd = (this->globalIndex_)->end(), it; 101 102 int ssize = globalIndex.numElements(), idx = 0; 103 CArray<size_t,1> localIndex(ssize); 104 it = itBegin; 105 for (int i = 0; i < ssize; ++i) 106 { 107 it = std::lower_bound(it, itEnd, globalIndex(i)); 108 if (itEnd != it) 109 { 110 localIndex(idx) = std::distance(itBegin, it); 111 ++idx; 112 } 113 } 114 115 globalIndex = localIndex; 58 116 } 117 118 } // namespace xios -
XIOS/trunk/src/node/distribution_server.hpp
r551 r552 5 5 6 6 namespace xios { 7 /*! 8 \class CDistributionServer 9 The class, for now, plays a role of computing local index for writing data on server 10 */ 7 11 class CDistributionServer : public CDistribution 8 12 { 9 13 public: 10 14 /** Default constructor */ 11 CDistributionServer(int rank, int dims, int nServer, CArray<size_t,1>* globalIndex = 0); 12 CDistributionServer(int rank, int nServer, const std::vector<int>& nGlobal); 15 CDistributionServer(int rank, int dims, CArray<size_t,1>* globalIndex = 0); 16 CDistributionServer(int rank, const std::vector<int>& nZoomBegin, 17 const std::vector<int>& nZoomSize, const std::vector<int>& nGlobal); 13 18 14 19 /** Default destructor */ 15 20 virtual ~CDistributionServer(); 16 21 22 CArray<size_t,1> computeLocalIndex(const CArray<size_t,1>& globalIndex); 23 void computeLocalIndex(CArray<size_t,1>& globalIndex); 24 17 25 protected: 18 26 virtual void createGlobalIndex(); 19 20 //! Read info21 void readDistributionInfo(const std::vector<int>& nGlobal);22 27 private: 23 int nServer_;24 28 std::vector<int> nGlobal_; 29 std::vector<int> nZoomSize_; 30 std::vector<int> nZoomBegin_; 25 31 }; 26 32 27 } 33 } // namespace xios 28 34 #endif // __XIOS_DISTRIBUTION_SERVER_HPP__ -
XIOS/trunk/src/node/grid.cpp
r551 r552 11 11 #include "context.hpp" 12 12 #include "context_client.hpp" 13 #include "context_server.hpp" 13 14 #include "array_new.hpp" 14 15 … … 22 23 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 23 24 , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 25 , serverDistribution_(0) 24 26 { 25 27 setVirtualDomainGroup(); … … 32 34 , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 33 35 , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 36 , serverDistribution_(0) 34 37 { 35 38 setVirtualDomainGroup(); … … 55 58 56 59 if (0 != clientDistribution_) delete clientDistribution_; 60 if (0 != serverDistribution_) delete serverDistribution_; 57 61 58 62 } … … 807 811 void CGrid::recvIndex(int rank, CBufferIn& buffer) 808 812 { 813 if (0 == serverDistribution_) 814 { 815 CContext* context = CContext::getCurrent() ; 816 CContextServer* server=context->server ; 817 int idx = 0, numElement = axisDomainOrder.numElements(); 818 int ssize = numElement; 819 std::vector<int> indexMap(numElement); 820 for (int i = 0; i < numElement; ++i) 821 { 822 indexMap[i] = idx; 823 if (true == axisDomainOrder(i)) 824 { 825 ++ssize; 826 idx += 2; 827 } 828 } 829 830 int axisId = 0, domainId = 0; 831 std::vector<CDomain*> domainList = getDomains(); 832 std::vector<CAxis*> axisList = getAxis(); 833 std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize); 834 for (int i = 0; i < numElement; ++i) 835 { 836 if (axisDomainOrder(i)) 837 { 838 nZoomBegin[indexMap[i]] = domainList[domainId]->zoom_ibegin_srv; 839 nZoomSize[indexMap[i]] = domainList[domainId]->zoom_ni_srv; 840 nGlob[indexMap[i]] = domainList[domainId]->ni_glo; 841 842 nZoomBegin[indexMap[i]+1] = domainList[domainId]->zoom_jbegin_srv; 843 nZoomSize[indexMap[i]+1] = domainList[domainId]->zoom_nj_srv; 844 nGlob[indexMap[i]+1] = domainList[domainId]->nj_glo; 845 ++domainId; 846 } 847 else 848 { 849 nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin; 850 nZoomSize[indexMap[i]] = axisList[axisId]->zoom_size; 851 nGlob[indexMap[i]] = axisList[axisId]->size; 852 ++axisId; 853 } 854 } 855 serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, nGlob); 856 } 857 809 858 CArray<size_t,1> outIndex; 810 859 buffer>>outIndex; 860 serverDistribution_->computeLocalIndex(outIndex); 811 861 outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 812 862 -
XIOS/trunk/src/node/grid.hpp
r551 r552 12 12 #include "attribute_array.hpp" 13 13 #include "distribution_client.hpp" 14 #include "distribution_server.hpp" 14 15 15 16 namespace xios { … … 23 24 class CGrid; 24 25 class CDistributionClient; 26 class CDistributionServer; 25 27 26 28 ///-------------------------------------------------------------- … … 217 219 bool isAxisListSet, isDomListSet; 218 220 CDistributionClient* clientDistribution_; 221 CDistributionServer* serverDistribution_; 219 222 }; // class CGrid 220 223
Note: See TracChangeset
for help on using the changeset viewer.