source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/distributed_view.hpp @ 1930

Last change on this file since 1930 was 1930, checked in by ymipsl, 4 years ago

Big update on on going work related to data distribution and transfer between clients and servers.
Revisite of the source and store filter using "connectors".

YM

  • Property svn:executable set to *
File size: 2.7 KB
Line 
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
8namespace 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      CDistributedView(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          globalIndView.resizeAndPreserve(pos) ;
46      }
47    }   
48
49      void getGlobalIndex(int rank, vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CDistributedView** view, int pos)
50      {
51        // using map can be expensive, find an otherway later
52        auto& globalInd=globalIndex_[rank] ;
53        int localSize=globalInd.numElements() ;
54        auto& index=index_[rank] ;
55        int size=index.numElements() ;
56               
57        if (pos==0)
58        {
59          for(int i=0;i<size;i++)
60            if (index(i)>=0 && index(i)<localSize) globalIndex.push_back(sliceIndex + globalInd(index(i))) ;
61        }
62        else 
63        {
64          for(int i=0;i<size;i++)
65            if (index(i)>=0 && index(i)<localSize) 
66              view[pos-1]->getGlobalIndex(rank, globalIndex, sliceIndex + globalInd(index(i))*sliceSize[pos], sliceSize, view , pos-1) ;
67        }
68      }
69
70
71    protected:
72
73      std::map<int,CArray<int,1>> index_ ;
74      std::map<int, int> size_;
75
76      std::map<int,CArray<size_t,1>>& globalIndex_ ; 
77      size_t& globalSize_ ;
78      std::map<int, int>& localSize_ ;
79   
80  } ;
81
82}
83
84#endif
Note: See TracBrowser for help on using the repository browser.