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(CDistributedElement* parent, CElementView::type type, const std::map<int,CArray<int,1>>& indexView) ; |
---|
17 | |
---|
18 | std::map<int,CArray<int,1>>& getIndex(void) { return index_ ;} |
---|
19 | std::map<int,CArray<size_t,1>>& getGlobalIndex(void) { return globalIndex_ ;} |
---|
20 | std::map<int, int>& getSize(void) { return size_ ;} |
---|
21 | std::map<int, int>& getLocalSize(void) { return localSize_ ;} |
---|
22 | size_t getGlobalSize(void) { return globalSize_ ;} |
---|
23 | |
---|
24 | void getGlobalIndex(int rank, vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CDistributedView** view, int pos) |
---|
25 | { |
---|
26 | // using map can be expensive, find an otherway later |
---|
27 | auto& globalInd=globalIndex_[rank] ; |
---|
28 | int localSize=globalInd.numElements() ; |
---|
29 | auto& index=index_[rank] ; |
---|
30 | int size=index.numElements() ; |
---|
31 | |
---|
32 | if (pos==0) |
---|
33 | { |
---|
34 | for(int i=0;i<size;i++) |
---|
35 | if (index(i)>=0 && index(i)<localSize) globalIndex.push_back(sliceIndex + globalInd(index(i))) ; |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | for(int i=0;i<size;i++) |
---|
40 | if (index(i)>=0 && index(i)<localSize) |
---|
41 | view[pos-1]->getGlobalIndex(rank, globalIndex, sliceIndex + globalInd(index(i))*sliceSize[pos], sliceSize, view , pos-1) ; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | protected: |
---|
47 | |
---|
48 | std::map<int,CArray<int,1>> index_ ; |
---|
49 | std::map<int, int> size_; |
---|
50 | |
---|
51 | std::map<int,CArray<size_t,1>>& globalIndex_ ; |
---|
52 | size_t& globalSize_ ; |
---|
53 | std::map<int, int>& localSize_ ; |
---|
54 | |
---|
55 | } ; |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | #endif |
---|