TIMPI
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Attributes | Friends | List of all members
TIMPI::Request Class Reference

Encapsulates the MPI_Request. More...

#include <request.h>

Public Member Functions

 Request ()
 
 Request (const request &r)
 
 Request (const Request &other)
 
void cleanup ()
 
Requestoperator= (const Request &other)
 
Requestoperator= (const request &r)
 
 ~Request ()
 
requestget ()
 
const requestget () const
 
Status wait ()
 
bool test ()
 
bool test (status &status)
 
void add_prior_request (const Request &req)
 
void add_post_wait_work (PostWaitWork *work)
 

Static Public Attributes

static const request null_request = MPI_REQUEST_NULL
 

Private Attributes

request _request
 
std::unique_ptr< Request_prior_request
 
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
 

Friends

std::size_t waitany (std::vector< Request > &)
 Wait for at least one non-blocking operation to finish.
 

Detailed Description

Encapsulates the MPI_Request.

Definition at line 67 of file request.h.

Constructor & Destructor Documentation

◆ Request() [1/3]

TIMPI::Request::Request ( )

Definition at line 48 of file request.C.

48 :
50 post_wait_work(nullptr)
51{}
static const request null_request
Definition request.h:111
request _request
Definition request.h:114
std::pair< std::vector< PostWaitWork * >, unsigned int > * post_wait_work
Definition request.h:124

Referenced by add_prior_request(), operator=(), and Request().

◆ Request() [2/3]

TIMPI::Request::Request ( const request r)

Definition at line 53 of file request.C.

53 :
54 _request(r),
55 post_wait_work(nullptr)
56{}
Tnew cast_int(Told oldvar)

◆ Request() [3/3]

TIMPI::Request::Request ( const Request other)

Definition at line 58 of file request.C.

58 :
59 _request(other._request),
60 post_wait_work(other.post_wait_work)
61{
62 if (other._prior_request.get())
63 _prior_request = std::unique_ptr<Request>
64 (new Request(*other._prior_request.get()));
65
66 // operator= should behave like a shared pointer
68 post_wait_work->second++;
69}
std::unique_ptr< Request > _prior_request
Definition request.h:116

References _prior_request, TIMPI::cast_int(), post_wait_work, and Request().

◆ ~Request()

TIMPI::Request::~Request ( )

Definition at line 117 of file request.C.

117 {
118 this->cleanup();
119}
void cleanup()
Definition request.C:71

References cleanup().

Member Function Documentation

◆ add_post_wait_work()

void TIMPI::Request::add_post_wait_work ( PostWaitWork work)

Definition at line 204 of file request.C.

205{
206 if (!post_wait_work)
207 post_wait_work = new
208 std::pair<std::vector <PostWaitWork * >, unsigned int>
209 (std::vector <PostWaitWork * >(), 1);
210 post_wait_work->first.push_back(work);
211}

References TIMPI::cast_int(), and post_wait_work.

◆ add_prior_request()

void TIMPI::Request::add_prior_request ( const Request req)

Definition at line 190 of file request.C.

191{
192 // We're making a chain of prior requests, not a tree
193 timpi_assert(!req._prior_request.get());
194
196
197 // new_prior_req takes ownership of our existing _prior_request
198 new_prior_req->_prior_request.reset(this->_prior_request.release());
199
200 // Our _prior_request now manages the new resource we just set up
201 this->_prior_request.reset(new_prior_req);
202}

References _prior_request, TIMPI::cast_int(), and Request().

◆ cleanup()

void TIMPI::Request::cleanup ( )

Definition at line 71 of file request.C.

72{
74 {
75 // Decrement the use count
76 post_wait_work->second--;
77
78 if (!post_wait_work->second)
79 {
80#ifdef DEBUG
81 // If we're done using this request, then we'd better have
82 // done the work we waited for
83 for (const auto & item : post_wait_work->first)
85#endif
86 delete post_wait_work;
87 post_wait_work = nullptr;
88 }
89 }
90}

References TIMPI::cast_int(), and post_wait_work.

Referenced by operator=(), operator=(), and ~Request().

◆ get() [1/2]

request * TIMPI::Request::get ( )
inline

Definition at line 84 of file request.h.

84{ return &_request; }

References _request.

Referenced by TIMPI::Communicator::nonblocking_barrier(), TIMPI::Communicator::send(), and TIMPI::Communicator::send().

◆ get() [2/2]

const request * TIMPI::Request::get ( ) const
inline

Definition at line 86 of file request.h.

86{ return &_request; }

References _request.

◆ operator=() [1/2]

Request & TIMPI::Request::operator= ( const Request other)

Definition at line 92 of file request.C.

93{
94 this->cleanup();
95 _request = other._request;
96 post_wait_work = other.post_wait_work;
97
98 if (other._prior_request.get())
99 _prior_request = std::unique_ptr<Request>
100 (new Request(*other._prior_request.get()));
101
102 // operator= should behave like a shared pointer
103 if (post_wait_work)
104 post_wait_work->second++;
105
106 return *this;
107}

