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

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

dev_omp

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