18#ifndef LIBMESH_PARALLEL_EIGEN_H
19#define LIBMESH_PARALLEL_EIGEN_H
22#include "libmesh/libmesh_config.h"
23#include "libmesh/libmesh_common.h"
24#include "libmesh/int_range.h"
29#ifdef LIBMESH_HAVE_EIGEN
32#include "libmesh/ignore_warnings.h"
34#include "libmesh/restore_warnings.h"
41 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
42 class Packing<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
47 template <
typename Context>
48 static unsigned int packable_size(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &
object,
49 const Context *context);
51 template <
typename BufferIter>
54 template <
typename OutputIter,
typename Context>
55 static void pack(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &
object,
57 const Context *context);
59 template <
typename BufferIter,
typename Context>
60 static Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>
unpack(BufferIter in, Context *context);
63 template <
typename T2>
70 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
71 template <
typename Context>
73 Packing<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>::packable_size(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &mtx,
74 const Context * context)
76 const auto rows = mtx.rows();
77 const auto cols = mtx.cols();
80 std::size_t ints_per_data;
81 if constexpr (IsFixed<Scalar>)
84 ints_per_data = BufferCount(rows * cols);
93 constexpr std::size_t header_size = (Rows == Eigen::Dynamic) + (Cols == Eigen::Dynamic);
94 return header_size + ints_per_data;
97 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
98 template <
typename BufferIter>
102 constexpr std::size_t header_size = (Rows == Eigen::Dynamic) + (Cols == Eigen::Dynamic);
103 const std::size_t rows = Rows == Eigen::Dynamic ? *in++ : Rows;
104 const std::size_t cols = Cols == Eigen::Dynamic ? *in++ : Cols;
107 std::size_t ints_per_data;
108 if constexpr (IsFixed<Scalar>)
109 ints_per_data = BufferCount(rows * cols);
120 return header_size + ints_per_data;
123 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
124 template <
typename OutputIter,
typename Context>
126 Packing<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>::pack(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &mtx,
128 const Context *context)
130 const auto rows = mtx.rows();
131 const auto cols = mtx.cols();
134 if constexpr (Rows == Eigen::Dynamic)
136 if constexpr (Cols == Eigen::Dynamic)
140 if constexpr (IsFixed<Scalar>)
143 const auto *raw_data =
reinterpret_cast<const buffer_type *
>(mtx.data());
144 for (
const auto i :
make_range(BufferCount(rows * cols)))
145 *data_out++ = (raw_data[i]);
152 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
153 template <
typename BufferIter,
typename Context>
154 Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>
157 const std::size_t rows = Rows == Eigen::Dynamic ? *in++ : Rows;
158 const std::size_t cols = Cols == Eigen::Dynamic ? *in++ : Cols;
159 auto mtx = Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>(rows, cols);
162 if constexpr (IsFixed<Scalar>)
165 auto *raw_data =
reinterpret_cast<buffer_type *
>(mtx.data());
166 for (
const auto i :
make_range(BufferCount(rows * cols)))
static std::size_t BufferCount(std::size_t n)
std::pair< T1, T2 > unpack(BufferIter in, Context *ctx)
static unsigned int packed_size(BufferIter iter)
unsigned int packable_size(const std::pair< T1, T2 > &pr, const Context *ctx)
void pack(const std::pair< T1, T2 > &pr, OutputIter data_out, const Context *ctx)
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...