OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
15// BrickExpLoop::apply member functions
16
17template<class LHS, class RHS, class OP, unsigned Dim>
19{
20public:
21 void
22 apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
23 {
24 int n0 = Lhs.size(0);
25 int n1 = Lhs.size(1);
26 int n2 = Lhs.size(2);
27 if ( (n0>0)&&(n1>0)&&(n2>0) )
28 {
29 unsigned d;
30 do
31 {
32 for (int i2=0; i2<n2; ++i2)
33 for (int i1=0; i1<n1; ++i1)
34 for (int i0=0; i0<n0; ++i0)
35 PETE_apply(Op,Lhs.offset(i0,i1,i2),
36 for_each(Rhs,EvalFunctor_3(i0,i1,i2)));
37
38 for (d=3; d<Dim; ++d)
39 {
40 Lhs.step(d);
42 if ( ! Lhs.done(d) )
43 break;
44 Lhs.rewind(d);
46 }
47 } while (d<Dim);
48 }
49 }
50};
51
52
54//a specialization of BrickExpLoop::apply for a 1D loop evaluation
55template<class LHS, class RHS, class OP>
56class BrickExpLoop<LHS,RHS,OP,1U>
57{
58public:
59 static inline void
60 apply(LHS& Lhs, RHS& Rhs, OP Op)
61 {
62 int n0 = Lhs.size(0);
63 for (int i0=0; i0<n0; ++i0) {
64 PETE_apply(Op,Lhs.offset(i0),for_each(Rhs,EvalFunctor_1(i0)));
65 }
66 }
67};
68
70//a specialization of BrickExpLoops::apply for a 2D loop evaluation
71template<class LHS, class RHS, class OP>
72class BrickExpLoop<LHS,RHS,OP,2U>
73{
74public:
75 static inline void
76 apply(LHS& __restrict__ Lhs, RHS& __restrict__ Rhs, OP Op)
77 {
78 int n0 = Lhs.size(0);
79 int n1 = Lhs.size(1);
80 for (int i1=0; i1<n1; ++i1)
81 for (int i0=0; i0<n0; ++i0)
82 PETE_apply(Op,Lhs.offset(i0,i1),
83 for_each(Rhs,EvalFunctor_2(i0,i1)));
84 }
85};
86
87
89//a specialization of BrickExpLoops::apply for a 3D loop evaluation
90template<class LHS, class RHS, class OP>
91class BrickExpLoop<LHS,RHS,OP,3U>
92{
93public:
94 static inline void
95 apply(LHS& Lhs, RHS& Rhs, OP Op)
96 {
97 int n0 = Lhs.size(0);
98 int n1 = Lhs.size(1);
99 int n2 = Lhs.size(2);
100 for (int i2=0; i2<n2; ++i2)
101 for (int i1=0; i1<n1; ++i1)
102 for (int i0=0; i0<n0; ++i0)
103 PETE_apply(Op,
104 Lhs.offset(i0,i1,i2),
105 for_each(Rhs,EvalFunctor_3(i0,i1,i2)));
106 }
107};
108
110// BrickExpression::apply - just use BrickExpLoop
111// Legacy code attempted to call apply() as a static method.
112// This is invalid since apply() is a non-static member function.
113template<unsigned Dim, class LHS, class RHS, class OP>
115{
117 loop.apply(Lhs, Rhs, Op);
118}
const unsigned Dim
void PETE_apply(const OpPeriodic< T > &, T &a, const T &b)
Definition BCond.hpp:353
bool for_each(const BareFieldIterator< T, D > &p, SameFieldID s, C)
Definition AssignDefs.h:30
virtual void apply()
void apply(LHS &__restrict__ Lhs, RHS &__restrict__ Rhs, OP Op)
static void apply(LHS &Lhs, RHS &Rhs, OP Op)
static void apply(LHS &__restrict__ Lhs, RHS &__restrict__ Rhs, OP Op)
static void apply(LHS &Lhs, RHS &Rhs, OP Op)