source: XIOS/dev/dev_trunk_omp/src/transformation/Functions/sum_reduction.cpp @ 1677

Last change on this file since 1677 was 1677, checked in by yushan, 5 years ago

MARK: Dynamic workflow graph developement. Branch up to date with trunk @1663.

File size: 2.0 KB
Line 
1/*!
2   \file sum.cpp
3   \author Ha NGUYEN
4   \since 27 June 2016
5   \date 9 Jan 2017
6
7   \brief sum reduction
8 */
9#include "sum_reduction.hpp"
10#include "utils.hpp"
11
12namespace xios {
13
14CSumReductionAlgorithm::CSumReductionAlgorithm()
15  : CReductionAlgorithm()
16{
17}
18
19CReductionAlgorithm* CSumReductionAlgorithm::create()
20{
21  return (new CSumReductionAlgorithm());
22}
23
24bool CSumReductionAlgorithm::registerTrans()
25{
26  return registerOperation(TRANS_REDUCE_SUM, CSumReductionAlgorithm::create);
27}
28
29void CSumReductionAlgorithm::apply(const std::vector<std::pair<int,double> >& localIndex,
30                                   const double* dataInput,
31                                   CArray<double,1>& dataOut,
32                                   std::vector<bool>& flagInitial,
33                                   bool ignoreMissingValue, bool firstPass)
34{
35  std::cout<<"================================ CSumReductionAlgorithm::apply"<<std::endl;
36  if (ignoreMissingValue)
37  {
38    int nbLocalIndex = localIndex.size();
39    int currentlocalIndex = 0;
40
41    if (firstPass) dataOut=std::numeric_limits<double>::quiet_NaN();
42 
43    for (int idx = 0; idx < nbLocalIndex; ++idx)
44    {
45      currentlocalIndex = localIndex[idx].first;   
46      if (!NumTraits<double>::isNan(*(dataInput + idx)))
47      {   
48        if (flagInitial[currentlocalIndex])
49        {
50          dataOut(currentlocalIndex) = *(dataInput + idx);
51          flagInitial[currentlocalIndex] = false;
52        }
53        else
54        {
55          dataOut(currentlocalIndex) += *(dataInput + idx);
56        }
57      }
58    }   
59  }
60  else
61  {
62    int nbLocalIndex = localIndex.size();
63    int currentlocalIndex = 0;   
64    for (int idx = 0; idx < nbLocalIndex; ++idx)
65    {
66      currentlocalIndex = localIndex[idx].first;     
67      if (flagInitial[currentlocalIndex])
68      {
69        dataOut(currentlocalIndex) = *(dataInput + idx);
70        flagInitial[currentlocalIndex] = false;
71      }
72      else
73      {
74        dataOut(currentlocalIndex) += *(dataInput + idx);
75      }
76    }
77  }
78}
79
80}
Note: See TracBrowser for help on using the repository browser.