source: XIOS/dev/branch_openmp/src/transformation/Functions/reduction.cpp @ 1339

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

dev_omp OK

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