References _prior_request, _request, TIMPI::cast_int(), cleanup(), post_wait_work, and Request().

◆ operator=() [2/2]

Request & TIMPI::Request::operator= ( const request r)

Definition at line 109 of file request.C.

110{
111 this->cleanup();
112 _request = r;
113 post_wait_work = nullptr;
114 return *this;
115}

References _request, TIMPI::cast_int(), cleanup(), and post_wait_work.

◆ test() [1/2]

bool TIMPI::Request::test ( )

Definition at line 153 of file request.C.

154{
155#ifdef TIMPI_HAVE_MPI
156 int val=0;
157
160
161 if (val)
162 {
164 timpi_assert_equal_to (val, 1);
165 }
166
167 return val;
168#else
169 return true;
170#endif
171}

References _request, TIMPI::cast_int(), and null_request.

Referenced by TIMPI::detail::push_parallel_nbx_helper().

◆ test() [2/2]

bool TIMPI::Request::test ( status status)

Definition at line 174 of file request.C.

175{
176 int val=0;
177
179 (MPI_Test (&_request, &val, &stat));
180
181 return val;
182}

References _request, and TIMPI::cast_int().

◆ wait()

Status TIMPI::Request::wait ( )

Definition at line 121 of file request.C.

122{
123 TIMPI_LOG_SCOPE("wait()", "Request");
124
125 if (_prior_request.get())
126 {
127 _prior_request->wait();
128 _prior_request.reset(nullptr);
129 }
130
131 Status stat {};
132#ifdef TIMPI_HAVE_MPI
134 (MPI_Wait (&_request, stat.get()));
135#endif
136 if (post_wait_work)
137 {
138 for (auto & item : post_wait_work->first)
139 {
140 // The user should never try to give us non-existent work or try
141 // to wait() twice.
143 item->run();
144 delete item;
145 item = nullptr;
146 }
147 post_wait_work->first.clear();
148 }
149
150 return stat;
151}

References _prior_request, _request, TIMPI::cast_int(), and post_wait_work.

Referenced by TIMPI::detail::push_parallel_nbx_helper().

Friends And Related Symbol Documentation

◆ waitany

std::size_t waitany ( std::vector< Request > &  r)
friend

Wait for at least one non-blocking operation to finish.

Return the index of the request which completed.

Definition at line 219 of file request.C.

220{
221 timpi_assert(!r.empty());
222
223 int r_size = cast_int<int>(r.size());
224 std::vector<request> raw(r_size);
225 int non_null = r_size;
226 for (int i=0; i != r_size; ++i)
227 {
228 Request * root = &r[i];
229 // If we have prior requests, we need to complete the first one
230 // first
231 while (root->_prior_request.get())
232 root = root->_prior_request.get();
233 raw[i] = *root->get();
234
236 non_null = std::min(non_null,i);
237 }
238
239 if (non_null == r_size)
240 return std::size_t(-1);
241
242 int index = non_null;
243
244#ifdef TIMPI_HAVE_MPI
245 bool only_priors_completed = false;
246 Request * next;
247
248 do
249 {
252
254
256
257 Request * completed = &r[index];
258 next = completed;
259
260 // If we completed a prior request, we're not really done yet,
261 // so find the next in that line to try again.
262 while (completed->_prior_request.get())
263 {
265 next = completed;
266 completed = completed->_prior_request.get();
267 }
268
269 // MPI sets a completed MPI_Request to MPI_REQUEST_NULL; we want
270 // to preserve that
271 completed->_request = raw[index];
272
273 // Do any post-wait work for the completed request
274 if (completed->post_wait_work)
275 for (auto & item : completed->post_wait_work->first)
276 {
277 // The user should never try to give us non-existent work or try
278 // to wait() twice.
280 item->run();
281 delete item;
282 item = nullptr;
283 }
284
285 next->_prior_request.reset(nullptr);
286 raw[index] = *next->get();
287
288 } while(only_priors_completed);
289#else
290 r[index]._request = Request::null_request;
291#endif
292
293 return index;
294}

Member Data Documentation

◆ _prior_request

std::unique_ptr<Request> TIMPI::Request::_prior_request
private

Definition at line 116 of file request.h.

Referenced by add_prior_request(), operator=(), Request(), and wait().

◆ _request

request TIMPI::Request::_request
private

Definition at line 114 of file request.h.

Referenced by get(), get(), operator=(), operator=(), test(), test(), and wait().

◆ null_request

const request TIMPI::Request::null_request = MPI_REQUEST_NULL
static

Definition at line 111 of file request.h.

Referenced by test(), and testNonblockingWaitany().

◆ post_wait_work

std::pair<std::vector <PostWaitWork * >, unsigned int>* TIMPI::Request::post_wait_work
private

Definition at line 124 of file request.h.

Referenced by add_post_wait_work(), cleanup(), operator=(), operator=(), Request(), and wait().


The documentation for this class was generated from the following files: