OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
NDIndexInlines.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef NDINDEX_INLINES_H
12 #define NDINDEX_INLINES_H
13 
14 // include files
15 #include "Utility/PAssert.h"
16 
17 
19 // Construct from a simple array of Indexes
20 template<unsigned Dim>
21 inline
23 {
24  for (unsigned i=0; i<Dim; ++i)
25  p[i]=idx[i];
26 }
27 
28 // Intersect with another NDIndex.
29 template<unsigned Dim>
30 inline NDIndex<Dim>
32 {
33  NDIndex<Dim> r;
34  for (unsigned d=0;d<Dim;++d)
35  r[d] = p[d].intersect( i[d] );
36  return r;
37 }
38 
40 
41 // Forward substitute the base of one index into this one.
42 
43 template<unsigned D1, unsigned D2>
44 inline NDIndex<D1> plugBase(const NDIndex<D1>& i1, const NDIndex<D2>& i2)
45 {
46  // Construct and return ret.
47  NDIndex<D1> ret(i1);
48  // Loop over each of the Indexes in ret.
49  for (unsigned d1=0; d1<D1; ++d1)
50  // Try to find the corresponding Index in i2.
51  for (unsigned d2=0; d2<D2; ++d2)
52  if ( i1[d1].sameBase( i2[d2] ) )
53  {
54  // Found it. Substitute for this one.
55  ret[d1] = ret[d1].plugBase( i2[d2] );
56  break;
57  }
58  return ret;
59 }
60 
61 
62 
64 
65 
66 template<unsigned Dim>
67 inline unsigned
69 {
70  unsigned s = p[0].length();
71  for (unsigned int d=1; d<Dim; ++d)
72  s *= p[d].length();
73  return s;
74 }
75 
76 //----------------------------------------------------------------------
77 
78 template <unsigned Dim>
79 inline bool
81 {
82  bool touch = true;
83  for (unsigned int d=0; (d<Dim)&&touch ; ++d)
84  touch = touch && p[d].touches(a.p[d]);
85  return touch;
86 }
87 
88 //----------------------------------------------------------------------
89 
90 template <unsigned Dim>
91 inline bool
93 {
94  bool cont = true;
95  for (unsigned int d=0; (d<Dim)&&cont ; ++d)
96  cont = cont && p[d].contains(a.p[d]);
97  return cont;
98 }
99 
100 //----------------------------------------------------------------------
101 
102 template <unsigned Dim>
103 inline bool
105 {
106  bool cont = true;
107  for (unsigned int d=0; (d<Dim)&&cont ; ++d)
108  cont = cont && p[d].containsAllPoints(a.p[d]);
109  return cont;
110 }
111 
112 //----------------------------------------------------------------------
113 
114 template<unsigned Dim>
115 inline bool
117 {
118  bool r = false;
119  for (unsigned d=0; d<Dim; ++d)
120  r = r || p[d].empty();
121  return r;
122 }
123 
124 //----------------------------------------------------------------------
125 
126 template<unsigned Dim>
127 inline bool
129  unsigned d, double a) const
130 {
131  if ( &l != this )
132  l = *this;
133  if ( &r != this )
134  r = *this;
135  return p[d].split(l[d],r[d],a);
136 }
137 
138 template<unsigned Dim>
139 inline bool
141 {
142  if ( &l != this )
143  l = *this;
144  if ( &r != this )
145  r = *this;
146  return p[d].split(l[d],r[d]);
147 }
148 
149 //----------------------------------------------------------------------
150 
151 template<unsigned Dim>
152 inline bool
154 {
155  unsigned int max_dim = 0;
156  unsigned int max_length = 0;
157  for (unsigned int d=0; d<Dim; ++d)
158  if ( p[d].length() > max_length ) {
159  max_dim = d;
160  max_length = p[d].length();
161  }
162  return split(l,r,max_dim);
163 }
164 
166 
167 template<unsigned Dim>
168 inline
170 {
171  PInsist(Dim==1, "Number of arguments does not match NDIndex dimension!!");
172  p[0] = i0;
173 }
174 
175 template<unsigned Dim>
176 inline
177 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1)
178 {
179  PInsist(Dim==2, "Number of arguments does not match NDIndex dimension!!");
180  p[0] = i0;
181  p[1] = i1;
182 }
183 
184 template<unsigned Dim>
185 inline
186 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2)
187 {
188  PInsist(Dim==3, "Number of arguments does not match NDIndex dimension!!");
189  p[0] = i0;
190  p[1] = i1;
191  p[2] = i2;
192 }
193 
194 template<unsigned Dim>
195 inline
196 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
197  const Index& i3)
198 {
199  PInsist(Dim==4, "Number of arguments does not match NDIndex dimension!!");
200  p[0] = i0;
201  p[1] = i1;
202  p[2] = i2;
203  p[3] = i3;
204 }
205 
206 template<unsigned Dim>
207 inline
208 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
209  const Index& i3,const Index& i4)
210 {
211  PInsist(Dim==5, "Number of arguments does not match NDIndex dimension!!");
212  p[0] = i0;
213  p[1] = i1;
214  p[2] = i2;
215  p[3] = i3;
216  p[4] = i4;
217 }
218 
219 template<unsigned Dim>
220 inline
221 NDIndex<Dim>::NDIndex(const Index& i0,const Index& i1,const Index& i2,
222  const Index& i3,const Index& i4,const Index& i5)
223 {
224  PInsist(Dim==6, "Number of arguments does not match NDIndex dimension!!");
225  p[0] = i0;
226  p[1] = i1;
227  p[2] = i2;
228  p[3] = i3;
229  p[4] = i4;
230  p[5] = i5;
231 }
232 
233 template<> inline
234 NDIndex<2>::NDIndex(const NDIndex<1>& ndi, const Index& i)
235 {
236  p[0] = ndi[0];
237  p[1] = i;
238 }
239 template<> inline
240 NDIndex<3>::NDIndex(const NDIndex<2>& ndi, const Index& i)
241 {
242  p[0] = ndi[0];
243  p[1] = ndi[1];
244  p[2] = i;
245 }
246 template<> inline
247 NDIndex<4>::NDIndex(const NDIndex<3>& ndi, const Index& i)
248 {
249  p[0] = ndi[0];
250  p[1] = ndi[1];
251  p[2] = ndi[2];
252  p[3] = i;
253 }
254 template<> inline
255 NDIndex<5>::NDIndex(const NDIndex<4>& ndi, const Index& i)
256 {
257  p[0] = ndi[0];
258  p[1] = ndi[1];
259  p[2] = ndi[2];
260  p[3] = ndi[3];
261  p[4] = i;
262 }
263 template<> inline
264 NDIndex<6>::NDIndex(const NDIndex<5>& ndi, const Index& i)
265 {
266  p[0] = ndi[0];
267  p[1] = ndi[1];
268  p[2] = ndi[2];
269  p[3] = ndi[3];
270  p[4] = ndi[4];
271  p[5] = i;
272 }
273 
275 //
276 // Attempts to determine whether i2 represents a stencil relative
277 // to i1. For each index in i1, it checks through all of the indices
278 // in i2 to see if the id's match. If a match is obtained, but the
279 // indexes are not equivalent, this must be a stencil. If i1's index
280 // is not found in i2, we make the safe choice of returning
281 // true (is-a-stencil). We only conclude this is not a stencil if
282 // all indices in i1 appear in i2 and are equivalent.
283 //
285 
286 template<unsigned D1, unsigned D2>
287 inline bool isStencil(const NDIndex<D1> &i1, const NDIndex<D2> &i2)
288 {
289  for (unsigned i = 0; i < D1; i++)
290  {
291  bool found = false;
292  for (unsigned j = 0; j < D2; j++)
293  {
294  if (i1[i].id() == i2[j].id())
295  {
296  found = true;
297  if (!(i1[i] == i2[j]))
298  return true;
299  }
300  }
301  if (!found)
302  return true;
303  }
304 
305  return false;
306 }
307 
308 #endif // NDINDEX_INLINES_H
309 
310 /***************************************************************************
311  * $RCSfile: NDIndexInlines.h,v $ $Author: adelmann $
312  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:27 $
313  * IPPL_VERSION_ID: $Id: NDIndexInlines.h,v 1.1.1.1 2003/01/23 07:40:27 adelmann Exp $
314  ***************************************************************************/
bool split(NDIndex< Dim > &l, NDIndex< Dim > &r, unsigned d, double a) const
bool containsAllPoints(const NDIndex< Dim > &b) const
unsigned size() const
NDIndex< D1 > plugBase(const NDIndex< D1 > &, const NDIndex< D2 > &)
NDIndex< Dim > plugBase(const NDIndex< 1 > &i) const
Definition: NDIndex.h:118
Definition: Index.h:236
bool empty() const
Index p[Dim==0?1:Dim]
Definition: NDIndex.h:154
bool touches(const NDIndex< Dim > &) const
bool isStencil(const NDIndex< D1 > &i1, const NDIndex< D2 > &i2)
bool contains(const NDIndex< Dim > &a) const
NDIndex< Dim > intersect(const NDIndex< Dim > &) const
#define PInsist(c, m)
Definition: PAssert.h:135
const unsigned Dim
NDIndex()
Definition: NDIndex.h:78