source: XIOS/dev/branch_yushan/src/transformation/Functions/reduction.cpp @ 1109

Last change on this file since 1109 was 1109, checked in by yushan, 7 years ago

test_omp OK

File size: 3.1 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;
11//std::map<StdString,EReductionType> CReductionAlgorithm::ReductionOperations = std::map<StdString,EReductionType>();
12std::map<StdString,EReductionType> *CReductionAlgorithm::ReductionOperations_ptr = 0; 
13
14bool CReductionAlgorithm::initReductionOperation(std::map<StdString,EReductionType>& m)
15{
16  // So so stupid way to intialize operation but it works ...
17  m["sum"] = TRANS_REDUCE_SUM;
18  CSumReductionAlgorithm::registerTrans();
19
20  m["min"] = TRANS_REDUCE_MIN;
21  CMinReductionAlgorithm::registerTrans();
22
23  m["max"] = TRANS_REDUCE_MAX;
24  CMaxReductionAlgorithm::registerTrans();
25
26  m["extract"] = TRANS_REDUCE_EXTRACT;
27  CExtractReductionAlgorithm::registerTrans();
28
29  m["average"] = TRANS_REDUCE_AVERAGE;
30  CAverageReductionAlgorithm::registerTrans();
31}
32
33
34bool CReductionAlgorithm::initReductionOperation()
35{
36  if(CReductionAlgorithm::ReductionOperations_ptr == NULL) CReductionAlgorithm::ReductionOperations_ptr = new std::map<StdString,EReductionType>();
37  // So so stupid way to intialize operation but it works ...
38  (*CReductionAlgorithm::ReductionOperations_ptr)["sum"] = TRANS_REDUCE_SUM;
39  CSumReductionAlgorithm::registerTrans();
40
41  (*CReductionAlgorithm::ReductionOperations_ptr)["min"] = TRANS_REDUCE_MIN;
42  CMinReductionAlgorithm::registerTrans();
43
44  (*CReductionAlgorithm::ReductionOperations_ptr)["max"] = TRANS_REDUCE_MAX;
45  CMaxReductionAlgorithm::registerTrans();
46
47  (*CReductionAlgorithm::ReductionOperations_ptr)["extract"] = TRANS_REDUCE_EXTRACT;
48  CExtractReductionAlgorithm::registerTrans();
49
50  (*CReductionAlgorithm::ReductionOperations_ptr)["average"] = TRANS_REDUCE_AVERAGE;
51  CAverageReductionAlgorithm::registerTrans();
52}
53
54//bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations);
55bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation();
56
57CReductionAlgorithm* CReductionAlgorithm::createOperation(EReductionType reduceType)
58{
59  int reduceTypeInt = reduceType;
60  //if (0 == reductionCreationCallBacks_)
61  //  reductionCreationCallBacks_ = new CallBackMap();
62
63  CallBackMap::const_iterator it = (*reductionCreationCallBacks_).find(reduceType);
64  if ((*reductionCreationCallBacks_).end() == it)
65  {
66     ERROR("CReductionAlgorithm::createOperation(EReductionType reduceType)",
67           << "Operation type " << reduceType
68           << "doesn't exist. Please define.");
69  }
70  return (it->second)();
71}
72
73bool CReductionAlgorithm::registerOperation(EReductionType reduceType, CreateOperationCallBack createFn)
74{
75  if (0 == reductionCreationCallBacks_)
76    reductionCreationCallBacks_ = new CallBackMap();
77
78  return (*reductionCreationCallBacks_).insert(make_pair(reduceType, createFn)).second;
79}
80
81bool CReductionAlgorithm::unregisterOperation(EReductionType reduceType)
82{
83  int reduceTypeInt = reduceType;
84  return (1 == (*reductionCreationCallBacks_).erase(reduceType));
85}
86
87
88}
Note: See TracBrowser for help on using the repository browser.