OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ReductionLoc.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef REDUCTION_LOC_H
12 #define REDUCTION_LOC_H
13 
14 // include files
15 #include "PETE/IpplExpressions.h"
16 
17 // forward declarations
18 template<unsigned D> class NDIndex;
19 template<class T, unsigned int D> class BareFieldIterator;
20 template<class T, unsigned int D> class IndexedBareFieldIterator;
21 
23 
24 // Fundamental reduction function for minloc and maxloc
25 
26 template<class T, class CompOp, class AccOp, unsigned D>
27 typename T::PETE_Return_t
28 Reduction(const PETE_Expr<T>& const_expr,
29  CompOp comp_op,
30  AccOp acc_op,
31  NDIndex<D>& loc);
32 
33 // Struct for saving current location
34 
35 template <unsigned int D>
37 {
38  typedef int PETE_Return_t;
40  FindLocation(NDIndex<D>& loc) : Loc(&loc) {}
41 };
42 
43 // Behavior of this struct
44 
45 template <class T, class C, unsigned int D>
46 inline int
48  FindLocation<D>& find_loc, C)
49 {
50  int loc[D];
51  expr.GetCurrentLocation(loc);
52  for (unsigned d=0; d<D; d++) (*(find_loc.Loc))[d] = Index(loc[d],loc[d]);
53  return 0;
54 }
55 
56 template <class T, class C, unsigned int D>
57 inline int
59 {
60  int loc[D];
61  expr.GetCurrentLocation(loc);
62  for (unsigned d=0; d<D; d++) (*(find_loc.Loc))[d] = Index(loc[d],loc[d]);
63  return 0;
64 }
65 
67 //
68 // Minloc and Maxloc require slightly different functionality.
69 // They need to keep track of the location in addition to finding
70 // the min and max.
71 //
73 
74 #ifdef __MWERKS__
75 // Workaround for CodeWarrior 4 bug
76 // Funny "MMMin" name is to avoid conflict with Min defined elsewhere in r1,
77 // and "MMin defined iin IpplExpressions.h.
78 template<class T, unsigned D>
79 struct MMMin {
80  typedef typename T::PETE_Expr_t::PETE_Return_t type_t;
81  static inline type_t apply(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
82  return Reduction(Expressionize<typename T::PETE_Expr_t>::apply( expr.PETE_unwrap().MakeExpression() ),
83  OpLT(), OpMinAssign(),loc);
84  }
85 };
86 
87 template<class T, unsigned D>
88 inline typename MMMin<T,D>::type_t
89 min(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
90  return MMMin<T,D>::apply(expr, loc);
91 }
92 #else
93 template<class T, unsigned D>
94 inline typename T::PETE_Expr_t::PETE_Return_t
95 min(const PETE_Expr<T>& expr, NDIndex<D>& loc)
96 {
98  OpLT(),OpMinAssign(),loc);
99 }
100 #endif // __MWERKS__
101 
102 #ifdef __MWERKS__
103 // Workaround for CodeWarrior 4 bug
104 // Funny "MMMax" name is to avoid conflict with Max defined elsewhere in r1,
105 // and "MMax defined iin IpplExpressions.h.
106 template<class T, unsigned D>
107 struct MMMax {
108  typedef typename T::PETE_Expr_t::PETE_Return_t type_t;
109  static inline type_t apply(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
110  return Reduction(Expressionize<typename T::PETE_Expr_t>::apply( expr.PETE_unwrap().MakeExpression() ),
111  OpGT(), OpMaxAssign(),loc);
112  }
113 };
114 
115 template<class T, unsigned D>
116 inline typename MMMax<T,D>::type_t
117 max(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
118  return MMMax<T,D>::apply(expr, loc);
119 }
120 #else
121 template<class T, unsigned D>
122 inline typename T::PETE_Expr_t::PETE_Return_t
123 max(const PETE_Expr<T>& expr, NDIndex<D>& loc)
124 {
126  OpGT(),OpMaxAssign(),loc);
127 }
128 #endif // __MWERKS__
129 
131 
132 #include "Field/ReductionLoc.hpp"
133 
134 #endif // REDUCTION_LOC_H
135 
136 /***************************************************************************
137  * $RCSfile: ReductionLoc.h,v $ $Author: adelmann $
138  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:26 $
139  * IPPL_VERSION_ID: $Id: ReductionLoc.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $
140  ***************************************************************************/
141 
142 
143 
144 
T::PETE_Return_t Reduction(const PETE_Expr< T > &const_expr, CompOp comp_op, AccOp acc_op, NDIndex< D > &loc)
Definition: PETE.h:80
void GetCurrentLocation(FieldLoc< Dim > &loc) const
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:123
WrappedExpr & PETE_unwrap()
Definition: PETE.h:85
NDIndex< D > * Loc
Definition: ReductionLoc.h:39
Definition: Index.h:236
FindLocation(NDIndex< D > &loc)
Definition: ReductionLoc.h:40
bool for_each(const BareFieldIterator< T, D > &p, SameFieldID s, C)
Definition: AssignDefs.h:30
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:95