+ // See comment about the mutex in finish_comms() above
+ const std::scoped_lock lock(*mut_);
+ // Finish own requests
+ // Let's see if we're either the destination or the sender of this request
+ // because we only wait for requests that we are responsible for.
+ // Also use the process id here since the request itself returns from src()
+ // and dst() the process id, NOT the rank (which only exists in the context of a communicator).
+ aid_t proc_id = comm_->group()->actor(rank);
+ auto it = std::stable_partition(begin(requests_), end(requests_), [proc_id](const MPI_Request& req) {
+ return (req == MPI_REQUEST_NULL || (req->src() != proc_id && req->dst() != proc_id));
+ });
+ std::vector<MPI_Request> myreqqs(it, end(requests_));
+ requests_.erase(it, end(requests_));
+ int size = static_cast<int>(myreqqs.size());