source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.hpp @ 1918

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

Big update on on going work related to data distribution and transfer between clients and servers.

  • move all related file into distribution directorie
  • implement the concept of data "View"
  • implement the concept of "connector" which make the data transfer between 2 differents "Views"

YM

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#ifndef __GATHERER_CONNECTOR_HPP__
2#define __GATHERER_CONNECTOR_HPP__
3
4#include "xios_spl.hpp"
5#include "array_new.hpp"
6#include "distributed_view.hpp"
7#include "mpi.hpp"
8#include "local_view.hpp"
9#include "distributed_view.hpp"
10#include "context_client.hpp"
11
12
13namespace xios
14{
15 
16  class CGathererConnector
17  {
18    private:
19      CDistributedView* srcView_;
20      CLocalView* dstView_;
21      map<int, vector<int>> connector_ ;
22      map<int, vector<bool>> mask_ ;  // mask is on src view
23      int dstSize_ ; 
24      map<int,int> srcSize_ ;
25
26    public:
27      CGathererConnector(CDistributedView* srcView, CLocalView* dstView) : srcView_(srcView), dstView_(dstView) {} ;
28      void computeConnector(void) ;
29     
30      template<typename T>
31      void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut)
32      {
33        dataOut.resize(dstSize_) ;
34        T* output = dataOut.dataFirst() ;
35        for(auto& data : dataIn)
36        {
37          int rank=data.first ;
38          auto input  = data.second.dataFirst() ;
39          auto& connector=connector_[rank] ;
40          auto& mask=mask_[rank] ;
41          int size=data.second.numElements() ;
42
43          for(int i=0, j=0 ;i<size;i++)
44          {
45            if (mask[i]) 
46            {
47              output[connector[j]] = input[i] ;
48              j++ ;
49            }
50          }
51        }
52      }
53   
54
55      template<typename T>
56      void transfer(int rank,  CGathererConnector** connectors, int nConnectors, const T* input, T* output)
57      {
58        auto& connector = connector_[rank] ; // probably costly, find a better way to avoid the map
59        auto& mask = mask_[rank] ; 
60        int srcSize = mask.size() ;
61     
62        if (nConnectors==0)
63        {
64          for(int i=0, j=0; i<srcSize; i++)
65            if (mask[i]) 
66            {
67              *(output+connector[j]) = *(input + i) ;
68              j++ ;
69            }
70
71        }
72        else
73       {
74          int srcSliceSize = (*(connectors-1))->getSrcSliceSize(rank, connectors-1, nConnectors-1) ;
75          int dstSliceSize = (*(connectors-1))->getDstSliceSize(connectors-1, nConnectors-1) ;
76
77          const T* in = input ; 
78          for(int i=0,j=0;i<srcSize;i++) 
79          {
80            if (mask[i]) 
81            {
82              (*(connectors-1))->transfer(rank, connectors-1, nConnectors-1, in, output+connector[j]*dstSliceSize) ; // the multiplication must be avoid in further optimization
83              j++ ;
84            }
85            in += srcSliceSize ;
86          }
87        }
88
89      }
90
91
92      template<typename T>
93      void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue)
94      {
95        dataOut.resize(dstSize_) ;
96        dataOut=missingValue ;
97        transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) ;
98      }
99     
100      template<typename T>
101      void transfer(CEventServer& event, CArray<T,1>& dataOut)
102      {
103        map<int, CArray<T,1>> dataIn ;
104        for (auto& subEvent : event.subEvents) 
105        {
106          auto& data = dataIn[subEvent.rank]; 
107          (*subEvent.buffer) >> data ;
108        }
109        transfer(dataIn, dataOut) ;
110      }
111
112      template<typename T>
113      void transfer(CEventServer& event, CArray<T,1>& dataOut, T missingValue)
114      {
115        map<int, CArray<T,1>> dataIn ;
116        for (auto& subEvent : event.subEvents) 
117        {
118          auto& data = dataIn[subEvent.rank]; 
119          (*subEvent.buffer) >> data ;
120        }
121        transfer(dataIn, dataOut, missingValue) ;
122      }
123
124    int getSrcSliceSize(int rank, CGathererConnector** connectors, int nConnectors) 
125    { if (nConnectors==0) return srcSize_[rank] ; else return srcSize_[rank] * (*(connectors-1))->getSrcSliceSize(rank, connectors-1,nConnectors-1) ; }
126
127    int getDstSliceSize(CGathererConnector** connectors, int nConnectors) 
128    { if (nConnectors==0) return dstSize_ ; else return dstSize_ * (*(connectors-1))->getDstSliceSize(connectors-1,nConnectors-1) ; }
129 
130    int getDstSize(void) {return dstSize_ ;}
131  } ;
132
133}
134
135#endif
Note: See TracBrowser for help on using the repository browser.