1 | #ifndef __DISTRIBUTED_VIEW_HPP__ |
---|
2 | #define __DISTRIBUTED_VIEW_HPP__ |
---|
3 | |
---|
4 | #include "xios_spl.hpp" |
---|
5 | #include "array_new.hpp" |
---|
6 | #include "element_view.hpp" |
---|
7 | |
---|
8 | namespace xios |
---|
9 | { |
---|
10 | class CDistributedElement; |
---|
11 | |
---|
12 | class CDistributedView : public CElementView |
---|
13 | { |
---|
14 | public: |
---|
15 | |
---|
16 | CDistributedView(shared_ptr<CDistributedElement> parent, CElementView::type type, const std::map<int,CArray<int,1>>& indexView) ; |
---|
17 | CDistributedView(shared_ptr<CDistributedElement> parent, CElementView::type type, const std::map<int,CArray<bool,1>>& maskView) ; |
---|
18 | |
---|
19 | std::map<int,CArray<int,1>>& getIndex(void) { return index_ ;} |
---|
20 | std::map<int,CArray<size_t,1>>& getGlobalIndex(void) { return globalIndex_ ;} |
---|
21 | std::map<int, int>& getSize(void) { return size_ ;} |
---|
22 | std::map<int, int>& getLocalSize(void) { return localSize_ ;} |
---|
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 | if (pos==0) globalIndView.resize(pos) ; |
---|
46 | else globalIndView.resizeAndPreserve(pos) ; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | void getGlobalIndex(int rank, vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, shared_ptr<CDistributedView>* view, int pos) |
---|
51 | { |
---|
52 | // using map can be expensive, find an otherway later |
---|
53 | auto& globalInd=globalIndex_[rank] ; |
---|
54 | int localSize=globalInd.numElements() ; |
---|
55 | auto& index=index_[rank] ; |
---|
56 | int size=index.numElements() ; |
---|
57 | |
---|
58 | if (pos==0) |
---|
59 | { |
---|
60 | for(int i=0;i<size;i++) |
---|
61 | if (index(i)>=0 && index(i)<localSize) globalIndex.push_back(sliceIndex + globalInd(index(i))) ; |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | for(int i=0;i<size;i++) |
---|
66 | if (index(i)>=0 && index(i)<localSize) |
---|
67 | view[pos-1]->getGlobalIndex(rank, globalIndex, sliceIndex + globalInd(index(i))*sliceSize[pos], sliceSize, view , pos-1) ; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | protected: |
---|
73 | |
---|
74 | std::map<int,CArray<int,1>> index_ ; |
---|
75 | std::map<int, int> size_; |
---|
76 | |
---|
77 | std::map<int,CArray<size_t,1>>& globalIndex_ ; |
---|
78 | size_t& globalSize_ ; |
---|
79 | std::map<int, int>& localSize_ ; |
---|
80 | |
---|
81 | } ; |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | #endif |
---|