BrickExpression.hpp 3.92 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
 * 
 * This program was prepared by PSI. 
 * All rights in the program are reserved by PSI.
 * Neither PSI nor the author(s)
 * makes any warranty, express or implied, or assumes any liability or
 * responsibility for the use of this software
 *
 * Visit www.amas.web.psi for more details
 *
 ***************************************************************************/

// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
 * 
 *
 * Visit http://people.web.psi.ch/adelmann/ for more details
 *
 ***************************************************************************/

// include files
uldis_l's avatar
uldis_l committed
27

gsell's avatar
gsell committed
28 29 30 31 32 33 34 35 36 37


//////////////////////////////////////////////////////////////////////
// BrickExpLoop::apply member functions

template<class LHS, class RHS, class OP, unsigned Dim>
class BrickExpLoop
{
public: 
  static inline void
gsell's avatar
gsell committed
38
  apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
gsell's avatar
gsell committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    {
      int n0 = Lhs.size(0);
      int n1 = Lhs.size(1);
      int n2 = Lhs.size(2);
      if ( (n0>0)&&(n1>0)&&(n2>0) )
	{
	  unsigned d;
	  do
	    {
	      for (int i2=0; i2<n2; ++i2)
		for (int i1=0; i1<n1; ++i1)
		  for (int i0=0; i0<n0; ++i0)
		    PETE_apply(Op,Lhs.offset(i0,i1,i2),
			       for_each(Rhs,EvalFunctor_3(i0,i1,i2)));

	      for (d=3; d<Dim; ++d)
		{
		  Lhs.step(d);
		  // #pragma inline here
		  for_each(Rhs,StepFunctor(d),PETE_NullCombiner());
		  if ( ! Lhs.done(d) ) 
		    break;
		  Lhs.rewind(d);
		  // #pragma inline here
		  for_each(Rhs,RewindFunctor(d),PETE_NullCombiner());
		} 
	    } while (d<Dim);
	}
    }
};


//////////////////////////////////////////////////////////////////////
//a specialization of BrickExpLoop::apply for a 1D loop evaluation
template<class LHS, class RHS, class OP>
class BrickExpLoop<LHS,RHS,OP,1U>
{
public:
gsell's avatar
gsell committed
77
  static inline void apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
gsell's avatar
gsell committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    {
      int n0 = Lhs.size(0);
      for (int i0=0; i0<n0; ++i0) {
	PETE_apply(Op,Lhs.offset(i0),for_each(Rhs,EvalFunctor_1(i0)));
      }
    }
};

//////////////////////////////////////////////////////////////////////
//a specialization of BrickExpLoops::apply for a 2D loop evaluation
template<class LHS, class RHS, class OP>
class BrickExpLoop<LHS,RHS,OP,2U>
{
public:
  static inline void
gsell's avatar
gsell committed
93
  apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
gsell's avatar
gsell committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    {
      int n0 = Lhs.size(0);
      int n1 = Lhs.size(1);
      for (int i1=0; i1<n1; ++i1)
	for (int i0=0; i0<n0; ++i0)
	  PETE_apply(Op,Lhs.offset(i0,i1),
		     for_each(Rhs,EvalFunctor_2(i0,i1)));
    }
};


//////////////////////////////////////////////////////////////////////
//a specialization of BrickExpLoops::apply for a 3D loop evaluation
template<class LHS, class RHS, class OP>
class BrickExpLoop<LHS,RHS,OP,3U>
{
public:
  static inline void
gsell's avatar
gsell committed
112
  apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
gsell's avatar
gsell committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    {
      int n0 = Lhs.size(0);
      int n1 = Lhs.size(1);
      int n2 = Lhs.size(2);
      for (int i2=0; i2<n2; ++i2) 
	for (int i1=0; i1<n1; ++i1) 
	  for (int i0=0; i0<n0; ++i0) 
	    PETE_apply(Op,Lhs.offset(i0,i1,i2),
		       for_each(Rhs,EvalFunctor_3(i0,i1,i2)));
    }
};

//////////////////////////////////////////////////////////////////////
// BrickExpression::apply - just use BrickExpLoop
// ada: remove restrict from apply to make  g++ 2.95.3 happy
template<unsigned Dim, class LHS, class RHS, class OP>
 void BrickExpression<Dim,LHS,RHS,OP>::apply()
{
uldis_l's avatar
uldis_l committed
131 132
  
  
gsell's avatar
gsell committed
133 134 135 136 137 138 139 140 141 142
  
  // #pragma inline here
  BrickExpLoop<LHS,RHS,OP,Dim>::apply(Lhs,Rhs,Op);
}

/***************************************************************************
 * $RCSfile: BrickExpression.cpp,v $   $Author: adelmann $
 * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
 * IPPL_VERSION_ID: $Id: BrickExpression.cpp,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
 ***************************************************************************/