OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 template<class T, unsigned D>
75 inline typename T::PETE_Expr_t::PETE_Return_t
76 min(const PETE_Expr<T>& expr, NDIndex<D>& loc)
77 {
79  OpLT(),OpMinAssign(),loc);
80 }
81 
82 template<class T, unsigned D>
83 inline typename T::PETE_Expr_t::PETE_Return_t
84 max(const PETE_Expr<T>& expr, NDIndex<D>& loc)
85 {
87  OpGT(),OpMaxAssign(),loc);
88 }
89 
91 
92 #include "Field/ReductionLoc.hpp"
93 
94 #endif // REDUCTION_LOC_H
95 
96 /***************************************************************************
97  * $RCSfile: ReductionLoc.h,v $ $Author: adelmann $
98  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:26 $
99  * IPPL_VERSION_ID: $Id: ReductionLoc.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $
100  ***************************************************************************/
101 
102 
103 
104 
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
int for_each(const IndexedBareFieldIterator< T, D > &expr, FindLocation< D > &find_loc, C)
Definition: ReductionLoc.h:47
T::PETE_Return_t Reduction(const PETE_Expr< T > &const_expr, CompOp comp_op, AccOp acc_op, NDIndex< D > &loc)
void GetCurrentLocation(FieldLoc< Dim > &loc) const
NDIndex< D > * Loc
Definition: ReductionLoc.h:39
FindLocation(NDIndex< D > &loc)
Definition: ReductionLoc.h:40
Definition: Index.h:237
Definition: PETE.h:77
WrappedExpr & PETE_unwrap()
Definition: PETE.h:81