Data.h

class Cubism::Block::DataBase

Type-less base class for a data block.

For byte-level operations on the data only.

Subclassed by Cubism::Block::Data< T, Entity, DIM, BlockAlloc >, Cubism::Block::Data< T, Entity, DIM, Alloc< T > >, Cubism::Block::Data< TField::DataType, TField::EntityType, TField::IndexRangeType::Dim, Cubism::AlignedBlockAllocator< TField::DataType > >

Public Functions

inline virtual void *getBlockPtr()

Mutable pointer to address of first data element.

Return

Address of first data block byte

inline virtual const void *getBlockPtr() const

Immutable pointer to address of first data element.

Return

Address of first data block byte

inline virtual size_t getBlockBytes() const

Number of bytes occupied by block.

Return

Number of block bytes

inline virtual size_t getDataElementBytes() const

Number of bytes occupied by a single data element.

Return

Number of block bytes

inline virtual size_t getBlockSize() const

Number of data elements contained in block.

Return

Number of block data elements

template<typename T, Cubism::EntityType Entity, size_t DIM, typename BlockAlloc = AlignedBlockAllocator<T>>
class Cubism::Block::Data : public Cubism::Block::DataBase

Generic block data.

Data type that manages memory allocation and data access for the specified index range spanned by the data.

Note

The memory allocation for a block may be larger than the minimum required data specified by the index range.

Template Parameters
  • T: Data type

  • Entity: Entity type

  • DIM: Data dimensionality

  • BlockAlloc: Allocator type

Public Types

enum MemoryOwner

Specifies memory ownership.

Values:

enumerator No
enumerator Yes

Public Functions

inline explicit Data(const IndexRangeType &r)

Base constructor for single block allocation.

The index range defines the spatial dimensionality of the data. The block memory is touched by the thread that calls the constructor.

Parameters
  • r: Index range of data

inline Data(const Data &c, const MemoryOwner owner)

General purpose copy-constructor mainly for data views.

The block memory is touched by the thread that calls the constructor.

Parameters
  • c: Data block to copy from

  • owner: Memory ownership

inline Data(const IndexRangeType &r, DataType *ptr, const size_t bytes)

Low-level constructor for externally managed memory.

The block owns the memory but does not deallocate it at destruction.

Parameters
  • r: Index range of data pointed to by ptr

  • ptr: Block data pointer to first element

  • bytes: Number of bytes of block data.

inline Data(const Data &c)

Copy constructor.

Depending on ownership of the memory, copy is deep or shallow. Relevant for views.

Parameters
  • c: Block data to copy from

inline Data(Data &&c) noexcept

Move constructor.

Move constructions are always shallow. Ownership of the memory is inherited from the source.

Parameters
  • c: Block data to copy from

inline ~Data() override

Virtual destructor.

inline virtual void *getBlockPtr() override

Mutable pointer to address of first data element.

Return

Address of first data block byte

inline virtual const void *getBlockPtr() const override

Immutable pointer to address of first data element.

Return

Address of first data block byte

inline virtual size_t getBlockBytes() const override

Number of bytes occupied by block.

Return

Number of block bytes

inline virtual size_t getDataElementBytes() const override

Number of bytes occupied by a single data element.

Return

Number of block bytes

inline virtual size_t getBlockSize() const override

Number of data elements contained in block.

Return

Number of block data elements

inline DataType *getData()

Get pointer to data.

Return

Pointer to first data element

inline const DataType *getData() const

Get pointer to data.

Return

const pointer to first data element

inline Data &operator=(const Data &c)

Copy assignment operator.

Depending on ownership of memory, copy is deep or shallow. Relevant for views.

Return

This instance with updated data

Parameters
  • c: Block data to assign from

inline Data &operator=(Data &&c)

Move assignment operator.

Move constructions are always shallow. Ownership of the memory is inherited from the source.

Return

This instance with moved data

Parameters
  • c:

inline DataType &operator[](size_t i)

Linear data access.

Return

Reference to data element

Parameters
  • i: Local flat index

inline const DataType &operator[](size_t i) const

Linear data access.

Return

const reference to data element

Parameters
  • i: Local flat index

inline DataType &operator[](const MultiIndex &p)

Linear data access.

Return

Reference to data element

Parameters
  • p: Local multi-dimensional index

inline const DataType &operator[](const MultiIndex &p) const

Linear data access.

Return

const reference to data element

Parameters
  • p: Local multi-dimensional index

inline DataType &operator()(const Index ix, const Index iy = 0, const Index iz = 0)

Classic data access.

This operator is only supported for dimensions 1, 2 and 3. Accessing data with this operator has less latency than the multi-index sibling.

Return

Reference to data element

Parameters
  • ix: Index for first dimension

  • iy: Index for second dimension

  • iz: Index for third dimension

inline const DataType &operator()(const Index ix, const Index iy = 0, const Index iz = 0) const

Classic data access.

This operator is only supported for dimensions 1, 2 and 3. Accessing data with this operator has less latency than the multi-index sibling.

Return

const reference to data element

Parameters
  • ix: Index for first dimension

  • iy: Index for second dimension

  • iz: Index for third dimension

inline void copyData(const Data &c)

Deep copy data.

Copies data unconditionally.

Parameters
  • c: Block data to copy from

inline IndexRangeType getIndexRange(const size_t = 0) const

Get index range.

Return

Index range spanned by the data

inline bool isMemoryOwner() const

Test for memory ownership.

Return

True if memory is owned by this instance

inline MemoryOwner getMemoryOwnership() const

Get memory ownership.

Return

Enumeration type describing the memory ownership

inline virtual BlockBytes getMemoryFootprint() const

Get byte utilization of block.

Return

Structure of byte usage for this instance

Public Static Attributes

static constexpr Cubism::EntityType EntityType = Entity

Specifies entity type of data.

struct BlockBytes

Byte utilization compound.