source: XIOS/dev/branch_yushan_merged/src/transformation/Functions/reduction.cpp @ 1155

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

test_remap OK with openmp

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