source: XIOS/dev/dev_olga/src/transformation/generic_algorithm_transformation.hpp @ 1653

Last change on this file since 1653 was 1653, checked in by oabramkina, 5 years ago

Developments for visualization of XIOS workflow.

Branch is spawned from trunk r1649.

Boost library is used for producing Graphviz DOT files. Current results: a DOT file representing a static workflow. For a complete proof of concept, DOT files for each timestamp should be generated. The necessary information has been collected by XIOS, it only requires rearranging the information for graphing (changes in classes CWorkflowGraph and CGraphviz).

File size: 8.4 KB
Line 
1/*!
2   \file generic_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
5   \date 29 June 2015
6
7   \brief Interface for all transformation algorithms.
8 */
9#ifndef __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
10#define __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
11
12#include <map>
13#include <set>
14#include "array_new.hpp"
15#include "client_client_dht_template.hpp"
16
17namespace xios {
18  class CGrid;
19  class CDomain;
20  class CAxis;
21  class CScalar;
22
23  /*!
24  \class CGenericAlgorithmTransformation
25  This class defines the interface for all other inherited algorithms class
26  */
27class CGenericAlgorithmTransformation
28{
29public:
30  enum AlgoTransType {
31    ELEMENT_GENERATION = 0,
32    ELEMENT_MODIFICATION_WITHOUT_DATA = 1,
33    ELEMENT_MODIFICATION_WITH_DATA = 2,
34    ELEMENT_NO_MODIFICATION_WITH_DATA = 3,
35    ELEMENT_NO_MODIFICATION_WITHOUT_DATA = 4
36  } ;
37
38public:
39  // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights
40  typedef std::unordered_map<int, std::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap;
41
42protected:
43  typedef std::unordered_map<size_t,int> GlobalLocalMap;
44protected:
45  typedef std::unordered_map<int, std::vector<int> > TransformationIndexMap;
46  typedef std::unordered_map<int, std::vector<double> > TransformationWeightMap;
47  typedef std::unordered_map<int, std::vector<int> > TransformationPositionMap;
48
49public:
50  CGenericAlgorithmTransformation();
51
52  virtual ~CGenericAlgorithmTransformation() {}
53
54  bool isDistributedTransformation(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst) ;
55
56  void computeGlobalSourceIndex(int elementPositionInGrid,
57                               CGrid* gridSrc,
58                               CGrid* gridDst,
59                               SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
60
61    /*!
62    Apply a operation on local data.
63    \param [in] localIndex vector contains local index of local data output and the corresponding weight
64    \param [in] dataInput Pointer to the first element of data input array (in form of buffer)
65    \param [in/out] dataOut Array contains local data
66    \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization
67    \param [in] ignoreMissingValue don't count missing value in operation if this flag is true
68    \param [in] firstPass indicate if it is the first time the apply funtion is called for a same transformation, in order to make a clean initialization
69  */
70  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
71                     const double* dataInput,
72                     CArray<double,1>& dataOut,
73                     std::vector<bool>& flagInitial,                     
74                     bool ignoreMissingValue, bool firstPass);
75
76  /*!
77   * Update whole dataOut (on necessary).
78   * (Example:  Impose a weight, whose value is only known after being applied an operation, on dataOut)
79   * \param [in/out] dataOut dataOut
80   */
81  virtual void updateData(CArray<double,1>& dataOut);
82
83  std::vector<StdString> getIdAuxInputs();
84  AlgoTransType type();
85  /*!
86  Compute global index mapping from one element of destination grid to the corresponding element of source grid
87  */
88  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
89  void computeTransformationMappingNonDistributed(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst,
90                                                  vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, int& nbLocalIndexOnGridDest);
91  void nonDistributedrecursiveFunct(int currentPos, bool masked, int elementPositionInGrid,  vector< CArray<bool,1>* >& maskSrc, vector< CArray<bool,1>* >& maskDst,
92                                    int& srcInd, int& srcIndCompressed, vector<int>& nIndexSrc,
93                                    int& t, vector<vector<vector<pair<int,double> > > >& dstIndWeight, int currentInd,
94                                    vector<int>& localSrc, vector<int>& localDst, vector<double>& weight) ;
95
96protected:
97  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
98
99  /*!
100  Compute proc which contains global index of an element
101    \param[in] globalElementIndex demanding global index of an element of source grid
102    \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar
103    \param[out] globalElementIndexOnProc Proc contains the demanding global index
104  */
105  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
106                                          int elementType,
107                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
108
109protected:
110  void computeGlobalGridIndexMapping(int elementPositionInGrid,
111                                     const std::vector<int>& srcRank,
112                                     std::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap,
113                                     CGrid* gridDst,
114                                     CGrid* gridSrc,
115                                     std::vector<std::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc,
116                                     SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
117
118  void computeExchangeDomainIndex(CDomain* domainDst,
119                                  CDomain* domainSrc,
120                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
121                                  std::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc);
122
123  void computeExchangeAxisIndex(CAxis* axisDst,
124                                CAxis* axisSrc,
125                                CArray<size_t,1>& destGlobalIndexPositionInGrid,
126                                std::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc);
127
128  void computeExchangeScalarIndex(CScalar* scalarDst,
129                                  CScalar* scalarSrc,
130                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
131                                  std::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc);
132
133  void computePositionElements(CGrid* dst, CGrid* src);
134
135protected:
136  //! indicate if the transformation is performed on a distributed element
137  bool isDistributed_ ;
138  //! indicate if the method  isDistributedTransformation has been called before
139  bool isDistributedComputed_ ;
140 
141  //! Map between global index of destination element and source element
142  std::vector<TransformationIndexMap> transformationMapping_;
143  //! Weight corresponding of source to destination
144  std::vector<TransformationWeightMap> transformationWeight_;
145  //! Map of global index of destination element and corresponding global index of other elements in the same grid
146  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
147  std::vector<TransformationPositionMap> transformationPosition_;
148
149  //! Id of auxillary inputs which helps doing transformation dynamically
150  std::vector<StdString> idAuxInputs_;
151  AlgoTransType type_;
152
153  std::set<StdSize> indexElementSrc_;
154
155  std::vector<std::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc_;
156
157  std::vector<int> procContainSrcElementIdx_;  // List of processes containing source index of transformed elements
158//  std::set<int> procOfNonTransformedElements_; // Processes contain the source index of non-transformed elements
159  std::set<int> commonProc_;
160  std::vector< set<int> > procElementList_ ; // List of processes containing source index of elements
161
162  CClientClientDHTInt::Index2VectorInfoTypeMap globalIndexOfTransformedElementOnProc_;
163 
164  bool computedProcSrcNonTransformedElement_; // Flag to indicate whether we computed proc containing non transformed elements
165
166  std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_;
167  std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_;
168
169  bool eliminateRedondantSrc_ ; // flag to indicate if the transformation must select only one global source point for all proc.
170                               // In this case it will choose preferentially the current process
171};
172
173}
174#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.