16#include <fmt/format.h>
29 template <
class Derived>
35 auto dThis =
static_cast<const Derived *
>(
this);
36 return dThis->father.Size() + dThis->son.Size();
42 auto dThis =
static_cast<const Derived *
>(
this);
43 return dThis->father.RowSize();
49 auto dThis =
static_cast<const Derived *
>(
this);
50 if (i >= 0 && i < dThis->
father.Size())
51 return dThis->father.RowSize(i);
53 return dThis->son.RowSize(i - dThis->father.Size());
59 auto dThis =
static_cast<const Derived *
>(
this);
60 if (i >= 0 && i < dThis->
father.Size())
61 return dThis->father.operator[](i);
63 return dThis->son.operator[](i - dThis->father.Size());
69 auto dThis =
static_cast<Derived *
>(
this);
70 if (i >= 0 && i < dThis->
father.Size())
71 return dThis->father.operator[](i);
73 return dThis->son.operator[](i - dThis->father.Size());
78 template <
class... TOthers>
81 auto dThis =
static_cast<Derived *
>(
this);
82 if (i >= 0 && i < dThis->
father.Size())
83 return dThis->father.operator()(i, aOthers...);
85 return dThis->son.operator()(i - dThis->father.Size(), aOthers...);
89 template <
class... TOthers>
92 auto dThis =
static_cast<const Derived *
>(
this);
93 if (i >= 0 && i < dThis->
father.Size())
94 return dThis->father.operator()(i, aOthers...);
96 return dThis->son.operator()(i - dThis->father.Size(), aOthers...);
103 template <DeviceBackend B,
class TArray = ParArray<real, 1>>
120 template <DeviceBackend B,
class TArray = ParArray<real, 1>>
161 template <
class TArray = ParArray<real, 1>>
167 static constexpr bool IsCSR() {
return t_arr::IsCSR(); }
201 return father->operator[](i);
210 return father->operator[](i);
304 fmt::format(
"father and son need to be constructed before Trans Attach. Array is {}",
305 father ?
father->getObjectIdentity(TArray::GetArrayName()) : TArray::GetArrayName()));
321 template <
typename...
Args>
335 template <
class TPrimaryPair>
339 this->trans.BorrowGGIndexing(
primary.trans);
340 this->trans.createMPITypes();
341 this->trans.pullOnce();
348 template <
class TPrimaryPair>
352 this->trans.BorrowGGIndexing(
primary.trans);
353 this->trans.createMPITypes();
380 trans.reInitPersistentPullPush();
381 R.trans.reInitPersistentPullPush();
391 std::vector<index>
hashes;
428 father->WriteSerializer(
serializerP,
"father", Serializer::ArrayGlobalOffset_Parts);
430 son->WriteSerializer(
serializerP,
"son", Serializer::ArrayGlobalOffset_Parts);
436 serializerP->WriteIndexVector(
"pullingIndexGlobal",
trans.pLGhostMapping->ghostIndex, Serializer::ArrayGlobalOffset_Parts);
502 auto offsetV_son = Serializer::ArrayGlobalOffset_Unknown;
513 auto offsetV_PIG = Serializer::ArrayGlobalOffset_Unknown;
515 trans.createFatherGlobalMapping();
552 const std::string &name,
557 "Redistribution read only supported for collective (H5) serializers");
575 fmt::format(
"File has no origIndex and was written with np={}, "
576 "but reading with np={}. Cannot redistribute.",
589 auto mpi =
father->getMPI();
606 fmt::format(
"readPair.father size {} != fileOrigIndex size {}",
611 fmt::format(
"father size {} != newOrigIndex size {}",
623 auto offsetOrigIdx = Serializer::ArrayGlobalOffset_EvenSplit;
629 auto readFather = std::make_shared<TArray>(mpi);
631 auto offsetFather = Serializer::ArrayGlobalOffset_EvenSplit;
636 fmt::format(
"readFather size {} != fileOrigIndex size {}",
641 fmt::format(
"father size {} != newOrigIndex size {}",
652 template <DeviceBackend B>
656 template <DeviceBackend B>
660 template <DeviceBackend B>
664 fmt::format(
"need both father and son to exist for device view: {}",
665 father ?
father->getObjectIdentity(TArray::GetArrayName()) : TArray::GetArrayName()));
672 template <DeviceBackend B>
676 fmt::format(
"need both father and son to exist for device view: {}",
677 father ?
father->getObjectIdentity(TArray::GetArrayName()) : TArray::GetArrayName()));
687 father->to_device(backend);
689 son->to_device(backend);
703 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
707 template <rowsize _vec_size = 1, rowsize _row_max = _vec_size, rowsize _align = NoAlign>
721 template <
int _n_row,
int _n_col>
Adjacency array (CSR-like index storage) built on ParArray.
Batch of variable-sized Eigen matrices stored in CSR layout.
Eigen-matrix array: each row is an Eigen::Map<Matrix> over contiguous real storage.
Batch of uniform-sized Eigen matrices per row, with variable batch count.
Eigen-vector array: each row is an Eigen::Map over contiguous real storage.
Redistributes ArrayPair data across different MPI partitions using ArrayTransformer.
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
#define DNDS_DEVICE_CALLABLE
Device memory abstraction layer with backend-specific storage and factory creation.
Non-owning device-side views of Array objects for host and CUDA backends.
Assertion / error-handling macros and supporting helper functions.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
#define DNDS_check_throw_info(expr, info)
Same as DNDS_check_throw but attaches a user-supplied info message to the thrown std::runtime_error.
#define DNDS_check_throw(expr)
Runtime check active in both debug and release builds. Throws std::runtime_error if expr evaluates to...
ArrayDofDeviceView< B, n_m, n_n > t_deviceView
Mutable device view alias.
MPI_int Allgather(const void *sendbuf, MPI_int sendcount, MPI_Datatype sendtype, void *recvbuf, MPI_int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
Wrapper over MPI_Allgather.
ssp< SerializerBase > SerializerBaseSSP
the host side operators are provided as implemented
const MPI_Datatype DNDS_MPI_INDEX
MPI datatype matching index (= MPI_INT64_T).
DeviceBackend
Enumerates the backends a DeviceStorage / Array can live on.
DNDS_CONSTANT const rowsize NoAlign
Alignment flag: no padding applied to rows (the only currently-supported value).
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Const device view of a father-son array pair.
t_arrayDeviceView father
the only difference from non-const
typename TArray::template t_deviceViewConst< B > t_arrayDeviceView
CRTP base implementing the unified-index accessors shared by ArrayPairDeviceView and ArrayPairDeviceV...
DNDS_DEVICE_CALLABLE auto operator[](index i)
Row pointer for index i (mutable).
DNDS_DEVICE_CALLABLE auto RowSize() const
Uniform row width (delegates to father; father/son share it).
DNDS_DEVICE_CALLABLE index Size() const
Combined father + son row count.
DNDS_DEVICE_CALLABLE auto operator[](index i) const
Row pointer for index i in the combined address space (const).
DNDS_DEVICE_CALLABLE auto RowSize(index i) const
Per-row width in the combined address space.
Mutable device view onto an ArrayPair (for CUDA kernels).
typename TArray::template t_deviceView< B > t_arrayDeviceView
Convenience bundle of a father, son, and attached ArrayTransformer.
void TransAttach()
Bind the transformer to the current father / son pointers.
void ReadSerializeRedistributed(Serializer::SerializerBaseSSP serializerP, const std::string &name, const std::vector< index > &newOrigIndex)
Reads ArrayPair data from HDF5 with redistribution support.
decltype(father->operator[](index(0))) operator[](index i) const
Read-only row-pointer access in the combined address space.
void to_device(DeviceBackend backend)
Mirror both father and son to the given device backend.
ArrayPairDeviceView< B, TArray > t_deviceView
Device-view template alias: t_deviceView<DeviceBackend::CUDA> gives the mutable CUDA view type for th...
void SwapDataFatherSon(t_self &R)
Swap both father and son data with another pair of the same type.
void to_host()
Bring both father and son mirrors back to host memory.
ssp< TArray > father
Owned-side array (must be resized before ghost setup).
auto deviceView()
Produce a mutable device view; both father and son must be allocated.
void WriteSerialize(Serializer::SerializerBaseSSP serializerP, const std::string &name, bool includePIG=true, bool includeSon=true)
Writes the ArrayPair (father, optional son, optional ghost mapping).
auto deviceView() const
Produce a const device view.
void ResizeRow(index i, TOthers... aOthers)
Variadic ResizeRow overload that forwards extra args.
index Size() const
Combined row count (father->Size() + son->Size()).
void BorrowSetup(TPrimaryPair &primary)
Attach, borrow ghost indexing from a primary pair, and create MPI types (no pull).
static constexpr bool IsCSR()
Whether the underlying array uses CSR storage.
void InitPair(const std::string &name, Args &&...args)
Allocate both father and son arrays, forwarding all args to TArray constructor.
ssp< TArray > son
Ghost-side array (sized automatically by createMPITypes / BorrowAndPull).
std::size_t hash()
Combined hash across ranks. Used for determinism / equality checks in tests.
void clone(const t_self &R)
Deep-copy: allocate new father / son and copy their data; rebind trans.
void BorrowAndPull(TPrimaryPair &primary)
Attach, borrow ghost indexing from a primary pair, create MPI types, and pull once.
auto RowSize() const
Uniform row width (delegates to father).
void ResizeRow(index i, rowsize rs)
Resize a single row in the combined address space.
void ReadSerialize(Serializer::SerializerBaseSSP serializerP, const std::string &name, bool includePIG=true, bool includeSon=true)
Reads an ArrayPair written by WriteSerialize (same partition count).
TTrans trans
Ghost-communication engine bound to father and son.
void WriteSerialize(Serializer::SerializerBaseSSP serializerP, const std::string &name, const std::vector< index > &origIndex, bool includePIG=true, bool includeSon=true)
Writes the ArrayPair with an origIndex companion dataset for redistribution support.
decltype(father->operator[](index(0))) operator[](index i)
Mutable row-pointer access in the combined address space.
void CopyFather(t_self &R)
Copy only the father's data from another pair (shallow).
auto RowSize(index i) const
Per-row width in the combined address space.
void CompressBoth()
Compress both father and son CSR arrays (no-op for non-CSR layouts).
auto runFunctionAppendedIndex(index i, TF &&F)
Invoke F(array, localIndex) on either father or son depending on which range i falls into.
typename ArrayTransformerType< TArray >::Type TTrans
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Tag type for naming objects created via make_ssp.