OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
BrickExpression.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * The IPPL Framework
4  *
5  * This program was prepared by PSI.
6  * All rights in the program are reserved by PSI.
7  * Neither PSI nor the author(s)
8  * makes any warranty, express or implied, or assumes any liability or
9  * responsibility for the use of this software
10  *
11  ***************************************************************************/
12 
13 // include files
14 
15 
16 
18 // BrickExpLoop::apply member functions
19 
20 template<class LHS, class RHS, class OP, unsigned Dim>
22 {
23 public:
24  static inline void
25  apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
26  {
27  int n0 = Lhs.size(0);
28  int n1 = Lhs.size(1);
29  int n2 = Lhs.size(2);
30  if ( (n0>0)&&(n1>0)&&(n2>0) )
31  {
32  unsigned d;
33  do
34  {
35  for (int i2=0; i2<n2; ++i2)
36  for (int i1=0; i1<n1; ++i1)
37  for (int i0=0; i0<n0; ++i0)
38  PETE_apply(Op,Lhs.offset(i0,i1,i2),
39  for_each(Rhs,EvalFunctor_3(i0,i1,i2)));
40 
41  for (d=3; d<Dim; ++d)
42  {
43  Lhs.step(d);
45  if ( ! Lhs.done(d) )
46  break;
47  Lhs.rewind(d);
49  }
50  } while (d<Dim);
51  }
52  }
53 };
54 
55 
57 //a specialization of BrickExpLoop::apply for a 1D loop evaluation
58 template<class LHS, class RHS, class OP>
59 class BrickExpLoop<LHS,RHS,OP,1U>
60 {
61 public:
62  static inline void apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
63  {
64  int n0 = Lhs.size(0);
65  for (int i0=0; i0<n0; ++i0) {
66  PETE_apply(Op,Lhs.offset(i0),for_each(Rhs,EvalFunctor_1(i0)));
67  }
68  }
69 };
70 
72 //a specialization of BrickExpLoops::apply for a 2D loop evaluation
73 template<class LHS, class RHS, class OP>
74 class BrickExpLoop<LHS,RHS,OP,2U>
75 {
76 public:
77  static inline void
78  apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
79  {
80  int n0 = Lhs.size(0);
81  int n1 = Lhs.size(1);
82  for (int i1=0; i1<n1; ++i1)
83  for (int i0=0; i0<n0; ++i0)
84  PETE_apply(Op,Lhs.offset(i0,i1),
85  for_each(Rhs,EvalFunctor_2(i0,i1)));
86  }
87 };
88 
89 
91 //a specialization of BrickExpLoops::apply for a 3D loop evaluation
92 template<class LHS, class RHS, class OP>
93 class BrickExpLoop<LHS,RHS,OP,3U>
94 {
95 public:
96  static inline void
97  apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
98  {
99  int n0 = Lhs.size(0);
100  int n1 = Lhs.size(1);
101  int n2 = Lhs.size(2);
102  for (int i2=0; i2<n2; ++i2)
103  for (int i1=0; i1<n1; ++i1)
104  for (int i0=0; i0<n0; ++i0)
105  PETE_apply(Op,Lhs.offset(i0,i1,i2),
106  for_each(Rhs,EvalFunctor_3(i0,i1,i2)));
107  }
108 };
109 
111 // BrickExpression::apply - just use BrickExpLoop
112 // ada: remove restrict from apply to make g++ 2.95.3 happy
113 template<unsigned Dim, class LHS, class RHS, class OP>
115 {
116 
118 }
const unsigned Dim
bool for_each(const BareFieldIterator< T, D > &p, SameFieldID s, C)
Definition: AssignDefs.h:30
void PETE_apply(const OpPeriodic< T > &, T &a, const T &b)
Definition: BCond.hpp:353
virtual void apply()
static void apply(LHS &__restrict__ Lhs, RHS &__restrict__ Rhs, OP Op)
static void apply(LHS &__restrict__ Lhs, RHS &__restrict__ Rhs, OP Op)
static void apply(LHS &__restrict__ Lhs, RHS &__restrict__ Rhs, OP Op)
static void apply(LHS &__restrict__ Lhs, RHS &__restrict__ Rhs, OP Op)