source: XIOS/trunk/src/transformation/scalar_algorithm_reduce_axis.cpp @ 888

Last change on this file since 888 was 888, checked in by mhnguyen, 5 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: 2.6 KB
Line 
1/*!
2   \file scalar_algorithm_reduce_scalar.cpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 June 2016
6
7   \brief Algorithm for reduce an axis to a scalar
8 */
9#include "scalar_algorithm_reduce_axis.hpp"
10//#include "context.hpp"
11//#include "context_client.hpp"
12//#include "client_client_dht_template.hpp"
13#include "axis.hpp"
14#include "scalar.hpp"
15#include "reduce_axis_to_scalar.hpp"
16#include "sum.hpp"
17
18namespace xios {
19
20CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CAxis* axisSource, CReduceAxisToScalar* algo)
21 : CScalarAlgorithmTransformation(scalarDestination, axisSource),
22   reduction_(0)
23{
24  if (algo->operation.isEmpty())
25    ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)",
26           << "Operation must be defined."
27           << "Axis source " <<axisSource->getId() << std::endl
28           << "Scalar destination " << scalarDestination->getId());
29  StdString op = algo->operation;
30  if (CReductionAlgorithm::ReductionOperations.end() == CReductionAlgorithm::ReductionOperations.find(op))
31    ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)",
32       << "Operation '" << op << "' not found. Please make sure to use a supported one"
33       << "Axis source " <<axisSource->getId() << std::endl
34       << "Scalar destination " << scalarDestination->getId());
35
36  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
37}
38
39void CScalarAlgorithmReduceScalar::apply(const std::vector<std::pair<int,double> >& localIndex,
40                                         const double* dataInput,
41                                         CArray<double,1>& dataOut,
42                                         std::vector<bool>& flagInitial)
43{
44  reduction_->apply(localIndex, dataInput, dataOut, flagInitial);
45}
46
47CScalarAlgorithmReduceScalar::~CScalarAlgorithmReduceScalar()
48{
49  if (0 != reduction_) delete reduction_;
50}
51
52void CScalarAlgorithmReduceScalar::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
53{
54  this->transformationMapping_.resize(1);
55  this->transformationWeight_.resize(1);
56
57  TransformationIndexMap& transMap = this->transformationMapping_[0];
58  TransformationWeightMap& transWeight = this->transformationWeight_[0];
59
60  CArray<int,1>& axisSrcIndex = axisSrc_->index;
61  int globalIndexSize = axisSrcIndex.numElements();
62
63  for (int idx = 0; idx < globalIndexSize; ++idx)
64  {
65    transMap[0].push_back(axisSrcIndex(idx));
66    transWeight[0].push_back(1.0);
67  }
68}
69
70}
Note: See TracBrowser for help on using the repository browser.