source: XIOS/dev/branch_openmp/src/transformation/Functions/reduction.hpp @ 1460

Last change on this file since 1460 was 1460, checked in by yushan, 6 years ago

branch_openmp merged with XIOS_DEV_CMIP6@1459

File size: 2.7 KB
Line 
1/*!
2   \file reduction.hpp
3   \author Ha NGUYEN
4   \since 27 June 2016
5   \date 27 June 2016
6
7   \brief Parent class for all reduction
8 */
9#ifndef __XIOS_REDUCTION_ALGORITHM_HPP__
10#define __XIOS_REDUCTION_ALGORITHM_HPP__
11
12#include <vector>
13#include "array_new.hpp"
14#include "reduction_types.hpp"
15
16namespace xios {
17
18/*!
19  \class CReductionAlgorithm
20  Interface for all reduction alogrithms.
21*/
22class CReductionAlgorithm
23{
24public:
25  //static std::map<StdString,EReductionType> ReductionOperations;
26  static std::map<StdString,EReductionType> *ReductionOperations_ptr;
27  #pragma omp threadprivate(ReductionOperations_ptr)
28public:
29  CReductionAlgorithm() {}
30
31  /*!
32    Create an operation (sum, max, min) based on type
33    \param [in] reduceType type to create
34    return pointer to base class
35  */
36  static CReductionAlgorithm* createOperation(EReductionType reduceType);
37
38  /*!
39    Apply a reduction operation on local data.
40    \param [in] localIndex vector contains local index of local data output and the corresponding weight
41    \param [in] dataInput Pointer to the first element of data input array (in form of buffer)
42    \param [in/out] dataOut Array contains local data
43    \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initialization
44    \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
45  */
46  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
47                     const double* dataInput,
48                     CArray<double,1>& dataOut,
49                     std::vector<bool>& flagInitial,                     
50                     bool ignoreMissingValue, bool firstPass) = 0;
51  /*!
52    Update local data
53    In some case (e.g average) we need global information (e.g weights) then update data with this information
54    \param [in] dataOut local data output
55  */
56  virtual void updateData(CArray<double,1>& dataOut) {}
57
58  virtual ~CReductionAlgorithm() {}
59
60protected:
61  typedef CReductionAlgorithm* (*CreateOperationCallBack)();
62  typedef std::map<EReductionType, CreateOperationCallBack> CallBackMap;
63  static CallBackMap* reductionCreationCallBacks_;
64  #pragma omp threadprivate(reductionCreationCallBacks_)
65
66  static bool registerOperation(EReductionType reduceType, CreateOperationCallBack createFn);
67  static bool unregisterOperation(EReductionType reduceType);
68
69protected:
70  static bool initReductionOperation(std::map<StdString,EReductionType>& m);
71  static bool initReductionOperation();
72  static bool _dummyInit;
73  #pragma omp threadprivate(_dummyInit)
74};
75
76}
77#endif // __XIOS_REDUCTION_ALGORITHM_HPP__
Note: See TracBrowser for help on using the repository browser.