MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
maia::collector_memory Namespace Reference

Helper functions useful for allocating collector memory.

Namespaces

namespace  unaligned_cell_wise
 

Functions

template<class T , class U >
U * align (U *p)
 Aligns pointer p such that a T stored at its adress is aligned. More...
 
template<class T >
void rowMajor1D (T *&p, void *&base, const MInt cellId, const MInt Nrows, const MInt maxNoCells)
 Stores 1D variables in row-major order. More...
 
template<class T >
 ATTRIBUTES1 (ATTRIBUTE_NO_AUTOVEC) inline void rowMajor2D(T **&p
 Stores 2D variables in row-major order. More...
 
 for (MInt i=0;i< Nrows;++i)
 
template<class T >
void copyElements1D (T *to, T *from, const MInt Nrows)
 Copies 1D cell elements. More...
 
template<class T >
void copyElements2D (T *to, T *from, const MInt Nrows, const MInt Ncols)
 Copies 2D cell elements. More...
 

Variables

void *& base = align<T>(base)
 
void const MInt cellId
 
void const MInt const MInt Nrows
 
void const MInt const MInt const MInt Ncols
 
void const MInt const MInt const MInt const MInt maxNoCells
 

Function Documentation

◆ align()

template<class T , class U >
U * maia::collector_memory::align ( U *  p)
inline
Parameters
[in]pPointer to align such that a T stored there is aligned
[out]p_alignedAligned pointer >= p that can store an aligned T
Returns
an aligned pointer > p such that a T stored there is aligned

Definition at line 187 of file collector.h.

187 {
188 const MLong N = sizeof(T);
189 const MLong padding = reinterpret_cast<MLong>(static_cast<void*>(p)) % N;
190 if(padding == 0) {
191 return p;
192 } else {
193 return reinterpret_cast<U*>(reinterpret_cast<char*>(p) + padding);
194 }
195}
int64_t MLong
Definition: maiatypes.h:64

◆ ATTRIBUTES1()

template<class T >
maia::collector_memory::ATTRIBUTES1 ( ATTRIBUTE_NO_AUTOVEC  ) &

In memory, an array of pointers is stored first. The variables itself are allocated behind it. | ptr_0, ..., ptr_(maxNoCells*Nrows) | var_(0,0), ..., var_(maxNoCells*Nrows,maxNoCells*Ncols) | ^^^^^^ base point here

The array of pointers provides 2D access and is stored as follows: ... | ptr_to_cell_(cellId)_v(0,0), ptr_to_cell_(cellId)_v(1,0), ..., ptr_to_cell_(cellId)_v(Nrows,0) | ptr_to_cell_(cellId+1)_v(0,0), ... | ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ p is set to point here!

The variables are stored as follows: ...| cell_(cellId)_v(0,0), cell_(cellId)_v(0,1), ..., cell_(cellId)_v(1,0), cell_(cellId)_v(1,1), ..., .... cell_(cellId)_v(Nrows,Ncols) | cell_(cellId+1)_v(0,0), ..., | ... ^^^^^^^^^^^^^^^^^^^^^ ptr_to_cell_(cellId)_v(0,0) ^^^^^^^^^^^^^ ptr_to_cell_(cellId)_v(1,0) points here!

Parameters
[out]pIs set to point to the first pointer of the cell variables.
[in,out]basePointer to the start of the variable's memory region.
[in]cellIdId of the cell.
[in]NrowsNumber of variables to store per cell.
[in]maxNoCellsMaximum number of cells to be allocated (used for offset computation).

◆ copyElements1D()

template<class T >
void maia::collector_memory::copyElements1D ( T *  to,
T *  from,
const MInt  Nrows 
)
inline
Parameters
[in]toElements will be copied here.
[in]fromElements to be copied.
[in]NrowsNumber of elements to copy

Definition at line 258 of file collector.h.

258 {
259 for(MInt i = 0; i < Nrows; ++i) {
260 to[i] = from[i];
261 }
262}
int32_t MInt
Definition: maiatypes.h:62
void const MInt const MInt Nrows
Definition: collector.h:239

◆ copyElements2D()

template<class T >
void maia::collector_memory::copyElements2D ( T *  to,
T *  from,
const MInt  Nrows,
const MInt  Ncols 
)
inline

Nrows*Ncols elements will be copied.

Parameters
[in]toElements will be copied here.
[in]fromElements to be copied.
[in]NrowsNumber of rows
[in]NcolsNumber of columns

Definition at line 273 of file collector.h.

273 {
274 for(MInt i = 0; i < Nrows; ++i) {
275 for(MInt j = 0; j < Ncols; ++j) {
276 to[i][j] = from[i][j];
277 }
278 }
279}
void const MInt const MInt const MInt Ncols
Definition: collector.h:239

◆ for()

maia::collector_memory::for ( )

Definition at line 245 of file collector.h.

245 {
246 p[i] =
247 reinterpret_cast<T*>(base) + static_cast<MLong>(1) * Nrows * Ncols * cellId + static_cast<MLong>(1) * i * Ncols;
248 }
void const MInt cellId
Definition: collector.h:239

◆ rowMajor1D()

template<class T >
void maia::collector_memory::rowMajor1D ( T *&  p,
void *&  base,
const MInt  cellId,
const MInt  Nrows,
const MInt  maxNoCells 
)
inline

I.e. the variables are stored in memory as follows: cell_(0)_v(0) ... cell_(0)_v(Nrows) | ... | cell_(cellId)_v(0), cell_(cellId)_v(1), ..., cell_(cellId)_v(Nrows) | cell_(cellId+1)_v(0), ..., | ... ^^^^^^^^^^^^^ base points here! ^^^^^^^^^^^^^^^^^^^ p is set to point here

Parameters
[out]pIs set to point to the first cell variable.
[in,out]basePointer to the start of the variable's memory region.
[in]cellIdId of the cell.
[in]NrowsNumber of variables to store per cell.
[in]maxNoCellsMaximum number of cells to be allocated (used for offset computation).

Definition at line 210 of file collector.h.

210 {
211 base = align<T>(base);
212 p = reinterpret_cast<T*>(base) + static_cast<MLong>(1) * Nrows * cellId;
213 base = reinterpret_cast<void*>(reinterpret_cast<T*>(base) + static_cast<MLong>(1) * Nrows * maxNoCells);
214}
void const MInt const MInt const MInt const MInt maxNoCells
Definition: collector.h:240

Variable Documentation

◆ base

maia::collector_memory::base = align<T>(base)

Definition at line 239 of file collector.h.

◆ cellId

void const MInt maia::collector_memory::cellId

Definition at line 239 of file collector.h.

◆ maxNoCells

void const MInt const MInt const MInt const MInt maia::collector_memory::maxNoCells
Initial value:
{
rowMajor1D(p, base, cellId, Nrows, maxNoCells)
void rowMajor1D(T *&p, void *&base, const MInt cellId, const MInt Nrows, const MInt maxNoCells)
Stores 1D variables in row-major order.
Definition: collector.h:210

Definition at line 240 of file collector.h.

◆ Ncols

void const MInt const MInt const MInt maia::collector_memory::Ncols

Definition at line 239 of file collector.h.

◆ Nrows

void const MInt const MInt maia::collector_memory::Nrows

Definition at line 239 of file collector.h.