15 static const index Offset_Parts = -1;
17 static const index Offset_One = -2;
19 static const index Offset_EvenSplit = -3;
56 "Overflow in ArrayGlobalOffset size multiplication");
58 "Overflow in ArrayGlobalOffset offset multiplication");
81 DNDS_assert_info(_size % R == 0, fmt::format(
"_size [{}] must be multiple of R [{}]", _size, R));
82 DNDS_assert_info(_offset % R == 0, fmt::format(
"_offset [{}] must be multiple of R [{}]", _offset, R));
91 return _size == other._size && _offset == other._offset;
93 return _offset == other._offset;
97 operator std::string()
const
99 return fmt::format(
"ArrayGlobalOffset{{size: {}, offset: {}}}", _size, _offset);
111 o << (std::string)(
v);
117 static const ArrayGlobalOffset ArrayGlobalOffset_Unknown = ArrayGlobalOffset{0, Offset_Unknown};
119 static const ArrayGlobalOffset ArrayGlobalOffset_One = ArrayGlobalOffset{0, Offset_One};
121 static const ArrayGlobalOffset ArrayGlobalOffset_Parts = ArrayGlobalOffset{0, Offset_Parts};
124 static const ArrayGlobalOffset ArrayGlobalOffset_EvenSplit = ArrayGlobalOffset{0, Offset_EvenSplit};
159 std::map<void *, std::pair<std::shared_ptr<void>, std::string>>
ptr_2_pth;
171 outPath = it->second.second;
181 ptr_2_pth[
v.get()] = {std::static_pointer_cast<void>(
v), path};
195 virtual void OpenFile(
const std::string &fName,
bool read) = 0;
217 virtual void WriteInt(
const std::string &name,
int v) = 0;
223 virtual void WriteString(
const std::string &name,
const std::string &
v) = 0;
258 virtual void ReadInt(
const std::string &name,
int &
v) = 0;
264 virtual void ReadString(
const std::string &name, std::string &
v) = 0;
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
Device memory abstraction layer with backend-specific storage and factory creation.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
MPI wrappers: MPIInfo, collective operations, type mapping, CommStrategy.
Host-device vector types with optional GPU storage and device-side views.
Describes one rank's window into a globally-distributed dataset.
index offset() const
Global offset of this rank's data (or a sentinel value, see Offset_Parts etc.).
index size() const
Local size this rank owns (in element units of the caller's choosing).
ArrayGlobalOffset operator*(index R) const
Scale the descriptor's element count by R (and the offset too if it is a real offset,...
bool isDist() const
Whether this descriptor carries a real distributed offset (rather than a sentinel like Offset_Parts).
friend std::ostream & operator<<(std::ostream &o, const ArrayGlobalOffset &v)
ArrayGlobalOffset(index __size, index __offset)
Construct with explicit local size and global offset.
bool operator==(const ArrayGlobalOffset &other) const
Equality: sentinel offsets compare only by offset, real-offset descriptors compare by the full (size,...
ArrayGlobalOffset operator/(index R) const
Inverse of operator*. Real-offset descriptors scale both size and offset; sentinel descriptors only s...
void CheckMultipleOf(index R) const
Assert that both size and offset are multiples of R.
Abstract interface for reading/writing scalars, vectors, and byte arrays.
virtual bool IsPerRank()=0
Whether this serializer is per-rank (JSON-file-per-rank) or collective (shared H5 file)....
virtual std::set< std::string > ListCurrentPath()=0
Names of direct children of the current path.
virtual void CloseFile()=0
Close the backing file, flushing buffers.
virtual ~SerializerBase()
virtual void ReadReal(const std::string &name, real &v)=0
Read a scalar real into v.
void dedupRegister(const ssp< T > &v, const std::string &path)
Register a shared pointer after writing its data.
virtual void WriteIndexVector(const std::string &name, const std::vector< index > &v, ArrayGlobalOffset offset)=0
Write an index vector (collective for H5). offset carries the distribution mode (ArrayGlobalOffset_Pa...
virtual void WriteString(const std::string &name, const std::string &v)=0
Write a UTF-8 string under name.
virtual void ReadInt(const std::string &name, int &v)=0
Read a scalar int into v.
std::map< void *, std::pair< std::shared_ptr< void >, std::string > > ptr_2_pth
virtual void ReadIndexVector(const std::string &name, std::vector< index > &v, ArrayGlobalOffset &offset)=0
virtual void ReadString(const std::string &name, std::string &v)=0
Read a UTF-8 string into v.
virtual void CreatePath(const std::string &p)=0
Create a sub-path (H5 group / JSON object) at the current location.
virtual const MPIInfo & getMPI()=0
MPI context the serializer was opened with.
virtual void WriteSharedIndexVector(const std::string &name, const ssp< host_device_vector< index > > &v, ArrayGlobalOffset offset)=0
Write a shared index vector; deduplicated across multiple writes that share the same shared_ptr.
virtual void WriteRealVector(const std::string &name, const std::vector< real > &v, ArrayGlobalOffset offset)=0
Write a real vector (collective for H5).
virtual void WriteSharedRowsizeVector(const std::string &name, const ssp< host_device_vector< rowsize > > &v, ArrayGlobalOffset offset)=0
Write a shared rowsize vector; deduplicated across multiple writes.
virtual void ReadUint8Array(const std::string &name, uint8_t *data, index &size, ArrayGlobalOffset &offset)=0
Two-pass byte array read.
virtual std::string GetCurrentPath()=0
String form of the current path.
bool dedupLookup(const ssp< T > &v, std::string &outPath)
Check if a shared pointer was already written; if so return its path.
std::map< std::string, void * > pth_2_ssp
Reverse map for read-side dedup: path -> raw pointer to the ssp local variable.
virtual void ReadRealVector(const std::string &name, std::vector< real > &v, ArrayGlobalOffset &offset)=0
virtual int GetMPIRank()=0
Rank index cached by the serializer (relevant for collective I/O).
virtual void WriteIndex(const std::string &name, index v)=0
Write a scalar index under name.
void dedupClear()
Clear all dedup state (call on CloseFile).
virtual void WriteIndexVectorPerRank(const std::string &name, const std::vector< index > &v)=0
Write a per-rank index vector (replicated name, independent values).
virtual void WriteInt(const std::string &name, int v)=0
Write a scalar int under name at the current path.
virtual void ReadRowsizeVector(const std::string &name, std::vector< rowsize > &v, ArrayGlobalOffset &offset)=0
virtual void WriteUint8Array(const std::string &name, const uint8_t *data, index size, ArrayGlobalOffset offset)=0
Write a raw byte buffer under name. offset.isDist() = true means the caller provides the exact per-ra...
virtual int GetMPISize()=0
Rank count cached by the serializer.
virtual void OpenFile(const std::string &fName, bool read)=0
Open a backing file (H5 file or JSON file depending on subclass).
virtual void ReadSharedRowsizeVector(const std::string &name, ssp< host_device_vector< rowsize > > &v, ArrayGlobalOffset &offset)=0
virtual void WriteReal(const std::string &name, real v)=0
Write a scalar real under name.
virtual void ReadIndex(const std::string &name, index &v)=0
Read a scalar index into v.
virtual void WriteRowsizeVector(const std::string &name, const std::vector< rowsize > &v, ArrayGlobalOffset offset)=0
Write a rowsize vector (collective for H5).
virtual void ReadSharedIndexVector(const std::string &name, ssp< host_device_vector< index > > &v, ArrayGlobalOffset &offset)=0
virtual void GoToPath(const std::string &p)=0
Navigate to an existing path. Supports / -separated segments.
Host + optional device vector of trivially copyable T.
ssp< SerializerBase > SerializerBaseSSP
DNDS_CONSTANT const index UnInitIndex
Sentinel "not initialised" index value (= INT64_MIN).
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Eigen::Matrix< real, 5, 1 > v