[2b666a]: / blitz / array / stencil-et.h  Maximize  Restore  History

Download this file

455 lines (413 with data), 24.9 kB

  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
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 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
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
// -*- C++ -*-
/***************************************************************************
* blitz/array/stencil-et.h Expression-template-capabale stencils
*
* Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Suggestions: blitz-dev@oonumerics.org
* Bugs: blitz-bugs@oonumerics.org
*
* For more information, please see the Blitz++ Home Page:
* http://oonumerics.org/blitz/
*
****************************************************************************/
#ifndef BZ_ARRAY_STENCIL_ET_H
#define BZ_ARRAY_STENCIL_ET_H
BZ_NAMESPACE(blitz)
template<typename T_ArrayNumtype, int N_rank, typename T_result>
class StencilExpr
{
public:
typedef T_result T_numtype;
typedef Array<T_ArrayNumtype,N_rank> T_array;
typedef const T_array& T_ctorArg1;
typedef int T_ctorArg2;
static const int
numArrayOperands = 1,
numIndexPlaceholders = 0,
rank = N_rank;
StencilExpr(const T_array& array)
: iter_(array)
{ }
~StencilExpr()
{ }
// operator* must be declared by subclass
int ascending(const int rank) const { return iter_.ascending(rank); }
int ordering(const int rank) const { return iter_.ordering(rank); }
int lbound(const int rank) const { return iter_.lbound(rank); }
int ubound(const int rank) const { return iter_.ubound(rank); }
void push(const int position) { iter_.push(position); }
void pop(const int position) { iter_.pop(position); }
void advance() { iter_.advance(); }
void advance(const int n) { iter_.advance(n); }
void loadStride(const int rank) { iter_.loadStride(rank); }
bool isUnitStride(const int rank) const { return iter_.isUnitStride(rank); }
void advanceUnitStride() { iter_.advanceUnitStride(); }
bool canCollapse(const int outerLoopRank,const int innerLoopRank) const {
// BZ_DEBUG_MESSAGE("_bz_ArrayExpr<>::canCollapse()");
return iter_.canCollapse(outerLoopRank, innerLoopRank);
}
// T_numtype operator[](int i) -- don't know how to do that.
// T_numtype fastRead(int i) -- ditto
diffType suggestStride(const int rank) const { return iter_.suggestStride(rank); }
bool isStride(const int rank,const diffType stride) const { return iter_.isStride(rank,stride); }
void prettyPrint(BZ_STD_SCOPE(string) &str) const
{
str += "(stencil)"; // lame, needs work
}
void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat&) const
{ str += "(stencil)"; }
template<typename T_shape>
bool shapeCheck(const T_shape& shape)
{ return iter_.shapeCheck(shape); }
void moveTo(const TinyVector<int,N_rank>& i)
{
iter_.moveTo(i);
}
protected:
FastArrayIterator<T_ArrayNumtype,N_rank> iter_;
};
#define BZ_ET_STENCIL(name,result) \
template<typename P_numtype, int N_rank> \
class name ## _et : public StencilExpr<P_numtype,N_rank,result>, \
public ETBase<name ## _et<P_numtype,N_rank> > \
{ \
private: \
typedef StencilExpr<P_numtype,N_rank,result> T_base; \
using T_base::iter_; \
public: \
name ## _et(const Array<P_numtype,N_rank>& A) \
: StencilExpr<P_numtype,N_rank,result>(A) \
{ } \
result operator*() \
{ return name(iter_); } \
result operator()(const TinyVector<int,N_rank>& a) \
{ iter_.moveTo(a); return name(iter_); } \
result fastRead(int i) \
{ \
const P_numtype* tmp = iter_.data(); \
iter_._bz_setData(tmp + i); \
P_numtype r = name(iter_); \
iter_._bz_setData(tmp); \
return r; \
} \
}; \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(const Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr<name ## _et<P_numtype, N_rank> >(A); \
} \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr<name ## _et<P_numtype, N_rank> >(A); \
}
#define BZ_ET_STENCILM(name,rank) \
template<typename P_numtype, int N_rank> \
class name ## _et : public StencilExpr<P_numtype,N_rank, \
TinyMatrix<_bz_typename multicomponent_traits<P_numtype>::T_element, \
rank, rank> >, \
public ETBase<name ## _et<P_numtype,N_rank> > \
{ \
private: \
typedef StencilExpr<P_numtype,N_rank, \
TinyMatrix<_bz_typename multicomponent_traits<P_numtype>::T_element, \
rank, rank> > T_base; \
using T_base::iter_; \
public: \
typedef \
TinyMatrix<_bz_typename multicomponent_traits<P_numtype>::T_element, \
rank, rank> result; \
name ## _et(const Array<P_numtype,N_rank>& A) \
: StencilExpr<P_numtype,N_rank,result>(A) \
{ } \
result operator*() \
{ return name(iter_); } \
result operator()(const TinyVector<int,N_rank>& a) \
{ iter_.moveTo(a); return name(iter_); } \
result fastRead(int i) \
{ \
const P_numtype* tmp = iter_.data(); \
iter_._bz_setData(tmp + i); \
P_numtype r = name(iter_); \
iter_._bz_setData(tmp); \
return r; \
} \
}; \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(const Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr< name ## _et<P_numtype, N_rank> >(A); \
} \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr< name ## _et<P_numtype, N_rank> >(A); \
}
#define BZ_ET_STENCILV(name,rank) \
template<typename P_numtype, int N_rank> \
class name ## _et : public StencilExpr<P_numtype,N_rank, \
TinyVector<P_numtype,rank> >, \
public ETBase<name ## _et<P_numtype,N_rank> > \
{ \
private: \
typedef StencilExpr<P_numtype,N_rank,TinyVector<P_numtype,rank> > T_base; \
using T_base::iter_; \
public: \
typedef TinyVector<P_numtype,rank> result; \
name ## _et(const Array<P_numtype,N_rank>& A) \
: StencilExpr<P_numtype,N_rank,result>(A) \
{ } \
result operator*() \
{ return name(iter_); } \
result operator()(const TinyVector<int,N_rank>& a) \
{ iter_.moveTo(a); return name(iter_); } \
result fastRead(int i) \
{ \
const P_numtype* tmp = iter_.data(); \
iter_._bz_setData(tmp + i); \
P_numtype r = name(iter_); \
iter_._bz_setData(tmp); \
return r; \
} \
}; \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(const Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr< name ## _et<P_numtype, N_rank> >(A); \
} \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr< name ## _et<P_numtype, N_rank> >(A); \
}
#define BZ_ET_STENCIL_SCA(name) \
template<typename P_numtype, int N_rank> \
class name ## _et : public StencilExpr<P_numtype,N_rank, \
_bz_typename multicomponent_traits<P_numtype>::T_element>, \
public ETBase<name ## _et<P_numtype,N_rank> > \
{ \
private: \
typedef StencilExpr<P_numtype,N_rank, \
_bz_typename multicomponent_traits<P_numtype>::T_element> T_base; \
using T_base::iter_; \
public: \
typedef _bz_typename multicomponent_traits<P_numtype>::T_element result; \
name ## _et(const Array<P_numtype,N_rank>& A) \
: StencilExpr<P_numtype,N_rank,result>(A) \
{ } \
result operator*() \
{ return name(iter_); } \
result operator()(const TinyVector<int,N_rank>& a) \
{ iter_.moveTo(a); return name(iter_); } \
result fastRead(int i) \
{ \
const P_numtype* tmp = iter_.data(); \
iter_._bz_setData(tmp + i); \
P_numtype r = name(iter_); \
iter_._bz_setData(tmp); \
return r; \
} \
}; \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(const Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr< name ## _et<P_numtype, N_rank> >(A); \
} \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(Array<P_numtype,N_rank>& A) \
{ \
return _bz_ArrayExpr< name ## _et<P_numtype, N_rank> >(A); \
}
#define BZ_ET_STENCIL_DIFF(name) \
template<typename P_numtype, int N_rank> \
class name ## _et : public StencilExpr<P_numtype,N_rank,P_numtype>, \
public ETBase<name ## _et<P_numtype,N_rank> > \
{ \
private: \
typedef StencilExpr<P_numtype,N_rank,P_numtype> T_base; \
using T_base::iter_; \
public: \
name ## _et(const Array<P_numtype,N_rank>& A, int dim) \
: StencilExpr<P_numtype,N_rank,P_numtype>(A), dim_(dim) \
{ } \
P_numtype operator*() \
{ return name(iter_,dim_); } \
P_numtype operator()(const TinyVector<int,N_rank>& a) \
{ iter_.moveTo(a); return name(iter_,dim_); } \
P_numtype fastRead(int i) \
{ \
const P_numtype* tmp = iter_.data(); \
iter_._bz_setData(tmp + i); \
P_numtype r = name(iter_,dim_); \
iter_._bz_setData(tmp); \
return r; \
} \
private: \
int dim_; \
}; \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(const Array<P_numtype,N_rank>& A, int dim) \
{ \
return _bz_ArrayExpr<name ## _et<P_numtype, N_rank> >(A,dim); \
} \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(Array<P_numtype,N_rank>& A, int dim) \
{ \
return _bz_ArrayExpr<name ## _et<P_numtype, N_rank> >(A,dim); \
}
#define BZ_ET_STENCIL_DIFF2(name) \
template<typename P_numtype, int N_rank> \
class name ## _et : public StencilExpr<P_numtype,N_rank,P_numtype>, \
public ETBase<name ## _et<P_numtype,N_rank> > \
{ \
private: \
typedef StencilExpr<P_numtype,N_rank,P_numtype> T_base; \
using T_base::iter_; \
public: \
name ## _et(const Array<P_numtype,N_rank>& A, int dim1, int dim2) \
: StencilExpr<P_numtype,N_rank,P_numtype>(A),dim1_(dim1),dim2_(dim2) \
{ } \
P_numtype operator*() \
{ return name(iter_,dim1_,dim2_); } \
P_numtype operator()(const TinyVector<int,N_rank>& a) \
{ iter_.moveTo(a); return name(iter_,dim1_,dim2_); } \
P_numtype fastRead(int i) \
{ \
const P_numtype* tmp = iter_.data(); \
iter_._bz_setData(tmp + i); \
P_numtype r = name(iter_,dim1_,dim2_); \
iter_._bz_setData(tmp); \
return r; \
} \
private: \
int dim1_,dim2_; \
}; \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(const Array<P_numtype,N_rank>& A, int dim1, int dim2) \
{ \
return _bz_ArrayExpr<name ## _et<P_numtype, N_rank> >(A,dim1,dim2); \
} \
template<typename P_numtype, int N_rank> \
inline _bz_ArrayExpr<name ## _et<P_numtype, N_rank> > \
name(Array<P_numtype,N_rank>& A, int dim1, int dim2) \
{ \
return _bz_ArrayExpr<name ## _et<P_numtype, N_rank> >(A,dim1,dim2); \
}
BZ_ET_STENCIL_DIFF(central12)
BZ_ET_STENCIL_DIFF(central22)
BZ_ET_STENCIL_DIFF(central32)
BZ_ET_STENCIL_DIFF(central42)
BZ_ET_STENCIL_DIFF(central14)
BZ_ET_STENCIL_DIFF(central24)
BZ_ET_STENCIL_DIFF(central34)
BZ_ET_STENCIL_DIFF(central44)
BZ_ET_STENCIL_DIFF(central12n)
BZ_ET_STENCIL_DIFF(central22n)
BZ_ET_STENCIL_DIFF(central32n)
BZ_ET_STENCIL_DIFF(central42n)
BZ_ET_STENCIL_DIFF(central14n)
BZ_ET_STENCIL_DIFF(central24n)
BZ_ET_STENCIL_DIFF(central34n)
BZ_ET_STENCIL_DIFF(central44n)
BZ_ET_STENCIL_DIFF(backward11)
BZ_ET_STENCIL_DIFF(backward21)
BZ_ET_STENCIL_DIFF(backward31)
BZ_ET_STENCIL_DIFF(backward41)
BZ_ET_STENCIL_DIFF(backward12)
BZ_ET_STENCIL_DIFF(backward22)
BZ_ET_STENCIL_DIFF(backward32)
BZ_ET_STENCIL_DIFF(backward42)
BZ_ET_STENCIL_DIFF(backward11n)
BZ_ET_STENCIL_DIFF(backward21n)
BZ_ET_STENCIL_DIFF(backward31n)
BZ_ET_STENCIL_DIFF(backward41n)
BZ_ET_STENCIL_DIFF(backward12n)
BZ_ET_STENCIL_DIFF(backward22n)
BZ_ET_STENCIL_DIFF(backward32n)
BZ_ET_STENCIL_DIFF(backward42n)
BZ_ET_STENCIL_DIFF(forward11)
BZ_ET_STENCIL_DIFF(forward21)
BZ_ET_STENCIL_DIFF(forward31)
BZ_ET_STENCIL_DIFF(forward41)
BZ_ET_STENCIL_DIFF(forward12)
BZ_ET_STENCIL_DIFF(forward22)
BZ_ET_STENCIL_DIFF(forward32)
BZ_ET_STENCIL_DIFF(forward42)
BZ_ET_STENCIL_DIFF(forward11n)
BZ_ET_STENCIL_DIFF(forward21n)
BZ_ET_STENCIL_DIFF(forward31n)
BZ_ET_STENCIL_DIFF(forward41n)
BZ_ET_STENCIL_DIFF(forward12n)
BZ_ET_STENCIL_DIFF(forward22n)
BZ_ET_STENCIL_DIFF(forward32n)
BZ_ET_STENCIL_DIFF(forward42n)
BZ_ET_STENCIL(Laplacian2D, P_numtype)
BZ_ET_STENCIL(Laplacian3D, P_numtype)
BZ_ET_STENCIL(Laplacian2D4, P_numtype)
BZ_ET_STENCIL(Laplacian2D4n, P_numtype)
BZ_ET_STENCIL(Laplacian3D4, P_numtype)
BZ_ET_STENCIL(Laplacian3D4n, P_numtype)
BZ_ET_STENCILV(grad2D, 2)
BZ_ET_STENCILV(grad2D4, 2)
BZ_ET_STENCILV(grad3D, 3)
BZ_ET_STENCILV(grad3D4, 3)
BZ_ET_STENCILV(grad2Dn, 2)
BZ_ET_STENCILV(grad2D4n, 2)
BZ_ET_STENCILV(grad3Dn, 3)
BZ_ET_STENCILV(grad3D4n, 3)
BZ_ET_STENCILV(gradSqr2D, 2)
BZ_ET_STENCILV(gradSqr2D4, 2)
BZ_ET_STENCILV(gradSqr3D, 3)
BZ_ET_STENCILV(gradSqr3D4, 3)
BZ_ET_STENCILV(gradSqr2Dn, 2)
BZ_ET_STENCILV(gradSqr2D4n, 2)
BZ_ET_STENCILV(gradSqr3Dn, 3)
BZ_ET_STENCILV(gradSqr3D4n, 3)
BZ_ET_STENCILM(Jacobian3D, 3)
BZ_ET_STENCILM(Jacobian3Dn, 3)
BZ_ET_STENCILM(Jacobian3D4, 3)
BZ_ET_STENCILM(Jacobian3D4n, 3)
BZ_ET_STENCIL(curl3D, P_numtype)
BZ_ET_STENCIL(curl3Dn, P_numtype)
BZ_ET_STENCIL(curl3D4, P_numtype)
BZ_ET_STENCIL(curl3D4n, P_numtype)
BZ_ET_STENCIL(curl2D, P_numtype)
BZ_ET_STENCIL(curl2Dn, P_numtype)
BZ_ET_STENCIL(curl2D4, P_numtype)
BZ_ET_STENCIL(curl2D4n, P_numtype)
BZ_ET_STENCIL_SCA(div2D)
BZ_ET_STENCIL_SCA(div2Dn)
BZ_ET_STENCIL_SCA(div2D4)
BZ_ET_STENCIL_SCA(div2D4n)
BZ_ET_STENCIL_SCA(div3D)
BZ_ET_STENCIL_SCA(div3Dn)
BZ_ET_STENCIL_SCA(div3D4)
BZ_ET_STENCIL_SCA(div3D4n)
BZ_ET_STENCIL_DIFF2(mixed22)
BZ_ET_STENCIL_DIFF2(mixed22n)
BZ_ET_STENCIL_DIFF2(mixed24)
BZ_ET_STENCIL_DIFF2(mixed24n)
BZ_NAMESPACE_END
#endif // BZ_ARRAY_STENCIL_ET_H