TIMPI
Loading...
Searching...
No Matches
status.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_STATUS_H
20#define TIMPI_STATUS_H
21
22// TIMPI includes
23#include "timpi/data_type.h"
24#include "timpi/timpi_assert.h"
25#include "timpi/timpi_config.h"
26
27// C/C++ includes
28#ifdef TIMPI_HAVE_MPI
30# include "mpi.h"
32#endif // TIMPI_HAVE_MPI
33
34namespace TIMPI
35{
36
37#ifdef TIMPI_HAVE_MPI
38
39//-------------------------------------------------------------------
40
45
46# if MPI_VERSION > 3
48#define TIMPI_GET_COUNT MPI_Get_count_c
49# else
50typedef int CountType;
51#define TIMPI_GET_COUNT MPI_Get_count
52# endif
53
54#else
55
56// This shouldn't actually be needed, but must be
57// unique types for function overloading to work
58// properly.
59struct status { /* unsigned int s; */ };
60
61// This makes backwards compatibility easiest, and it should be fine
62// to use 32 bits here since serial operations are generally no-ops
63// that don't actually use a CountType
64typedef int CountType;
65
66#endif // TIMPI_HAVE_MPI
67
68
69
70//-------------------------------------------------------------------
75class Status
76{
77public:
78 Status () = default;
79 ~Status () = default;
80 Status (const Status &) = default;
81 Status (Status &&) = default;
82 Status & operator=(const Status &) = default;
83 Status & operator=(Status &&) = default;
84
85 explicit Status (const data_type & type);
86
87 explicit Status (const status & status);
88
89 Status (const status & status,
90 const data_type & type);
91
92 Status (const Status & status,
93 const data_type & type);
94
95 status * get() { return &_status; }
96
97 status const * get() const { return &_status; }
98
99 int source () const;
100
101 int tag () const;
102
103 data_type & datatype () { return _datatype; }
104
105 const data_type & datatype () const { return _datatype; }
106
107 CountType size (const data_type & type) const;
108
109 CountType size () const;
110
111private:
112
115};
116
117// ------------------------------------------------------------
118// Status member functions
119
120inline Status::Status (const data_type & type) :
121 _status(),
122 _datatype(type)
123{}
124
125inline Status::Status (const status & stat) :
126 _status(stat),
127 _datatype()
128{}
129
130inline Status::Status (const status & stat,
131 const data_type & type) :
132 _status(stat),
133 _datatype(type)
134{}
135
136inline Status::Status (const Status & stat,
137 const data_type & type) :
138 _status(stat._status),
139 _datatype(type)
140{}
141
142inline int Status::source () const
143{
144#ifdef TIMPI_HAVE_MPI
145 return _status.MPI_SOURCE;
146#else
147 return 0;
148#endif
149}
150
151inline int Status::tag () const
152{
153#ifdef TIMPI_HAVE_MPI
154 return _status.MPI_TAG;
155#else
157 return 0;
158#endif
159}
160
161inline CountType Status::size (const data_type & type) const
162{
163 ignore(type); // We don't use this ifndef TIMPI_HAVE_MPI
166 (TIMPI_GET_COUNT(const_cast<MPI_Status*>(&_status), type,
167 &msg_size));
168
170 return msg_size;
171}
172
173inline CountType Status::size () const
174{ return this->size (this->datatype()); }
175
176
177} // namespace TIMPI
178
179#endif // TIMPI_STATUS_H
Encapsulates the MPI_Status struct.
Definition status.h:76
data_type & datatype()
Definition status.h:103
~Status()=default
int source() const
Definition status.h:142
status const * get() const
Definition status.h:97
const data_type & datatype() const
Definition status.h:105
CountType size() const
Definition status.h:173
Status & operator=(const Status &)=default
Status()=default
status _status
Definition status.h:113
Status(Status &&)=default
Status(const Status &)=default
data_type _datatype
Definition status.h:114
int tag() const
Definition status.h:151
status * get()
Definition status.h:95
Status & operator=(Status &&)=default
MPI_Count CountType
Definition status.h:47
Tnew cast_int(Told oldvar)
void ignore(const Args &...)