source: XIOS/dev/dev_trunk_omp/src/transformation/Functions/max_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.1 KB
Line 
1/*!
2   \file max.cpp
3   \author Ha NGUYEN
4   \since 27 June 2016
5   \date 27 June 2016
6
7   \brief max reduction
8 */
9#include "max_reduction.hpp"
10#include "utils.hpp"
11
12namespace xios {
13
14CMaxReductionAlgorithm::CMaxReductionAlgorithm()
15  : CReductionAlgorithm()
16{
17}
18
19CReductionAlgorithm* CMaxReductionAlgorithm::create()
20{
21  return (new CMaxReductionAlgorithm());
22}
23
24bool CMaxReductionAlgorithm::registerTrans()
25{
26  return registerOperation(TRANS_REDUCE_MAX, CMaxReductionAlgorithm::create);
27}
28
29void CMaxReductionAlgorithm::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<<"================================ CMaxReductionAlgorithm::apply"<<std::endl;
36  if (ignoreMissingValue)
37  {
38    int nbLocalIndex = localIndex.size();
39    int currentlocalIndex = 0;
40    if (firstPass) dataOut=std::numeric_limits<double>::quiet_NaN();   
41    for (int idx = 0; idx < nbLocalIndex; ++idx)
42    {
43      currentlocalIndex = localIndex[idx].first;     
44      if (!NumTraits<double>::isNan(*(dataInput + idx)))
45      {
46        if (flagInitial[currentlocalIndex])
47        {
48          dataOut(currentlocalIndex) = *(dataInput + idx);
49          flagInitial[currentlocalIndex] = false;
50        }
51        else
52        {
53          dataOut(currentlocalIndex) = std::max(*(dataInput + idx), dataOut(currentlocalIndex));
54        }
55      }
56    }
57  }
58  else
59  {
60    int nbLocalIndex = localIndex.size();
61    int currentlocalIndex = 0;   
62    for (int idx = 0; idx < nbLocalIndex; ++idx)
63    {
64      currentlocalIndex = localIndex[idx].first;     
65      if (flagInitial[currentlocalIndex])
66      {
67        dataOut(currentlocalIndex) = *(dataInput + idx);
68        flagInitial[currentlocalIndex] = false;
69      }
70      else
71      {
72        dataOut(currentlocalIndex) = std::max(*(dataInput + idx), dataOut(currentlocalIndex));
73      }
74    }
75  }
76}
77
78}
Note: See TracBrowser for help on using the repository browser.