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 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
50 #ifndef _ZOLTAN2_MultiJagged_ReductionOps_HPP_
51 #define _ZOLTAN2_MultiJagged_ReductionOps_HPP_
52 
53 #include <Teuchos_ReductionOp.hpp>
54 
55 namespace Teuchos{
56 template <typename Ordinal, typename T>
57 class MultiJaggedCombinedReductionOp : public ValueTypeReductionOp<Ordinal,T>
58 {
59 private:
60  Ordinal numSum_0, numMin_1, numMin_2;
61  std::vector <Ordinal> *partVector;
62  Ordinal vectorBegin;
63  Ordinal k;
64  int reductionType;
65 
66 public:
69  MultiJaggedCombinedReductionOp ():numSum_0(0), numMin_1(0),
70  numMin_2(0), k(0), partVector(NULL), vectorBegin(0), reductionType(0){}
71 
78  MultiJaggedCombinedReductionOp (Ordinal nsum, Ordinal nmin1, Ordinal nmin2,
79  Ordinal k_):
80  numSum_0(nsum), numMin_1(nmin1), numMin_2(nmin2), partVector(NULL),
81  vectorBegin(0), k(k_), reductionType(0){}
82 
83 
84  MultiJaggedCombinedReductionOp (std::vector <Ordinal> *pVector, Ordinal vBegin,
85  Ordinal k_):
86  numSum_0(0), numMin_1(0), numMin_2(0), partVector(pVector),
87  vectorBegin(vBegin), k(k_), reductionType(1){}
88 
89 
92  void reduce( const Ordinal /* count */, const T inBuffer[], T inoutBuffer[]) const
93  {
94  if (reductionType == 0){
95  Ordinal next=0;
96  for(Ordinal ii = 0; ii < k ; ++ii){
97  for (Ordinal i=0; i < numSum_0; i++, next++)
98  inoutBuffer[next] += inBuffer[next];
99 
100  for (Ordinal i=0; i < numMin_1; i++, next++)
101  if (inoutBuffer[next] < inBuffer[next])
102  inoutBuffer[next] = inBuffer[next];
103 
104  for (Ordinal i=0; i < numMin_2; i++, next++)
105  if (inoutBuffer[next] > inBuffer[next])
106  inoutBuffer[next] = inBuffer[next];
107  }
108  }
109  else {
110  Ordinal next=0;
111  for(Ordinal ii = 0; ii < k ; ++ii){
112  Ordinal partPartition = (*partVector)[ii + vectorBegin];
113  Ordinal tnumSum_ = 2 * partPartition - 1;
114  Ordinal tnumMin_1 = partPartition - 1;
115  Ordinal tnumMin_2 = tnumMin_1 ;
116  for (Ordinal i=0; i < tnumSum_; i++, next++)
117  inoutBuffer[next] += inBuffer[next];
118 
119  for (Ordinal i=0; i < tnumMin_1; i++, next++)
120  if (inoutBuffer[next] < inBuffer[next])
121  inoutBuffer[next] = inBuffer[next];
122 
123  for (Ordinal i=0; i < tnumMin_2; i++, next++)
124  if (inoutBuffer[next] > inBuffer[next])
125  inoutBuffer[next] = inBuffer[next];
126  }
127  }
128  }
129 };
130 
131 
132 template <typename Ordinal, typename T>
134  public ValueTypeReductionOp<Ordinal,T>
135 {
136 private:
137  Ordinal numMin, numMax, numTotal;
138 
139 public:
142  MultiJaggedCombinedMinMaxTotalReductionOp ():numMin(0), numMax(0), numTotal(0)
143  {}
144 
151  MultiJaggedCombinedMinMaxTotalReductionOp (Ordinal nmin, Ordinal nmax, Ordinal
152  nTotal): numMin(nmin), numMax(nmax), numTotal(nTotal){}
153 
156  void reduce( const Ordinal /* count */, const T inBuffer[], T inoutBuffer[]) const
157  {
158  Ordinal next=0;
159 
160  for (Ordinal i=0; i < numMin; i++, next++)
161  if (inoutBuffer[next] > inBuffer[next])
162  inoutBuffer[next] = inBuffer[next];
163 
164  for (Ordinal i=0; i < numMax; i++, next++)
165  if (inoutBuffer[next] < inBuffer[next])
166  inoutBuffer[next] = inBuffer[next];
167 
168 
169  for (Ordinal i=0; i < numTotal; i++, next++)
170  inoutBuffer[next] += inBuffer[next];
171  }
172 };
173 } // namespace Teuchos
174 
175 #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.