source: XIOS/trunk/src/transformation/Functions/reduction.cpp @ 1261

Last change on this file since 1261 was 979, checked in by mhnguyen, 5 years ago

Implementing AVERAGE operation

+) Add average operation for reduction transformation

Test
+) On Curie
+) Correct

File size: 2.0 KB
Line 
1#include "reduction.hpp"
2#include "sum_reduction.hpp"
3#include "min_reduction.hpp"
4#include "max_reduction.hpp"
5#include "extract.hpp"
6#include "average_reduction.hpp"
7
8namespace xios {
9
10CReductionAlgorithm::CallBackMap* CReductionAlgorithm::reductionCreationCallBacks_ = 0;
11std::map<StdString,EReductionType> CReductionAlgorithm::ReductionOperations = std::map<StdString,EReductionType>();
12bool CReductionAlgorithm::initReductionOperation(std::map<StdString,EReductionType>& m)
13{
14  // So so stupid way to intialize operation but it works ...
15  m["sum"] = TRANS_REDUCE_SUM;
16  CSumReductionAlgorithm::registerTrans();
17
18  m["min"] = TRANS_REDUCE_MIN;
19  CMinReductionAlgorithm::registerTrans();
20
21  m["max"] = TRANS_REDUCE_MAX;
22  CMaxReductionAlgorithm::registerTrans();
23
24  m["extract"] = TRANS_REDUCE_EXTRACT;
25  CExtractReductionAlgorithm::registerTrans();
26
27  m["average"] = TRANS_REDUCE_AVERAGE;
28  CAverageReductionAlgorithm::registerTrans();
29}
30
31bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations);
32
33CReductionAlgorithm* CReductionAlgorithm::createOperation(EReductionType reduceType)
34{
35  int reduceTypeInt = reduceType;
36  CallBackMap::const_iterator it = (*reductionCreationCallBacks_).find(reduceType);
37  if ((*reductionCreationCallBacks_).end() == it)
38  {
39     ERROR("CReductionAlgorithm::createOperation(EReductionType reduceType)",
40           << "Operation type " << reduceType
41           << "doesn't exist. Please define.");
42  }
43  return (it->second)();
44}
45
46bool CReductionAlgorithm::registerOperation(EReductionType reduceType, CreateOperationCallBack createFn)
47{
48  if (0 == reductionCreationCallBacks_)
49    reductionCreationCallBacks_ = new CallBackMap();
50
51  return (*reductionCreationCallBacks_).insert(make_pair(reduceType, createFn)).second;
52}
53
54bool CReductionAlgorithm::unregisterOperation(EReductionType reduceType)
55{
56  int reduceTypeInt = reduceType;
57  return (1 == (*reductionCreationCallBacks_).erase(reduceType));
58}
59
60
61}
Note: See TracBrowser for help on using the repository browser.