Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_MultiJagged_ReductionOps.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #ifndef _ZOLTAN2_MultiJagged_ReductionOps_HPP_
15 #define _ZOLTAN2_MultiJagged_ReductionOps_HPP_
16 
17 #include <Teuchos_ReductionOp.hpp>
18 
19 namespace Teuchos{
20 template <typename Ordinal, typename T>
21 class MultiJaggedCombinedReductionOp : public ValueTypeReductionOp<Ordinal,T>
22 {
23 private:
24  Ordinal numSum_0, numMin_1, numMin_2;
25  std::vector <Ordinal> *partVector;
26  Ordinal vectorBegin;
27  Ordinal k;
28  int reductionType;
29 
30 public:
33  MultiJaggedCombinedReductionOp ():numSum_0(0), numMin_1(0),
34  numMin_2(0), k(0), partVector(NULL), vectorBegin(0), reductionType(0){}
35 
42  MultiJaggedCombinedReductionOp (Ordinal nsum, Ordinal nmin1, Ordinal nmin2,
43  Ordinal k_):
44  numSum_0(nsum), numMin_1(nmin1), numMin_2(nmin2), partVector(NULL),
45  vectorBegin(0), k(k_), reductionType(0){}
46 
47 
48  MultiJaggedCombinedReductionOp (std::vector <Ordinal> *pVector, Ordinal vBegin,
49  Ordinal k_):
50  numSum_0(0), numMin_1(0), numMin_2(0), partVector(pVector),
51  vectorBegin(vBegin), k(k_), reductionType(1){}
52 
53 
56  void reduce( const Ordinal /* count */, const T inBuffer[], T inoutBuffer[]) const
57  {
58  if (reductionType == 0){
59  Ordinal next=0;
60  for(Ordinal ii = 0; ii < k ; ++ii){
61  for (Ordinal i=0; i < numSum_0; i++, next++)
62  inoutBuffer[next] += inBuffer[next];
63 
64  for (Ordinal i=0; i < numMin_1; i++, next++)
65  if (inoutBuffer[next] < inBuffer[next])
66  inoutBuffer[next] = inBuffer[next];
67 
68  for (Ordinal i=0; i < numMin_2; i++, next++)
69  if (inoutBuffer[next] > inBuffer[next])
70  inoutBuffer[next] = inBuffer[next];
71  }
72  }
73  else {
74  Ordinal next=0;
75  for(Ordinal ii = 0; ii < k ; ++ii){
76  Ordinal partPartition = (*partVector)[ii + vectorBegin];
77  Ordinal tnumSum_ = 2 * partPartition - 1;
78  Ordinal tnumMin_1 = partPartition - 1;
79  Ordinal tnumMin_2 = tnumMin_1 ;
80  for (Ordinal i=0; i < tnumSum_; i++, next++)
81  inoutBuffer[next] += inBuffer[next];
82 
83  for (Ordinal i=0; i < tnumMin_1; i++, next++)
84  if (inoutBuffer[next] < inBuffer[next])
85  inoutBuffer[next] = inBuffer[next];
86 
87  for (Ordinal i=0; i < tnumMin_2; i++, next++)
88  if (inoutBuffer[next] > inBuffer[next])
89  inoutBuffer[next] = inBuffer[next];
90  }
91  }
92  }
93 };
94 
95 
96 template <typename Ordinal, typename T>
98  public ValueTypeReductionOp<Ordinal,T>
99 {
100 private:
101  Ordinal numMin, numMax, numTotal;
102 
103 public:
106  MultiJaggedCombinedMinMaxTotalReductionOp ():numMin(0), numMax(0), numTotal(0)
107  {}
108 
115  MultiJaggedCombinedMinMaxTotalReductionOp (Ordinal nmin, Ordinal nmax, Ordinal
116  nTotal): numMin(nmin), numMax(nmax), numTotal(nTotal){}
117 
120  void reduce( const Ordinal /* count */, const T inBuffer[], T inoutBuffer[]) const
121  {
122  Ordinal next=0;
123 
124  for (Ordinal i=0; i < numMin; i++, next++)
125  if (inoutBuffer[next] > inBuffer[next])
126  inoutBuffer[next] = inBuffer[next];
127 
128  for (Ordinal i=0; i < numMax; i++, next++)
129  if (inoutBuffer[next] < inBuffer[next])
130  inoutBuffer[next] = inBuffer[next];
131 
132 
133  for (Ordinal i=0; i < numTotal; i++, next++)
134  inoutBuffer[next] += inBuffer[next];
135  }
136 };
137 } // namespace Teuchos
138 
139 #endif //_ZOLTAN2_MultiJagged_ReductionOps_HPP_
void reduce(const Ordinal, const T inBuffer[], T inoutBuffer[]) const
Implement Teuchos::ValueTypeReductionOp interface.
void reduce(const Ordinal, const T inBuffer[], T inoutBuffer[]) const
Implement Teuchos::ValueTypeReductionOp interface.
MultiJaggedCombinedReductionOp(std::vector< Ordinal > *pVector, Ordinal vBegin, Ordinal k_)
MultiJaggedCombinedReductionOp(Ordinal nsum, Ordinal nmin1, Ordinal nmin2, Ordinal k_)
Constructor.
MultiJaggedCombinedMinMaxTotalReductionOp(Ordinal nmin, Ordinal nmax, Ordinal nTotal)
Constructor.