1 #ifndef MUSTER_GATHER_H
2 #define MUSTER_GATHER_H
29 int parent = binomial.
parent(rank);
30 std::vector<int> children = binomial.
children(rank);
32 std::vector<int> sizes;
33 sizes.push_back(src.packed_size(comm));
35 for (
size_t i=0; i < children.size(); i++) {
38 CMPI_Recv(&cur_size, 1, MPI_INT, children[i], 0, comm, MPI_STATUS_IGNORE);
39 sizes.push_back(cur_size);
43 std::vector<int> offsets;
45 std::partial_sum(sizes.begin(), sizes.end(), back_inserter(offsets));
48 std::vector<char> sendbuf(accumulate(sizes.begin(), sizes.end(), 0));
52 src.pack(&sendbuf[0], sendbuf.size(), &pos, comm);
55 for (
size_t i = 0; i < children.size(); i++) {
56 CMPI_Recv(&sendbuf[offsets[i+1]], sizes[i+1], MPI_PACKED, children[i], 0, comm, MPI_STATUS_IGNORE);
61 int size = sendbuf.size();
62 CMPI_Send(&size, 1, MPI_INT, parent, 0, comm);
63 CMPI_Send(&sendbuf[0], sendbuf.size(), MPI_PACKED, parent, 0, comm);
79 dest.resize(binomial.
size());
80 for (
size_t i=0; i < binomial.
size(); i++) {
81 dest[binomial.
reverse_relative_rank(i)] = T::unpack(const_cast<char*>(&src[0]), src.size(), &pos, comm);
90 void gather(
const T& src, std::vector<T>& dest, MPI_Comm comm,
int root = 0) {
97 std::vector<char> packed;
111 void allgather(
const T& src, std::vector<T>& dest, MPI_Comm comm,
int root = 0) {
118 std::vector<char> packed;
121 size_t packed_size = packed.size();
124 packed.resize(packed_size);
125 CMPI_Bcast(const_cast<char*>(&packed[0]), packed.size(), MPI_PACKED, root, comm);
132 #endif // MUSTER_GATHER_H
void unpack_binomial(const std::vector< char > &src, std::vector< T > &dest, const binomial_embedding binomial, MPI_Comm comm)
Unpacks a packed vector in binomial order into objects in rank order in the destination vector...
void gather_packed(const T &src, std::vector< char > &dest, const binomial_embedding binomial, MPI_Comm comm)
Packs and gathers a buffer full of packed representation of src's.
void allgather(const T &src, std::vector< T > &dest, MPI_Comm comm, int root=0)
Allgather for variable-length data.
int reverse_relative_rank(int rank) const
Reverse rank permutation.
std::vector< int > children(int rank) const
Same as get_children, but returns vector.
int parent(int rank) const
Get the parent of a particular rank.
Overloaded utility functions to convert between arbitrary C/C++ types and MPI types, custom typedefs for cstdlib types like size_t, and a wrapper for MPI_Pack_Size.
void gather(const T &src, std::vector< T > &dest, MPI_Comm comm, int root=0)
Binomial gather of char buffers into a single agglomerated clump of buffers.
#defines for switching between MPI and PMPI bindings.