Changeset 1930 for XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution
- Timestamp:
- 09/10/20 13:51:02 (4 years ago)
- Location:
- XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/distributed_view.cpp
r1918 r1930 9 9 : globalIndex_(parent->globalIndex_), globalSize_(parent->globalSize_), localSize_(parent->localSize_) 10 10 { 11 for(auto index : indexView)11 for(auto& index : indexView) 12 12 { 13 13 index_[index.first].reference(index.second.copy()) ; … … 16 16 } 17 17 18 19 } 18 CDistributedView::CDistributedView(CDistributedElement* parent, CElementView::type, const std::map<int,CArray<bool,1>>& maskView) 19 : globalIndex_(parent->globalIndex_), globalSize_(parent->globalSize_), localSize_(parent->localSize_) 20 { 21 for(auto& it : maskView) 22 { 23 int rank = it.first ; 24 auto& mask = it.second ; 25 int size = mask.numElements() ; 26 auto& index = index_[rank] ; 27 index.resize(size) ; 28 int pos=0 ; 29 for(int i=0 ; i < size ; i++) 30 if (mask(i)) { index(pos) = i ; pos++ ; } 31 index.resizeAndPreserve(pos) ; 32 size_[rank] = pos ; 33 } 34 } 35 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/distributed_view.hpp
r1918 r1930 15 15 16 16 CDistributedView(CDistributedElement* parent, CElementView::type type, const std::map<int,CArray<int,1>>& indexView) ; 17 CDistributedView(CDistributedElement* parent, CElementView::type type, const std::map<int,CArray<bool,1>>& maskView) ; 17 18 18 19 std::map<int,CArray<int,1>>& getIndex(void) { return index_ ;} … … 21 22 std::map<int, int>& getLocalSize(void) { return localSize_ ;} 22 23 size_t getGlobalSize(void) { return globalSize_ ;} 24 25 void getGlobalIndexView(map<int,CArray<size_t,1>>& globalIndexView) 26 { 27 for(auto& it : globalIndex_) 28 { 29 int rank=it.first ; 30 auto& globalIndex = it.second; 31 auto& globalIndView = globalIndexView[rank] ; 32 auto& index = index_[rank] ; 33 auto& size = size_[rank] ; 34 auto& localSize = localSize_[rank] ; 35 globalIndView.resize(size) ; 36 int pos=0 ; 37 for(int i=0 ; i<size ; i++) 38 { 39 if (index(i)>=0 && index(i)<localSize) 40 { 41 globalIndView(i) = globalIndex(index(i)) ; 42 pos++ ; 43 } 44 } 45 globalIndView.resizeAndPreserve(pos) ; 46 } 47 } 23 48 24 49 void getGlobalIndex(int rank, vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CDistributedView** view, int pos) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/element.cpp
r1918 r1930 29 29 { 30 30 views_[type] = new CDistributedView(this, type, indexView) ; 31 } 32 33 void CDistributedElement::addView(CElementView::type type, std::map<int, CArray<bool,1>>& maskView) 34 { 35 views_[type] = new CDistributedView(this, type, maskView) ; 31 36 } 32 37 … … 118 123 } 119 124 125 void CLocalElement::addView(CElementView::type type, CArray<bool,1>& maskView) 126 { 127 views_[type] = new CLocalView(this, type, maskView) ; 128 } 129 120 130 void CLocalElement::addFullView(void) 121 131 { -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/element.hpp
r1918 r1930 40 40 41 41 void addView(CElementView::type type, std::map<int, CArray<int,1>>& indexView) ; 42 void addView(CElementView::type type, std::map<int, CArray<bool,1>>& maskView) ; 42 43 void sendToServer(CEventClient& event, const CMessage& messageHeader) ; 43 44 … … 55 56 CLocalElement(int localRank, CEventServer& event) ; 56 57 void recvFromClient(int localRank, CEventServer& event) ; 57 58 const CArray<size_t,1>& getGlobalIndex(void) { return globalIndex_ ;} 58 59 void addView(CElementView::type type, CArray<int,1>& indexView) ; 60 void addView(CElementView::type type, CArray<bool,1>& maskView) ; 59 61 void addFullView(void) ; 60 62 CLocalView* getView(CElementView::type type) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.cpp
r1918 r1930 15 15 unordered_map<size_t,int> mapGlobalLocalIndex ; 16 16 int globalIndexSize=dstGlobalIndex.size() ; 17 for(auto& ind : dstIndex) mapGlobalLocalIndex[dstGlobalIndex(ind)] = ind ; 17 //for(auto& ind : dstIndex) mapGlobalLocalIndex[dstGlobalIndex(ind)] = ind ; 18 for(int i=0; i<dstSize_ ; i++) if (dstIndex(i)>=0 && dstIndex(i)<globalIndexSize) mapGlobalLocalIndex[dstGlobalIndex(dstIndex(i))] = i ; 19 18 20 for(auto& rankIndex : srcIndex) 19 21 { … … 27 29 for(int ind=0; ind<indexSize ; ind++) 28 30 { 29 if (ind >=0 && ind<globalIndexSize)31 if (index(ind)>=0 && index(ind)<globalIndexSize) 30 32 { 31 auto it=mapGlobalLocalIndex.find(globalIndex(ind )) ;33 auto it=mapGlobalLocalIndex.find(globalIndex(index(ind))) ; 32 34 if (it != mapGlobalLocalIndex.end()) 33 35 { -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.hpp
r1918 r1930 29 29 30 30 template<typename T> 31 void transfer( map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut)31 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 32 32 { 33 dataOut.resize(dstSize_) ; 33 // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 34 dataOut.resize(dstSize_*sizeT) ; 34 35 T* output = dataOut.dataFirst() ; 35 36 for(auto& data : dataIn) … … 39 40 auto& connector=connector_[rank] ; 40 41 auto& mask=mask_[rank] ; 41 int size= data.second.numElements() ;42 int size=mask.size() ; 42 43 43 44 for(int i=0, j=0 ;i<size;i++) … … 45 46 if (mask[i]) 46 47 { 47 output[connector[j]] = input[i] ; 48 int cj = connector[j]*sizeT ; 49 int ci = i*sizeT ; 50 for (int k=0;k<sizeT;k++) output[cj+k] = input[ci+k] ; 48 51 j++ ; 49 52 } … … 52 55 } 53 56 57 template<typename T> 58 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 59 { 60 transfer(1,dataIn,dataOut) ; 61 } 54 62 55 63 template<typename T> … … 93 101 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue) 94 102 { 95 dataOut.resize(dstSize_) ; 96 dataOut=missingValue ; 97 transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) ; 103 transfer(1, dataIn, dataout, missingValue) 98 104 } 99 105 100 106 template<typename T> 101 void transfer(CEventServer& event, CArray<T,1>& dataOut) 107 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue) 108 { 109 dataOut.resize(dstSize_*sizeT) ; 110 dataOut=missingValue ; 111 transfer(sizeT, dataIn, dataOut) ; 112 } 113 114 template<typename T> 115 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut) 102 116 { 103 117 map<int, CArray<T,1>> dataIn ; … … 107 121 (*subEvent.buffer) >> data ; 108 122 } 109 transfer(dataIn, dataOut) ; 123 transfer(sizeT, dataIn, dataOut) ; 124 } 125 126 template<typename T> 127 void transfer(CEventServer& event, CArray<T,1>& dataOut) 128 { 129 transfer(event, 1, dataOut) ; 130 } 131 132 template<typename T> 133 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut, T missingValue) 134 { 135 map<int, CArray<T,1>> dataIn ; 136 for (auto& subEvent : event.subEvents) 137 { 138 auto& data = dataIn[subEvent.rank]; 139 (*subEvent.buffer) >> data ; 140 } 141 transfer(sizeT, dataIn, dataOut, missingValue) ; 110 142 } 111 143 … … 119 151 (*subEvent.buffer) >> data ; 120 152 } 121 transfer( dataIn, dataOut, missingValue) ;153 transfer(1, dataIn, dataOut, missingValue) ; 122 154 } 123 155 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_local_view.cpp
r1918 r1930 6 6 CGridLocalView::CGridLocalView(CGridLocalElements* parent, CElementView::type type) : localMask_(parent->getLocalMask()) 7 7 { 8 for(auto element : parent->getElements()) views_.push_back(element->getView(type)) ; 8 size_ = 1 ; 9 for(auto element : parent->getElements()) 10 { 11 views_.push_back(element->getView(type)) ; 12 size_ *= element->getView(type)->getSize() ; 13 } 14 9 15 } 10 16 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_local_view.hpp
r1918 r1930 14 14 std::vector<CLocalView*> views_ ; 15 15 std::vector<bool>& localMask_ ; 16 int size_ ; 16 17 17 18 public: 18 19 CGridLocalView(CGridLocalElements* parent, CElementView::type type) ; 19 20 std::vector<CLocalView*>& getViews(void) {return views_ ;} 21 int getSize() { return size_ ;} 20 22 } ; 21 23 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_remote_connector.cpp
r1918 r1930 19 19 { 20 20 // generic method, every element can be distributed 21 int nDst = dstView_.size() ; 22 vector<size_t> dstSliceSize(nDst) ; 23 dstSliceSize[0] = 1 ; 24 for(int i=1; i<nDst; i++) dstSliceSize[i] = dstView_[i-1]->getGlobalSize()*dstSliceSize[i-1] ; 25 26 CClientClientDHTTemplate<int>::Index2VectorInfoTypeMap dataInfo ; 27 28 CClientClientDHTTemplate<size_t>::Index2VectorInfoTypeMap info ; // info map 29 for(int pos=0; pos<nDst; pos++) 30 { 31 size_t sliceSize=dstSliceSize[pos] ; 32 map<int,CArray<size_t,1>> globalIndexView ; 33 dstView_[pos]->getGlobalIndexView(globalIndexView) ; 34 35 CClientClientDHTTemplate<size_t>::Index2VectorInfoTypeMap lastInfo(info) ; 36 37 if (pos>0) 38 { 39 CArray<size_t,1> ranks(globalIndexView.size()) ; 40 auto it=globalIndexView.begin() ; 41 for(int i=0 ; i<ranks.numElements();i++,it++) ranks(i)=it->first ; 42 CClientClientDHTTemplate<size_t> dataRanks(info, localComm_) ; 43 dataRanks.computeIndexInfoMapping(ranks) ; 44 lastInfo = dataRanks.getInfoIndexMap() ; 45 } 46 47 info.clear() ; 48 for(auto& it : globalIndexView) 49 { 50 int rank = it.first ; 51 auto& globalIndex = it.second ; 52 auto& inf = info[rank] ; 53 if (pos==0) for(int i=0;i<globalIndex.numElements();i++) inf.push_back(globalIndex(i)) ; 54 else 55 { 56 auto& lastGlobalIndex = lastInfo[rank] ; 57 for(size_t lastGlobalInd : lastGlobalIndex) 58 { 59 for(int i=0;i<globalIndex.numElements();i++) inf.push_back(globalIndex(i)*sliceSize+lastGlobalInd) ; 60 } 61 } 62 } 63 64 if (pos==nDst-1) 65 { 66 for(auto& it : info) 67 { 68 int rank=it.first ; 69 auto& globalIndex = it.second ; 70 for(auto globalInd : globalIndex) dataInfo[globalInd].push_back(rank) ; 71 } 72 } 73 } 74 75 CClientClientDHTTemplate<int> dataRanks(dataInfo, localComm_) ; 76 /* 21 77 CClientClientDHTTemplate<int>::Index2VectorInfoTypeMap info ; // info map 22 78 … … 37 93 38 94 CClientClientDHTTemplate<int> dataRanks(info, localComm_) ; 39 95 */ 40 96 // generate list of global index for src view 41 97 int nSrc = srcView_.size() ; 42 98 vector<size_t> srcSliceSize(nSrc) ; 43 srcSliceSize[nSrc-1] = 1 ; 44 for(int i=nSrc-2; i>=0; i--) srcSliceSize[i] = srcView_[i+1]->getGlobalSize()*srcSliceSize[i+1] ; 45 99 // srcSliceSize[nSrc-1] = 1 ; 100 // for(int i=nSrc-2; i>=0; i--) srcSliceSize[i] = srcView_[i+1]->getGlobalSize()*srcSliceSize[i+1] ; 101 102 srcSliceSize[0] = 1 ; 103 for(int i=1; i<nSrc; i++) srcSliceSize[i] = srcView_[i-1]->getGlobalSize()*srcSliceSize[i-1] ; 104 46 105 vector<size_t> srcGlobalIndex ; 47 106 size_t sliceIndex=0 ; … … 54 113 vector<map<int, set<size_t>>> elements(nSrc) ; // internal representation of elements composing the grid 55 114 56 srcSliceSize[nSrc-1] = srcView_[nSrc-1]->getGlobalSize() ;57 for(int i=nSrc-2 ; i>=0 ; i--) srcSliceSize[i] = srcView_[i]->getGlobalSize()*srcSliceSize[i+1] ;115 // srcSliceSize[nSrc-1] = srcView_[nSrc-1]->getGlobalSize() ; 116 // for(int i=nSrc-2 ; i>=0 ; i--) srcSliceSize[i] = srcView_[i]->getGlobalSize()*srcSliceSize[i+1] ; 58 117 59 118 for(auto& indRanks : returnInfo) … … 61 120 size_t gridIndexGlo=indRanks.first ; 62 121 auto& ranks = indRanks.second ; 63 for(int i= 0;i<nSrc;i++)122 for(int i=nSrc-1; i>=0; i--) 64 123 { 65 124 auto& element = elements[i] ; 66 size_t localIndGlo = gridIndexGlo % srcSliceSize[i] ; 125 size_t localIndGlo = gridIndexGlo / srcSliceSize[i] ; 126 gridIndexGlo = gridIndexGlo % srcSliceSize[i] ; 67 127 for(int rank : ranks) element[rank].insert(localIndGlo) ; 68 128 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/local_view.cpp
r1918 r1930 15 15 } 16 16 17 CLocalView::CLocalView(CLocalElement* parent, CElementView::type type, const CArray<bool,1>& maskView) 18 : CDistributedView( parent, type, {{ parent->localRank_, maskView }} ), 19 localRank_(parent->localRank_), 20 globalIndex_(parent->globalIndex_), size_(CDistributedView::size_[parent->localRank_]), 21 index_(CDistributedView::index_[parent->localRank_]), localSize_(CDistributedView::localSize_[parent->localRank_]) 22 { 23 24 } 17 25 18 26 void CLocalView::sendRemoteElement(CRemoteConnector& connector, CContextClient* client, CEventClient& event, const CMessage& messageHeader) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/local_view.hpp
r1918 r1930 17 17 public: 18 18 CLocalView(CLocalElement* parent, CElementView::type type, const CArray<int,1>& indexView) ; 19 CLocalView(CLocalElement* parent, CElementView::type type, const CArray<bool,1>& maskView) ; 20 19 21 const CArray<int,1>& getIndex(void) { return index_ ;} 20 22 const CArray<size_t,1>& getGlobalIndex(void) { return globalIndex_ ;} 23 24 void getGlobalIndexView(CArray<size_t,1>& globalIndexView) 25 { 26 globalIndexView.resize(size_) ; 27 int pos=0 ; 28 for(int i=0 ; i<size_ ; i++) 29 { 30 if (index_(i)>=0 && index_(i)<localSize_) 31 { 32 globalIndexView(i) = globalIndex_(index_(i)) ; 33 pos++ ; 34 } 35 } 36 globalIndexView.resizeAndPreserve(pos) ; 37 } 21 38 22 39 void getGlobalIndex(vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CLocalView** localView, int pos) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/scatterer_connector.hpp
r1918 r1930 34 34 void computeConnector(void) ; 35 35 36 template<typename T >37 void transfer(const CArray<T, 1>& dataIn, map<int, CArray<T,1>>& dataOut)36 template<typename T, int n> 37 void transfer(const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut) 38 38 { 39 transfer(1, dataIn, dataOut) ; 40 } 41 42 template<typename T, int n> 43 void transfer(const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut, T missingValue) 44 { 45 transfer(1, dataIn, dataOut, missingValue) ; 46 } 47 48 template<typename T, int n> 49 void transfer(int sizeT, const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut) 50 { 51 // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 39 52 for(auto& rankConnector : connector_) 40 53 { … … 44 57 int dstSize = mask.size() ; 45 58 auto& data = dataOut[rank] ; 46 data.resize(dstSize ) ;59 data.resize(dstSize * sizeT) ; 47 60 T* dstData = data.dataFirst() ; 48 61 const T* srcData = dataIn.dataFirst() ; … … 50 63 if (mask[i]) 51 64 { 52 dstData[i] = srcData[connector[j]] ; 65 for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = srcData[connector[j]*sizeT+k] ; 66 j++ ; 67 } 68 } 69 } 70 71 template<typename T, int n> 72 void transfer(int sizeT, const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut, T missingValue) 73 { 74 // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 75 for(auto& rankConnector : connector_) 76 { 77 int rank = rankConnector.first ; 78 auto& connector = rankConnector.second ; 79 auto& mask = mask_[rank] ; 80 int dstSize = mask.size() ; 81 auto& data = dataOut[rank] ; 82 data.resize(dstSize * sizeT) ; 83 T* dstData = data.dataFirst() ; 84 const T* srcData = dataIn.dataFirst() ; 85 for(int i=0, j=0; i<dstSize; i++) 86 if (mask[i]) 87 { 88 for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = srcData[connector[j]*sizeT+k] ; 89 j++ ; 90 } 91 else 92 { 93 for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = missingValue ; 53 94 j++ ; 54 95 } … … 56 97 } 57 98 58 template<typename T> 59 void transfer(const CArray<T,1>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 99 template<typename T,int n> 100 void transfer(const CArray<T,n>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 101 { 102 transfer(1, dataIn, client, event, messageHeader) ; 103 } 104 105 template<typename T,int n> 106 void transfer(const CArray<T,n>& dataIn, T missingValue, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 107 { 108 transfer(1, dataIn, missingValue, client, event, messageHeader) ; 109 } 110 111 template<typename T, int n> 112 void transfer(int sizeT, const CArray<T,n>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 60 113 { 61 114 map<int, CArray<T,1>> dataOut ; 62 transfer(dataIn, dataOut) ; 115 transfer(sizeT, dataIn, dataOut) ; 116 sendToServer(dataOut, client, event, messageHeader) ; 117 } 118 119 template<typename T, int n> 120 void transfer(int sizeT, const CArray<T,n>& dataIn, T missingValue, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 121 { 122 map<int, CArray<T,1>> dataOut ; 123 transfer(sizeT, dataIn, dataOut, missingValue) ; 63 124 sendToServer(dataOut, client, event, messageHeader) ; 64 125 }
Note: See TracChangeset
for help on using the changeset viewer.