Skip to content

Commit

Permalink
Simplify ucxx::RequestTagMulti final status logic (#144)
Browse files Browse the repository at this point in the history
The current way to handle the final status of `ucxx::RequestTagMulti` involves looping all requests, this change simplifies that by simply caching the status of the first request error. Additionally this prevents checking the status of the final request if it hasn't been set yet, which would then return `UCS_INPROGRESS` instead.

Authors:
  - Peter Andreas Entschev (https://github.com/pentschev)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)

URL: #144
  • Loading branch information
pentschev authored Dec 6, 2023
1 parent c5e9957 commit 13a663b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
2 changes: 2 additions & 0 deletions cpp/include/ucxx/request_tag_multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class RequestTagMulti : public Request {
std::mutex
_completedRequestsMutex{}; ///< Mutex to control access to completed requests container
size_t _completedRequests{0}; ///< Count requests that already completed
ucs_status_t _finalStatus{
UCS_OK}; ///< Shortcut to the final status, a.k.a. the first error to occur

public:
std::vector<BufferRequestPtr> _bufferRequests{}; ///< Container of all requests posted
Expand Down
37 changes: 18 additions & 19 deletions cpp/src/request_tag_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,27 @@ void RequestTagMulti::markCompleted(ucs_status_t status, RequestCallbackUserData
ucxx_trace_req("RequestTagMulti::markCompleted request: %p, tag: %lx", this, _tag);
std::lock_guard<std::mutex> lock(_completedRequestsMutex);

if (_finalStatus == UCS_OK && status != UCS_OK) _finalStatus = status;

if (++_completedRequests == _totalFrames) {
auto s = UCS_OK;

// Get the first non-UCS_OK status and set that as complete status
for (const auto& br : _bufferRequests) {
if (br->request) {
s = br->request->getStatus();
if (s != UCS_OK) break;
}
}
// Check the status of the current (and final) message as it may have completed before
// `_bufferRequests->request` was populated.
if (s == UCS_OK) s = status;
setStatus(_finalStatus);

setStatus(s);
ucxx_trace_req(
"RequestTagMulti::markCompleted request: %p, tag: %lx, completed: %lu/%lu, final status: %d "
"(%s)",
this,
_tag,
_completedRequests,
_totalFrames,
_finalStatus,
ucs_status_string(_finalStatus));
} else {
ucxx_trace_req("RequestTagMulti::markCompleted request: %p, tag: %lx, completed: %lu/%lu",
this,
_tag,
_completedRequests,
_totalFrames);
}

ucxx_trace_req("RequestTagMulti::markCompleted request: %p, tag: %lx, completed: %lu/%lu",
this,
_tag,
_completedRequests,
_totalFrames);
}

void RequestTagMulti::recvHeader()
Expand Down

0 comments on commit 13a663b

Please sign in to comment.