src/Field/ReductionLoc.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef REDUCTION_LOC_H
00012 #define REDUCTION_LOC_H
00013 
00014 // include files
00015 #include "PETE/IpplExpressions.h"
00016 
00017 // forward declarations
00018 template<unsigned D> class NDIndex;
00019 template<class T, unsigned int D> class BareFieldIterator;
00020 template<class T, unsigned int D> class IndexedBareFieldIterator;
00021 
00023 
00024 // Fundamental reduction function for minloc and maxloc
00025 
00026 template<class T, class CompOp, class AccOp, unsigned D>
00027 typename T::PETE_Return_t
00028 Reduction(const PETE_Expr<T>& const_expr,
00029           CompOp comp_op,
00030           AccOp  acc_op,
00031           NDIndex<D>& loc);
00032 
00033 // Struct for saving current location
00034 
00035 template <unsigned int D>
00036 struct FindLocation
00037 {
00038   typedef int PETE_Return_t;
00039   NDIndex<D>* Loc;
00040   FindLocation(NDIndex<D>& loc) : Loc(&loc) {}
00041 };
00042 
00043 // Behavior of this struct
00044 
00045 template <class T, class C, unsigned int D>
00046 inline int
00047 for_each(const IndexedBareFieldIterator<T,D>& expr,
00048          FindLocation<D>& find_loc, C)
00049 {
00050   int loc[D];
00051   expr.GetCurrentLocation(loc);
00052   for (unsigned d=0; d<D; d++) (*(find_loc.Loc))[d] = Index(loc[d],loc[d]);
00053   return 0;
00054 }
00055 
00056 template <class T, class C, unsigned int D>
00057 inline int
00058 for_each(const BareFieldIterator<T,D>& expr, FindLocation<D>& find_loc, C)
00059 {
00060   int loc[D];
00061   expr.GetCurrentLocation(loc);
00062   for (unsigned d=0; d<D; d++) (*(find_loc.Loc))[d] = Index(loc[d],loc[d]);
00063   return 0;
00064 }
00065 
00067 //
00068 // Minloc and Maxloc require slightly different functionality.
00069 // They need to keep track of the location in addition to finding
00070 // the min and max.
00071 //
00073 
00074 #ifdef __MWERKS__
00075 // Workaround for CodeWarrior 4 bug
00076 // Funny "MMMin" name is to avoid conflict with Min defined elsewhere in r1,
00077 // and "MMin defined iin IpplExpressions.h.
00078 template<class T, unsigned D> 
00079 struct MMMin {
00080   typedef typename T::PETE_Expr_t::PETE_Return_t type_t;
00081   static inline type_t apply(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00082     return Reduction(Expressionize<typename T::PETE_Expr_t>::apply( expr.PETE_unwrap().MakeExpression() ), 
00083               OpLT(), OpMinAssign(),loc);
00084   }
00085 };
00086 
00087 template<class T, unsigned D> 
00088 inline typename MMMin<T,D>::type_t 
00089 min(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00090   return MMMin<T,D>::apply(expr, loc);
00091 }
00092 #else
00093 template<class T, unsigned D> 
00094 typename T::PETE_Expr_t::PETE_Return_t
00095 min(const PETE_Expr<T>& expr, NDIndex<D>& loc)
00096 {
00097   return Reduction(Expressionize<typename T::PETE_Expr_t>::apply(expr.PETE_unwrap().MakeExpression()),
00098                    OpLT(),OpMinAssign(),loc);
00099 }
00100 #endif // __MWERKS__
00101 
00102 #ifdef __MWERKS__
00103 // Workaround for CodeWarrior 4 bug
00104 // Funny "MMMax" name is to avoid conflict with Max defined elsewhere in r1,
00105 // and "MMax defined iin IpplExpressions.h.
00106 template<class T, unsigned D> 
00107 struct MMMax {
00108   typedef typename T::PETE_Expr_t::PETE_Return_t type_t;
00109   static inline type_t apply(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00110     return Reduction(Expressionize<typename T::PETE_Expr_t>::apply( expr.PETE_unwrap().MakeExpression() ), 
00111               OpGT(), OpMaxAssign(),loc);
00112   }
00113 };
00114 
00115 template<class T, unsigned D> 
00116 inline typename MMMax<T,D>::type_t 
00117 max(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00118   return MMMax<T,D>::apply(expr, loc);
00119 }
00120 #else
00121 template<class T, unsigned D>
00122 typename T::PETE_Expr_t::PETE_Return_t
00123 max(const PETE_Expr<T>& expr, NDIndex<D>& loc)
00124 {
00125   return Reduction(Expressionize<typename T::PETE_Expr_t>::apply(expr.PETE_unwrap().MakeExpression()),
00126                    OpGT(),OpMaxAssign(),loc);
00127 }
00128 #endif // __MWERKS__
00129 
00131 
00132 #include "Field/ReductionLoc.cpp"
00133 
00134 #endif // REDUCTION_LOC_H
00135 
00136 /***************************************************************************
00137  * $RCSfile: ReductionLoc.h,v $   $Author: adelmann $
00138  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
00139  * IPPL_VERSION_ID: $Id: ReductionLoc.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
00140  ***************************************************************************/
00141 
00142 
00143 
00144 

Generated on Mon Jan 16 13:23:46 2006 for IPPL by  doxygen 1.4.6