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

Last change on this file since 888 was 888, checked in by mhnguyen, 8 years ago

Adding new transformation for scalar: Reducing an axis to a scalar

+) Add new xml node for new transformation
+) Add new algorithms for axis reduction
+) Make change in some place to make sure everything work fine

Test
+) On Curie
+) Tests pass and are correct

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