2 #ifndef _PROTO_RECTMDARRAY_H_ 3 #define _PROTO_RECTMDARRAY_H_ 14 #include <unordered_map> 15 #include <type_traits> 33 #ifdef PROTO_MEM_CHECK 34 struct BoxDataMemCheck
36 static BoxDataMemCheck& instance()
38 static BoxDataMemCheck inst;
50 inline static int& numCopies() {
return instance().m_numCopies; }
51 inline static int& numFastCopies() {
return instance().m_numFastCopies; }
52 inline static int& numSlowCopies() {
return instance().m_numSlowCopies; }
53 inline static int& numMoveAssign() {
return instance().m_numMoveAssign; }
55 inline static void clear()
72 using std::shared_ptr;
77 template<
typename T,
unsigned int C, MemType MEM,
unsigned int D,
unsigned int E>
80 template<
typename T,
unsigned int C, MemType MEM,
unsigned int D,
unsigned int E>
116 unsigned int D=1,
unsigned int E=1>
124 inline T& getValDevice(
unsigned int a_c,
unsigned int a_d = 0,
unsigned int a_e = 0)
126 int idx = threadIdx.x + blockIdx.x*blockDim.x;
127 int idy = blockIdx.y;
129 int idz = blockIdx.z;
130 return (m_ptrs[a_c + C*a_d + C*D*a_e])[idx + boxDimX * (idy + idz * boxDimY)];
132 return (m_ptrs[a_c + C*a_d + C*D*a_e])[idx + idy * boxDimX];
138 inline T& getValDevice(
unsigned int a_c,
unsigned int a_d = 0,
unsigned int a_e = 0)
140 return *(m_ptrs[a_c + C*a_d + C*D*a_e]);
144 inline T&
getValDevice(
unsigned int a_c,
unsigned int a_d = 0,
unsigned int a_e = 0)
146 return *(m_ptrs[a_c + C*a_d + C*D*a_e]);
159 __attribute__((always_inline))
160 T& operator()(
unsigned int a_c,
unsigned int a_d = 0,
unsigned int a_e = 0)
162 PROTO_ASSERT(a_c < C,
"Var::operator() | Error: index out of bounds");
163 PROTO_ASSERT(a_d < D,
"Var::operator() | Error: index out of bounds");
164 PROTO_ASSERT(a_e < E,
"Var::operator() | Error: index out of bounds");
167 return getValDevice(a_c,a_d,a_e);
170 return *(m_ptrs[a_c + C*a_d + C*D*a_e]);
184 inline const T& getValDevice(
186 unsigned int a_d = 0,
187 unsigned int a_e = 0)
const 189 int idx = threadIdx.x + blockIdx.x*blockDim.x;
190 int idy = blockIdx.y;
192 int idz = blockIdx.z;
193 return (m_ptrs[a_c + C*a_d + C*D*a_e])[idx + boxDimX * (idy + idz * boxDimY)];
195 return (m_ptrs[a_c + C*a_d + C*D*a_e])[idx + idy * boxDimX];
201 inline const T& getValDevice(
203 unsigned int a_d = 0,
204 unsigned int a_e = 0)
const 206 return *(m_ptrs[a_c + C*a_d + C*D*a_e]);
210 inline const T& getValDevice(
212 unsigned int a_d = 0,
213 unsigned int a_e = 0)
const 215 return *(m_ptrs[a_c + C*a_d + C*D*a_e]);
220 __attribute__((always_inline))
223 unsigned int a_d = 0,
224 unsigned int a_e = 0)
const 228 return getValDevice(a_c,a_d,a_e);
231 return *(m_ptrs[a_c + C*a_d + C*D*a_e]);
237 for (
int ii = 0; ii < C*D*E; ii++)
239 m_ptrs[ii] += a_increment;
249 unsigned int shift = a_p[0] + (a_p[1] + a_p[2]*boxDimY)*boxDimX;
251 unsigned int shift = a_p[0] + a_p[1]*boxDimX;
260 unsigned int shift = a_p[0] + (a_p[1] + a_p[2]*boxDimY)*boxDimX;
262 unsigned int shift = a_p[0] + a_p[1]*boxDimX;
268 inline Var& operator++()
270 for (
int ii = 0; ii < C*D*E; ii++)
278 inline Var& operator--()
280 for (
int ii = 0; ii < C*D*E; ii++)
287 unsigned int boxDimX;
311 template <
class T=double,
unsigned int C=1,
313 unsigned int D=1,
unsigned int E=1>
372 void define(
const Box& a_box);
377 template<
unsigned int ncomp>
379 unsigned int& a_comp);
392 BoxData(
const T* a_ptr,
const Box& a_box,
int a_ncomp = C);
405 void define(
const T* a_ptr,
const Box& a_box,
int a_ncomp = C);
425 BoxData(LazyStencil<T,C,MEM,D,E>&& a_op);
433 BoxData(shared_ptr<T> a_data,
const T* a_ptr,
const Box& a_box);
460 template<MemType MEM_DEST>
479 template<MemType MEM_DEST>
483 const Point& a_destShift = Point::Zeros())
const;
492 template<MemType MEM_DEST>
495 const Box& a_destBox)
const;
515 template <
unsigned int Cdest,
MemType MEM_DEST,
516 unsigned int Ddest,
unsigned int Edest>
521 const Point& a_destShift,
539 template<
unsigned int Csrc>
543 unsigned int a_srcComp,
544 const Box& a_destBox,
545 unsigned int a_destComp,
546 unsigned int a_numcomp);
592 unsigned int a_c = 0,
593 unsigned int a_d = 0,
594 unsigned int a_e = 0)
const;
611 inline T& operator()(
613 unsigned int a_c = 0,
614 unsigned int a_d = 0,
615 unsigned int a_e = 0)
const;
633 inline const T* operator[](
unsigned int a_index)
const;
642 inline T* operator[](
unsigned int a_index);
654 inline const T* data(
656 unsigned int a_c = 0,
657 unsigned int a_d = 0,
658 unsigned int a_e = 0)
const;
672 unsigned int a_c = 0,
673 unsigned int a_d = 0,
674 unsigned int a_e = 0);
686 unsigned int a_c = 0,
687 unsigned int a_d = 0,
688 unsigned int a_e = 0);
695 inline const T* data(
696 unsigned int a_c = 0,
697 unsigned int a_d = 0,
698 unsigned int a_e = 0)
const;
705 inline ::std::shared_ptr<T>
aliasData() {
return m_data; }
712 inline ::std::shared_ptr<T>
aliasData()
const {
return m_data; }
727 inline std::size_t
size()
const {
return m_box.size()*C*D*E;};
728 inline std::size_t
numValues()
const {
return m_box.size()*C*D*E; }
734 inline bool defined()
const {
return bool(m_data);};
764 inline void operatorT(
const T a_scale);
916 inline void incrementProduct(
const BoxData<T,C,MEM,D,E>& A,
const BoxData<T,C,MEM,D,E>& B, T scale = 1);
930 inline void setVal(
const T& a_val);
947 inline void setToZero();
959 inline void setVal(
const T& a_val,
const Box& a_box);
971 inline void setVal(
const T& a_val,
978 inline void setRandom(T a_low, T a_high);
987 template<Proto::Operation OP>
1000 template<Proto::Operation OP>
1007 inline T absMax()
const;
1017 inline T absMax(
int a_c,
int a_d = 0,
int a_e = 0)
const;
1044 inline T min()
const;
1054 inline T min(
int a_c,
int a_d = 0,
int a_e = 0)
const;
1081 inline T max()
const;
1091 inline T max(
int a_c,
int a_d = 0,
int a_e = 0)
const;
1118 inline T sum()
const;
1128 inline T sum(
int a_c,
int a_d = 0,
int a_e = 0)
const;
1155 inline T sumAbs()
const;
1165 inline T sumAbs(
int a_c,
int a_d = 0,
int a_e = 0)
const;
1189 inline T sumSquare()
const;
1190 inline T sumSquare(
int a_c,
int a_d = 0,
int a_e = 0)
const;
1204 inline T integrate(T a_dx,
int a_c = 0,
int a_d = 0,
int a_e = 0)
const;
1218 int a_c = 0,
int a_d = 0,
int a_e = 0)
const;
1228 inline void shift(
const Point& a_shift)
const;
1260 unsigned int a_startcomp,
1261 unsigned int a_numcomps)
const;
1293 const ::Proto::Box& a_bx,
1294 unsigned int a_startcomp,
1295 unsigned int a_numcomps);
1303 inline bool contains(
CInterval a_interval)
const;
1311 template<
unsigned int CC,
unsigned int DD,
unsigned int EE>
1328 void printData(
int a_prec = 2)
const;
1340 void printData(
const Box& a_box,
int a_prec = 2)
const;
1356 void printData(
const Box& a_box,
int a_c,
int a_d,
int a_e,
int a_prec = 2)
const;
1358 bool containsInfOrNAN()
const;
1359 bool containsInfOrNAN(
Box domain)
const;
1360 bool containsUninitialized()
const;
1361 bool containsUninitialized(
Box domain)
const;
1362 bool containsAddress(T* address)
const;
1371 template<
class TT,
unsigned int CC,
unsigned int DD,
unsigned int EE,MemType MM>
1373 const Point& a_shift);
1375 template<
class TT,
unsigned int CC,
unsigned int DD,
unsigned int EE,MemType MM>
1377 const Point& a_shift);
1379 template<
typename _T,
unsigned int _C, MemType _MEM,
unsigned int _D,
unsigned int _E>
1386 template<
typename _T,
unsigned int _C,
unsigned int _CC, MemType _MEM>
1389 unsigned int a_nstart);
1391 template<
typename _T,
unsigned int _C,
unsigned int _D, MemType _MEM>
1398 const size_t a_comps)
const 1400 return a_box.
size() * (
sizeof(T) * a_comps);
1406 unsigned int a_startcomp,
1407 unsigned int a_numcomps)
const 1409 return a_bx.size()*
sizeof(T)*a_numcomps;
1434 template<
class T = double,
unsigned int C=1,
1442 define(a_box, a_doExtrude);
1451 "FluxBoxData::constructor | Error: input vector must have DIM components");
1452 for (
int ii = 0; ii < DIM; ii++)
1454 m_data[ii] = a_data[ii];
1467 m_data[
dir] = std::make_shared<BoxData<T,C,MEM,D,E>>(Bd);
1474 "FluxBoxData::operator[] | Error: index out of bounds");
1475 return *(m_data[a_index]);
1481 "FluxBoxData::operator[] | Error: index out of bounds");
1482 return *(m_data[a_index]);
1487 Box box(
int a_dir)
const {
return m_data[a_dir]->box(); }
1515 template<
class T,
unsigned int C=1,
unsigned int D=1,
unsigned int E=1,
1519 const Point& a_shift = Point::Zeros());
1528 template<
class T,
unsigned int C = 1,
unsigned int D = 1,
unsigned int E = 1,
1532 const Point& a_shift=Point::Zeros());
1544 unsigned int D=1,
unsigned int E=1>
1548 unsigned int a_d = 0,
1549 unsigned int a_e = 0);
1558 template<
typename T,
unsigned int C,
unsigned int CC, MemType MEM=MEMTYPE_DEFAULT>
1561 unsigned int a_startcomp);
1563 template<
typename T,
unsigned int C,
unsigned int D, MemType MEM=MEMTYPE_DEFAULT>
1570 template <
typename T,
unsigned int CL,
unsigned int CR,
MemType MEM,
1571 unsigned int DL,
unsigned int DR,
unsigned int E = 1>
1578 template <
typename T,
unsigned int CL,
unsigned int CR,
MemType MEM,
1579 unsigned int DL,
unsigned int DR,
unsigned int E = 1>
1586 template <
typename T,
unsigned int CL,
unsigned int CR,
MemType MEM,
1587 unsigned int DL,
unsigned int DR,
unsigned int E = 1>
1595 #endif //end include guard Definition: Proto_BoxData.H:89
ACCEL_DECORATION std::size_t size(unsigned int a_dim) const
Edge Size.
Box m_box0
Definition: Proto_BoxData.H:1489
std::enable_if< I< sizeof...(LArgs), void >::typecall_mb_level_forall(Func &a_func, MBIndex &a_index, Centering CTR, std::tuple< LArgs... > a_args, FArgs &&... a_fargs){ auto &arg=parse_mb_level_arg(a_index, CTR, std::get< I >a_args));call_mb_level_forall< I+1 >a_func, a_index, CTR, a_args, a_fargs..., arg);}template< typename T, unsigned int C, MemType MEM, Centering CTR >template< typename Func, typename... Srcs >void MBLevelBoxData< T, C, MEM, CTR >::initialize(Func &a_func, Srcs &... a_srcs){ auto srcs=std::tuple< Srcs &... >a_srcs...);for(auto iter :(m_layout)) { auto &patch=(*this)[iter];auto block=layout().block(iter);call_mb_level_forall(a_func, iter, CTR, srcs, patch, block);} }template< typename T, unsigned int C, MemType MEM, Centering CTR >template< typename Func, typename... Srcs >void MBLevelBoxData< T, C, MEM, CTR >::initConvolve(Func &a_func, Srcs &... a_srcs){ auto g=ghost();g[0]=g[0]+Point::Ones();MBLevelBoxData< T, C, MEM, CTR > tmp(m_layout, g);tmp.initialize(a_func, a_srcs...);for(auto iter :m_layout) { auto &tmp_i=tmp[iter];auto &patch=(*this)[iter];Operator::convolve(patch, tmp_i);}}template< typename T, unsigned int C, MemType MEM, Centering CTR >void MBLevelBoxData< T, C, MEM, CTR >::setVal(T a_value){ for(auto data :m_data) { data-> setVal(a_value)
Definition: Proto_MBLevelBoxData.H:208
unsigned int subBoxDimY
Definition: Proto_BoxData.H:290
inline ::std::shared_ptr< T > aliasData()
Shared Buffer Accessor.
Definition: Proto_BoxData.H:705
unsigned int subBoxDimX
Definition: Proto_BoxData.H:289
int linearSize(const T &inputT)
Definition: Proto_PointLIO.H:55
std::size_t size() const
Definition: Proto_BoxData.H:727
inline ::std::shared_ptr< T > aliasData() const
Shared Buffer Accessor (Const)
Definition: Proto_BoxData.H:712
bool m_stackAlloc
Definition: Proto_BoxData.H:1428
FluxBoxData()
Definition: Proto_BoxData.H:1439
Array< std::shared_ptr< BoxData< T, C, MEM, D, E > >, DIM > m_data
Definition: Proto_BoxData.H:1490
BoxDataOp
Definition: Proto_BoxData.H:86
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
void linearOut(void *const a_outBuf, const T &inputT)
Definition: Proto_PointLIO.H:67
unsigned int boxDimY
Definition: Proto_BoxData.H:288
A Linear Stencil Operation.
Definition: Proto_BoxData.H:76
Definition: Proto_MemType.H:7
BoxData< T, CC, MEM, 1, 1 > slice(const BoxData< T, C, MEM, 1, 1 > &a_src, unsigned int a_startcomp)
Vector Slice (Non-Const)
Definition: Proto_BoxData.H:88
MemType
Definition: Proto_MemType.H:7
BoxData< T, CL, MEM, DR, E > matrixProduct(const BoxData< T, CL, MEM, DL, E > &A, const BoxData< T, CR, MEM, DR, E > &B, T scale=1.0)
static int memTypeAllocation()
Definition: Proto_BoxData.H:1421
Defines discrete rotations in logically rectangular coordinate systems.
Definition: Proto_CoordPermutation.H:13
Box extrude(const Point &a_dir, int a_dist=1) const
Extrude.
std::size_t numValues() const
Definition: Proto_BoxData.H:728
Definition: Proto_BoxData.H:95
Definition: Proto_BoxData.H:81
Component-Space Interval.
Definition: Proto_CInterval.H:14
T * m_rawPtr
Raw pointer to the data.
Definition: Proto_BoxData.H:1431
FluxBoxData(const Box &a_box, bool a_doExtrude=true)
Definition: Proto_BoxData.H:1440
const Array< std::shared_ptr< BoxData< T, C, MEM, D, E > >, DIM > & array() const
Definition: Proto_BoxData.H:1485
An interval in DIM dimensional space.
Definition: Proto_Box.H:29
Definition: Proto_BoxData.H:94
size_t charsize(const ::Proto::Box &a_bx, unsigned int a_startcomp, unsigned int a_numcomps) const
Definition: Proto_BoxData.H:1405
Definition: Proto_Reduction.H:30
Definition: Proto_BoxData.H:93
Definition: Proto_BoxData.H:92
void define(const Box &a_box, bool a_doExtrude=true)
Definition: Proto_BoxData.H:1457
#define ACCEL_DECORATION
Definition: Proto_Accel.H:12
Box box() const
Definition: Proto_BoxData.H:1486
static int preAllocatable()
Definition: Proto_BoxData.H:1415
MBPoint operator+(const MBPoint &mbpoint, const Point &p)
Definition: Proto_MBProblemDomain.H:55
#define PROTO_ASSERT(stmt, args...)
Definition: Proto_PAssert.H:48
bool defined() const
Defined Query.
Definition: Proto_BoxData.H:734
size_t size(const Box &a_box, const size_t a_comps) const
Definition: Proto_BoxData.H:1397
Box box() const
Definition: Proto_BoxData.H:719
Definition: Proto_Array.H:17
uint64_t index
Definition: Proto_MBBoxPartition.H:15
const BoxData< T, C, MEM, D, E > & operator[](unsigned int a_index) const
Definition: Proto_BoxData.H:1478
Definition: Proto_BoxData.H:90
T & getValDevice(unsigned int a_c, unsigned int a_d=0, unsigned int a_e=0)
Definition: Proto_BoxData.H:144
BoxData< T, DL, MEM, DR, E > matrixProductLeftTranspose(const BoxData< T, CL, MEM, DL, E > &A, const BoxData< T, CR, MEM, DR, E > &B, T scale=1.0)
ACCEL_DECORATION Array< T, N > & operator*(int scale, Array< T, N > &arr)
Premultiplication by a scalar int.
A templated constant size array object similar to std::array, but with the ability to be used inside ...
Definition: Proto_Array.H:28
Integer Valued Vector.
Definition: Proto_Point.H:24
ACCEL_DECORATION Array< T, N > & operator-(Array< T, N > &arr)
Unary negation.
FluxBoxData(Array< std::shared_ptr< BoxData< T, C, MEM, D, E >>, DIM > &a_data)
Definition: Proto_BoxData.H:1444
BoxData< T, C, MEM, 1, 1 > plane(const BoxData< T, C, MEM, D, 1 > &a_src, unsigned int a_d)
Definition: Proto_BoxData.H:91
Box m_box
Box defining the domain of *this.
Definition: Proto_BoxData.H:1429
void linearIn(T &a_outputT, const void *const inBuf)
Definition: Proto_PointLIO.H:61
Point dir
Definition: Proto_MBBoxPartition.H:16
void null_deleter_boxdata(void *ptr)
Definition: Proto_BoxData.H:84
::std::shared_ptr< T > m_data
Data array.
Definition: Proto_BoxData.H:1430
BoxData< T, C, MEM, D, E > & operator+=(BoxData< T, C, MEM, D, E > &a_dst, const LazyInterpStencil< T, C, MEM, D, E > &&a_op)
Definition: Proto_InterpStencil.H:84
FluxBoxData(std::vector< std::shared_ptr< BoxData< T, C, MEM, D, E >>> &a_data)
Definition: Proto_BoxData.H:1448
BoxData< T, CL, MEM, CR, E > matrixProductRightTranspose(const BoxData< T, CL, MEM, DL, E > &A, const BoxData< T, CR, MEM, DR, E > &B, T scale=1.0)
Box box(int a_dir) const
Definition: Proto_BoxData.H:1487
Pointwise Variable.
Definition: Proto_BoxData.H:117
#define MEMTYPE_DEFAULT
Definition: Proto_MemType.H:24
Var< T, C, MEM, D, E > reference
Definition: Proto_BoxData.H:318
bool m_alias
was this created as an alias
Definition: Proto_BoxData.H:1427
Array< std::shared_ptr< BoxData< T, C, MEM, D, E > >, DIM > & array()
Definition: Proto_BoxData.H:1484
const BoxData< T, C, MEM, D, E > alias(const BoxData< T, C, MEM, D, E > &a_original, const Point &a_shift=Point::Zeros())
Alias (Const)
BoxData< T, C, MEM, D, E > & operator[](unsigned int a_index)
Definition: Proto_BoxData.H:1471
Definition: Proto_BoxData.H:1436