TIMPI
Loading...
Searching...
No Matches
post_wait_unpack_nested_buffer.h
Go to the documentation of this file.
1// The TIMPI Message-Passing Parallelism Library.
2// Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19#ifndef TIMPI_POST_WAIT_UNPACK_NESTED_BUFFER_H
20#define TIMPI_POST_WAIT_UNPACK_NESTED_BUFFER_H
21
22// TIMPI includes
23#include "timpi/communicator.h"
25#include "timpi/standard_type.h"
26
27namespace TIMPI
28{
29
30// PostWaitWork specialization for MPI_Unpack of nested buffers.
31// Container will most likely be vector<vector<T>>
32template <typename Container>
34 PostWaitUnpackNestedBuffer(const std::vector<char> & buffer,
35 Container & out,
37 const Communicator & comm_in) :
40#ifndef TIMPI_HAVE_MPI
41 timpi_not_implemented(); // This makes no sense without MPI_Unpack
42#endif
43 }
44
46#ifdef TIMPI_HAVE_MPI
47 // Not bothering with return type; we can't throw in a destructor
48 MPI_Type_free(&(type.operator data_type &()));
49#endif
50 }
51
52 virtual void run() override {
53#ifdef TIMPI_HAVE_MPI
54
55#if MPI_VERSION > 3
56# define TIMPI_COUNT_TYPE MPI_COUNT
57# define TIMPI_UNPACK MPI_Unpack_c
58#else
59# define TIMPI_COUNT_TYPE MPI_INT
60# define TIMPI_UNPACK MPI_Unpack
61#endif
62
63 // We should at least have one header datum, for outer vector size
64 timpi_assert (!recvbuf.empty());
65
66 // Unpack the received buffer
70 (TIMPI_UNPACK(recvbuf.data(), bufsize, &pos, &recvsize, 1,
72
73 // ... size the outer buffer
74 recv.resize (recvsize);
75
76 const std::size_t n_vecs = recvsize;
77 for (std::size_t i = 0; i != n_vecs; ++i)
78 {
80
84
85 // ... size the inner buffer
86 recv[i].resize (subvec_size);
87
88 // ... unpack the inner buffer if it is not empty
89 if (!recv[i].empty())
91 (TIMPI_UNPACK(recvbuf.data(), bufsize, &pos, recv[i].data(),
93 }
94#endif //TIMPI_HAVE_MPI
95 }
96
97private:
98 const std::vector<char> & recvbuf;
102};
103
104} // namespace TIMPI
105
106#endif // TIMPI_POST_WAIT_UNPACK_NESTED_BUFFER_H
Encapsulates the MPI_Comm object.
communicator & get()
Encapsulates the MPI_Datatype.
Definition data_type.h:51
MPI_Count CountType
Definition status.h:47
Tnew cast_int(Told oldvar)
PostWaitUnpackNestedBuffer(const std::vector< char > &buffer, Container &out, const DataType &timpi_mpi_var(T_type), const Communicator &comm_in)
An abstract base class that can be subclassed to allow other code to perform work after a MPI_Wait su...