OpenMP Backend

The OpenMP backend provides CPU-based parallel computation using OpenMP. It is the default backend and always available.

API Reference

Like every backend, the OpenMP backend implements classes representing block multivectors and block matrices and views of individual blocks for these types.

template<class ScalarT, unsigned int block_size>
class BlockMultivector

OpenMP multivector backed by aligned host memory.

Backend specifics:

  • Allocates 64-byte aligned memory using std::aligned_alloc.

  • Blocks are stored contiguously in row-major order.

  • Zero-initialized on construction.

  • Not copyable, only movable.

Public Functions

inline BlockMultivector(std::size_t rows, unsigned int cols)

Allocates a block multivector of the given size.

Allocates memory aligned to 64 bytes. If rows * cols is not a multiple of alignment, the next larger multiple is used as the allocation size (this is a requirement of std::aligned_alloc). The aligned memory is zero-initialised.

Throws:

std::invalid_argument – if cols is not divisible by blocksize.

inline BlockView block_view(std::size_t i) const

Returns a view of the i-th block.

The returned view is a lightweight std::span-like object that does not own the data.

Throws:

std::out_of_range – if i is not a valid block index.

inline std::size_t blocks() const

Returns the number of blocks in the multivector.

template<class ScalarT, unsigned int block_size>
class BlockView

OpenMP block view backed by aligned host memory.

Backend specifics:

  • Data is stored in row-major order with 64-byte alignment.

  • Operations use OpenMP parallel loops and SIMD pragmas.

  • The view is lightweight (std::span-like); copying the view is cheap but does not copy the underlying data.

  • dot() uses thread-local buffers combined in a critical section.

Public Functions

inline void set_zero()

Sets all entries to zero.

Computes \( X_{ij} = 0 \) for all \( i, j \).

inline std::size_t rows() const

Returns the number of rows in the block.

inline constexpr std::size_t cols() const

Returns the block size (number of columns).

inline void copy_from(BlockView other)

Copies data from another block view.

Computes the element-wise assignment \( X = Y \).

inline BlockView &operator-=(BlockView other)

Subtracts another block view element-wise.

Computes \( X = X - Y \) where X is this block view.

inline void mult_add(MatrixBlockView W, BlockView other)

Computes matrix-block product and adds to result.

Computes \( Y = Y + X W \) where X is this block view, W is a small square block matrix, and Y is the output.

inline void mult(MatrixBlockView W, BlockView other)

Computes matrix-block product.

Computes \( Y = X W \) where X is this block view and W is a small square block matrix.

inline void mult_transpose(MatrixBlockView W, BlockView other)

Computes matrix-block product with transposed block matrix.

Computes \( Y = X W^T \) where X is this block view and \( W^T \) is the transpose of the block matrix.

inline void dot(BlockView other, MatrixBlockView R)

Computes block inner product.

Computes \( R = X^T Y \) where X is this block view, Y is the other block view, and R is a small square block matrix.

Implementation:

Uses thread-local buffers to accumulate partial results, which are combined in a critical section to avoid race conditions.

inline void subtract_product(BlockView other, MatrixBlockView R)

Subtracts a matrix-block product from this block view.

Computes \( X = X - Y R \) where X is this block view, Y is another block view, and R is a small square block matrix.

template<class ScalarT, unsigned int block_size>
class BlockMatrix

OpenMP block matrix backed by aligned host memory.

Backend specifics:

  • Allocates 64-byte aligned memory using std::aligned_alloc.

  • Zero-initialized on construction.

  • Not copyable or movable.

Public Functions

inline std::size_t block_rows() const

Returns the number of block rows.

inline std::size_t block_cols() const

Returns the number of block columns.

inline BlockView block_view(std::size_t block_row, std::size_t block_col) const

Returns a view of the block at position (block_row, block_col).

The returned view is a lightweight object that does not own the data.

template<class ScalarT, unsigned int block_size>
class BlockMatrixBlockView

OpenMP matrix block view backed by aligned host memory.

Backend specifics:

  • Stores a raw pointer to row-major data.

  • All operations are executed sequentially on the CPU.

  • No parallelism within block operations (blocks are typically small).

Public Functions

inline void copy_from(BlockMatrixBlockView other)

Copies matrix data from another block.

Computes the element-wise assignment \( A = B \).

inline void copy_from_transpose(BlockMatrixBlockView other)

Copies transposed matrix data from another block.

Computes \( A = B^T \) where A is this block.

inline void set_zero()

Sets all matrix entries to zero.

Computes \( A_{ij} = 0 \) for all \( i, j \).

inline void mult(BlockMatrixBlockView B, BlockMatrixBlockView C)

Computes matrix-matrix product.

Computes \( C = A B \) where A is this block matrix.

inline void set_diagonal(std::span<ScalarT> values)

Sets the diagonal entries of the matrix.

Sets \( A_{ii} \) to values[i] for all diagonal indices \( i \). Off-diagonal entries remain unchanged.