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 39 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
40 class Packing<
Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
45 template <
typename Context>
46 static unsigned int packable_size(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &
object,
47 const Context *context);
49 template <
typename BufferIter>
52 template <
typename OutputIter,
typename Context>
53 static void pack(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &
object,
55 const Context *context);
57 template <
typename BufferIter,
typename Context>
58 static Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>
unpack(BufferIter in, Context *context);
61 template <
typename T2>
68 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
69 template <
typename Context>
71 Packing<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>::packable_size(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &mtx,
72 const Context * context)
74 const auto rows = mtx.rows();
75 const auto cols = mtx.cols();
78 std::size_t ints_per_data;
79 if constexpr (IsFixed<Scalar>)
82 ints_per_data = BufferCount(rows * cols);
91 constexpr std::size_t header_size = (Rows == Eigen::Dynamic) + (Cols == Eigen::Dynamic);
92 return header_size + ints_per_data;
95 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
96 template <
typename BufferIter>
100 constexpr std::size_t header_size = (Rows == Eigen::Dynamic) + (Cols == Eigen::Dynamic);
101 const std::size_t rows = Rows == Eigen::Dynamic ? *in++ : Rows;
102 const std::size_t cols = Cols == Eigen::Dynamic ? *in++ : Cols;
105 std::size_t ints_per_data;
106 if constexpr (IsFixed<Scalar>)
107 ints_per_data = BufferCount(rows * cols);
118 return header_size + ints_per_data;
121 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
122 template <
typename OutputIter,
typename Context>
124 Packing<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>::pack(
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &mtx,
126 const Context *context)
128 const auto rows = mtx.rows();
129 const auto cols = mtx.cols();
132 if constexpr (Rows == Eigen::Dynamic)
134 if constexpr (Cols == Eigen::Dynamic)
138 if constexpr (IsFixed<Scalar>)
141 const auto *raw_data =
reinterpret_cast<const buffer_type *
>(mtx.data());
142 for (
const auto i :
make_range(BufferCount(rows * cols)))
143 *data_out++ = (raw_data[i]);
150 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
151 template <
typename BufferIter,
typename Context>
152 Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>
155 const std::size_t rows = Rows == Eigen::Dynamic ? *in++ : Rows;
156 const std::size_t cols = Cols == Eigen::Dynamic ? *in++ : Cols;
157 auto mtx = Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>(rows, cols);
160 if constexpr (IsFixed<Scalar>)
163 auto *raw_data =
reinterpret_cast<buffer_type *
>(mtx.data());
164 for (
const auto i :
make_range(BufferCount(rows * cols)))
181 #endif // LIBMESH_HAVE_EIGEN 183 #endif // LIBMESH_PARALLEL_EIGEN_H static std::size_t BufferCount(std::size_t n)
The libMesh namespace provides an interface to certain functionality in the library.
static T unpack(BufferIter in, Context *ctx)
static unsigned int packable_size(const T &object, const Context *context)
void libmesh_ignore(const Args &...)
static unsigned int packed_size(BufferIter iter)
static void pack(const T &object, OutputIter data_out, const Context *context)
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...