TIMPI
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
29 # include "timpi/ignore_warnings.h"
30 # include "mpi.h"
31 # include "timpi/restore_warnings.h"
32 #endif // TIMPI_HAVE_MPI
33 
34 namespace TIMPI
35 {
36 
37 #ifdef TIMPI_HAVE_MPI
38 
39 //-------------------------------------------------------------------
40 
44 typedef MPI_Status status;
45 
46 # if MPI_VERSION > 3
47 typedef MPI_Count CountType;
48 #define TIMPI_GET_COUNT MPI_Get_count_c
49 # else
50 typedef 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.
59 struct 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
64 typedef int CountType;
65 
66 #endif // TIMPI_HAVE_MPI
67 
68 
69 
70 //-------------------------------------------------------------------
75 class Status
76 {
77 public:
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 
111 private:
112 
115 };
116 
117 // ------------------------------------------------------------
118 // Status member functions
119 
120 inline Status::Status (const data_type & type) :
121  _status(),
122  _datatype(type)
123 {}
124 
125 inline Status::Status (const status & stat) :
126  _status(stat),
127  _datatype()
128 {}
129 
130 inline Status::Status (const status & stat,
131  const data_type & type) :
132  _status(stat),
133  _datatype(type)
134 {}
135 
136 inline Status::Status (const Status & stat,
137  const data_type & type) :
138  _status(stat._status),
139  _datatype(type)
140 {}
141 
142 inline int Status::source () const
143 {
144 #ifdef TIMPI_HAVE_MPI
145  return _status.MPI_SOURCE;
146 #else
147  return 0;
148 #endif
149 }
150 
151 inline int Status::tag () const
152 {
153 #ifdef TIMPI_HAVE_MPI
154  return _status.MPI_TAG;
155 #else
156  timpi_not_implemented();
157  return 0;
158 #endif
159 }
160 
161 inline CountType Status::size (const data_type & type) const
162 {
163  ignore(type); // We don't use this ifndef TIMPI_HAVE_MPI
164  CountType msg_size = 1;
165  timpi_call_mpi
166  (TIMPI_GET_COUNT(const_cast<MPI_Status*>(&_status), type,
167  &msg_size));
168 
169  timpi_assert_greater_equal (msg_size, 0);
170  return msg_size;
171 }
172 
173 inline CountType Status::size () const
174 { return this->size (this->datatype()); }
175 
176 
177 } // namespace TIMPI
178 
179 #endif // TIMPI_STATUS_H
const data_type & datatype() const
Definition: status.h:105
void ignore(const Args &...)
Definition: timpi_assert.h:54
int source() const
Definition: status.h:142
status _status
Definition: status.h:113
MPI_Status status
Status object for querying messages.
Definition: status.h:44
Status & operator=(const Status &)=default
data_type & datatype()
Definition: status.h:103
int tag() const
Definition: status.h:151
data_type _datatype
Definition: status.h:114
MPI_Count CountType
Definition: status.h:47
~Status()=default
CountType size() const
Definition: status.h:173
Status()=default
Encapsulates the MPI_Status struct.
Definition: status.h:75