[888] | 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 | |
---|
| 16 | namespace xios { |
---|
| 17 | |
---|
| 18 | /*! |
---|
| 19 | \class CReductionAlgorithm |
---|
| 20 | Interface for all reduction alogrithms. |
---|
| 21 | */ |
---|
| 22 | class CReductionAlgorithm |
---|
| 23 | { |
---|
| 24 | public: |
---|
| 25 | static std::map<StdString,EReductionType> ReductionOperations; |
---|
| 26 | |
---|
| 27 | public: |
---|
| 28 | CReductionAlgorithm() {} |
---|
| 29 | |
---|
| 30 | /*! |
---|
| 31 | Create an operation (sum, max, min) based on type |
---|
| 32 | \param [in] reduceType type to create |
---|
| 33 | return pointer to base class |
---|
| 34 | */ |
---|
| 35 | static CReductionAlgorithm* createOperation(EReductionType reduceType); |
---|
| 36 | |
---|
| 37 | /*! |
---|
| 38 | Apply a reduction operation on local data. |
---|
| 39 | \param [in] localIndex vector contains local index of local data output and the corresponding weight |
---|
| 40 | \param [in] dataInput Pointer to the first element of data input array (in form of buffer) |
---|
| 41 | \param [in/out] dataOut Array contains local data |
---|
[979] | 42 | \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initialization |
---|
[1260] | 43 | \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 |
---|
[888] | 44 | */ |
---|
| 45 | virtual void apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
| 46 | const double* dataInput, |
---|
| 47 | CArray<double,1>& dataOut, |
---|
[1158] | 48 | std::vector<bool>& flagInitial, |
---|
[1260] | 49 | bool ignoreMissingValue, bool firstPass) = 0; |
---|
[979] | 50 | /*! |
---|
| 51 | Update local data |
---|
| 52 | In some case (e.g average) we need global information (e.g weights) then update data with this information |
---|
| 53 | \param [in] dataOut local data output |
---|
| 54 | */ |
---|
| 55 | virtual void updateData(CArray<double,1>& dataOut) {} |
---|
[888] | 56 | |
---|
| 57 | virtual ~CReductionAlgorithm() {} |
---|
| 58 | |
---|
| 59 | protected: |
---|
| 60 | typedef CReductionAlgorithm* (*CreateOperationCallBack)(); |
---|
| 61 | typedef std::map<EReductionType, CreateOperationCallBack> CallBackMap; |
---|
| 62 | static CallBackMap* reductionCreationCallBacks_; |
---|
| 63 | |
---|
| 64 | static bool registerOperation(EReductionType reduceType, CreateOperationCallBack createFn); |
---|
| 65 | static bool unregisterOperation(EReductionType reduceType); |
---|
| 66 | |
---|
| 67 | protected: |
---|
| 68 | static bool initReductionOperation(std::map<StdString,EReductionType>& m); |
---|
| 69 | static bool _dummyInit; |
---|
| 70 | }; |
---|
| 71 | |
---|
| 72 | } |
---|
| 73 | #endif // __XIOS_REDUCTION_ALGORITHM_HPP__ |
---|