source: XIOS/dev/dev_trunk_omp/src/transformation/Functions/min_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 min.cpp
3   \author Ha NGUYEN
4   \since 27 June 2016
5   \date 9 Jan 2017
6
7   \brief min reduction
8 */
9#include "min_reduction.hpp"
10#include "utils.hpp"
11
12namespace xios {
13
14CMinReductionAlgorithm::CMinReductionAlgorithm()
15  : CReductionAlgorithm()
16{
17}
18
19CReductionAlgorithm* CMinReductionAlgorithm::create()
20{
21  return (new CMinReductionAlgorithm());
22}
23
24bool CMinReductionAlgorithm::registerTrans()
25{
26  return registerOperation(TRANS_REDUCE_MIN, CMinReductionAlgorithm::create);
27}
28
29void CMinReductionAlgorithm::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<<"================================ CMinReductionAlgorithm::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::min(*(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::min(*(dataInput + idx), dataOut(currentlocalIndex));
73      }
74    }
75  }
76}
77
78}
Note: See TracBrowser for help on using the repository browser.