src/Field/BrickExpression.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
00027 #include "Profile/Profiler.h"
00028 
00029 
00031 // BrickExpLoop::apply member functions
00032 
00033 template<class LHS, class RHS, class OP, unsigned Dim>
00034 class BrickExpLoop
00035 {
00036 public: 
00037   static inline void
00038   apply(LHS& restrict Lhs, RHS& restrict Rhs, OP Op)
00039     {
00040       int n0 = Lhs.size(0);
00041       int n1 = Lhs.size(1);
00042       int n2 = Lhs.size(2);
00043       if ( (n0>0)&&(n1>0)&&(n2>0) )
00044         {
00045           unsigned d;
00046           do
00047             {
00048               for (int i2=0; i2<n2; ++i2)
00049                 for (int i1=0; i1<n1; ++i1)
00050                   for (int i0=0; i0<n0; ++i0)
00051                     PETE_apply(Op,Lhs.offset(i0,i1,i2),
00052                                for_each(Rhs,EvalFunctor_3(i0,i1,i2)));
00053 
00054               for (d=3; d<Dim; ++d)
00055                 {
00056                   Lhs.step(d);
00057                   // #pragma inline here
00058                   for_each(Rhs,StepFunctor(d),PETE_NullCombiner());
00059                   if ( ! Lhs.done(d) ) 
00060                     break;
00061                   Lhs.rewind(d);
00062                   // #pragma inline here
00063                   for_each(Rhs,RewindFunctor(d),PETE_NullCombiner());
00064                 } 
00065             } while (d<Dim);
00066         }
00067     }
00068 };
00069 
00070 
00072 //a specialization of BrickExpLoop::apply for a 1D loop evaluation
00073 template<class LHS, class RHS, class OP>
00074 class BrickExpLoop<LHS,RHS,OP,1U>
00075 {
00076 public:
00077   static inline void apply(LHS& restrict Lhs, RHS& restrict Rhs, OP Op)
00078     {
00079       int n0 = Lhs.size(0);
00080       for (int i0=0; i0<n0; ++i0) {
00081         PETE_apply(Op,Lhs.offset(i0),for_each(Rhs,EvalFunctor_1(i0)));
00082       }
00083     }
00084 };
00085 
00087 //a specialization of BrickExpLoops::apply for a 2D loop evaluation
00088 template<class LHS, class RHS, class OP>
00089 class BrickExpLoop<LHS,RHS,OP,2U>
00090 {
00091 public:
00092   static inline void
00093   apply(LHS& restrict Lhs, RHS& restrict Rhs, OP Op)
00094     {
00095       int n0 = Lhs.size(0);
00096       int n1 = Lhs.size(1);
00097       for (int i1=0; i1<n1; ++i1)
00098         for (int i0=0; i0<n0; ++i0)
00099           PETE_apply(Op,Lhs.offset(i0,i1),
00100                      for_each(Rhs,EvalFunctor_2(i0,i1)));
00101     }
00102 };
00103 
00104 
00106 //a specialization of BrickExpLoops::apply for a 3D loop evaluation
00107 template<class LHS, class RHS, class OP>
00108 class BrickExpLoop<LHS,RHS,OP,3U>
00109 {
00110 public:
00111   static inline void
00112   apply(LHS& restrict Lhs, RHS& restrict Rhs, OP Op)
00113     {
00114       int n0 = Lhs.size(0);
00115       int n1 = Lhs.size(1);
00116       int n2 = Lhs.size(2);
00117       for (int i2=0; i2<n2; ++i2) 
00118         for (int i1=0; i1<n1; ++i1) 
00119           for (int i0=0; i0<n0; ++i0) 
00120             PETE_apply(Op,Lhs.offset(i0,i1,i2),
00121                        for_each(Rhs,EvalFunctor_3(i0,i1,i2)));
00122     }
00123 };
00124 
00126 // BrickExpression::apply - just use BrickExpLoop
00127 // ada: remove restrict from apply to make  g++ 2.95.3 happy
00128 template<unsigned Dim, class LHS, class RHS, class OP>
00129 #if (IPPL_RESTRICT_BUG)
00130  void BrickExpression<Dim,LHS,RHS,OP>::apply()
00131 #else
00132  void BrickExpression<Dim,LHS,RHS,OP>::apply() restrict
00133 #endif
00134 {
00135   TAU_TYPE_STRING(taustr, CT(*this) + " void ()" );
00136   TAU_PROFILE("BrickExpression::apply()", taustr, TAU_PETE);
00137   
00138   // #pragma inline here
00139   BrickExpLoop<LHS,RHS,OP,Dim>::apply(Lhs,Rhs,Op);
00140 }
00141 
00142 /***************************************************************************
00143  * $RCSfile: BrickExpression.cpp,v $   $Author: adelmann $
00144  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
00145  * IPPL_VERSION_ID: $Id: BrickExpression.cpp,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
00146  ***************************************************************************/

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