25#ifndef __SERIALIZER_HPP__
26#define __SERIALIZER_HPP__
45 void copyin(uint8_t
const* ptr__,
size_t nbytes__)
55 void copyout(uint8_t* ptr__,
size_t nbytes__)
63 if (source__ == dest__) {
71 int tag = mpi::Communicator::get_tag(source__, dest__);
73 if (comm__.
rank() == source__) {
75 RTE_ASSERT(sz <
static_cast<size_t>(std::numeric_limits<int>::max()));
76 r1 = comm__.isend(&sz, 1, dest__, tag++);
77 r2 = comm__.isend(&
stream_[0], (
int)sz, dest__, tag++);
80 if (comm__.
rank() == dest__) {
81 comm__.recv(&sz, 1, source__, tag++);
83 comm__.recv(&
stream_[0], (
int)sz, source__, tag++);
86 if (comm__.
rank() == source__) {
92 std::vector<uint8_t>
const& stream()
const
102 s__.
copyin(
reinterpret_cast<uint8_t const*
>(&var__),
sizeof(T));
109 s__.
copyout(
reinterpret_cast<uint8_t*
>(&var__),
sizeof(T));
114inline void serialize(
serializer& s__, std::vector<T>
const& vec__)
116 serialize(s__, vec__.size());
117 s__.
copyin(
reinterpret_cast<uint8_t const*
>(&vec__[0]),
sizeof(T) * vec__.size());
127 s__.
copyout(
reinterpret_cast<uint8_t*
>(&vec__[0]),
sizeof(T) * vec__.size());
131template <
typename T,
int N>
134 serialize(s__, array__.
size());
135 if (array__.
size() == 0) {
138 for (
int i = 0; i < N; i++) {
139 serialize(s__, array__.
dim(i).
begin());
140 serialize(s__, array__.
dim(i).
end());
142 s__.
copyin(
reinterpret_cast<uint8_t const*
>(&array__[0]),
sizeof(T) * array__.
size());
146template <
typename T,
int N>
155 std::array<sddk::mdarray_index_descriptor, N> dims;
156 for (
int i = 0; i < N; i++) {
157 sddk::mdarray_index_descriptor::index_type begin, end;
163 s__.
copyout(
reinterpret_cast<uint8_t*
>(&array__[0]),
sizeof(T) * array__.
size());
169 serialize(s__, dd__.num_ranks);
170 serialize(s__, dd__.counts);
171 serialize(s__, dd__.offsets);
MPI communicator wrapper.
int rank() const
Rank of MPI process inside communicator.
Index descriptor of mdarray.
index_type end() const
Return last index value.
index_type begin() const
Return first index value.
Multidimensional array with the column-major (Fortran) order.
mdarray_index_descriptor dim(int i) const
Return a descriptor of a dimension.
size_t size() const
Return total size (number of elements) of the array.
Serialize and deserialize objects.
void copyout(uint8_t *ptr__, size_t nbytes__)
Copy n bytes from the serialization stream.
size_t pos_
Position in the stream. This is used during unpacking.
std::vector< uint8_t > stream_
Data stream is represendted as a sequence of characters.
void copyin(uint8_t const *ptr__, size_t nbytes__)
Copy n bytes into a serialization stream.
Contains declaration and implementation of mpi::Communicator class.
Memory management functions and classes.
Namespace of the SIRIUS library.
void deserialize(serializer &s__, T &var__)
Deserialize a single element.