+bool Request::match_common(MPI_Request req, MPI_Request sender, MPI_Request receiver)
+{
+ xbt_assert(sender, "Cannot match against null sender");
+ xbt_assert(receiver, "Cannot match against null receiver");
+ XBT_DEBUG("Trying to match %s of sender src %d against %d, tag %d against %d, id %d against %d",
+ (req == receiver ? "send" : "recv"), sender->src_, receiver->src_, sender->tag_, receiver->tag_,
+ sender->comm_->id(), receiver->comm_->id());
+
+ if ((receiver->comm_->id() == MPI_UNDEFINED || sender->comm_->id() == MPI_UNDEFINED ||
+ receiver->comm_->id() == sender->comm_->id()) &&
+ ((receiver->src_ == MPI_ANY_SOURCE && (receiver->comm_->group()->rank(sender->src_) != MPI_UNDEFINED)) ||
+ receiver->src_ == sender->src_) &&
+ ((receiver->tag_ == MPI_ANY_TAG && sender->tag_ >= 0) || receiver->tag_ == sender->tag_)) {
+ // we match, we can transfer some values
+ if (receiver->src_ == MPI_ANY_SOURCE)
+ receiver->real_src_ = sender->src_;
+ if (receiver->tag_ == MPI_ANY_TAG)
+ receiver->real_tag_ = sender->tag_;
+ if (receiver->real_size_ < sender->real_size_)
+ receiver->truncated_ = true;
+ if (sender->detached_)
+ receiver->detached_sender_ = sender; // tie the sender to the receiver, as it is detached and has to be freed in
+ // the receiver
+ if (req->cancelled_ == 0)
+ req->cancelled_ = -1; // mark as uncancelable
+ XBT_DEBUG("match succeeded");
+ return true;
+ }
+ return false;
+}
+
+void Request::init_buffer(int count){
+ void *old_buf = nullptr;
+// FIXME Handle the case of a partial shared malloc.
+ // This part handles the problem of non-contiguous memory (for the unserialization at the reception)
+ if ((((flags_ & MPI_REQ_RECV) != 0) && ((flags_ & MPI_REQ_ACCUMULATE) != 0)) || (old_type_->flags() & DT_FLAG_DERIVED)) {
+ // This part handles the problem of non-contiguous memory
+ old_buf = const_cast<void*>(buf_);
+ if (count==0){
+ buf_ = nullptr;
+ }else {
+ buf_ = xbt_malloc(count*old_type_->size());
+ if ((old_type_->flags() & DT_FLAG_DERIVED) && ((flags_ & MPI_REQ_SEND) != 0)) {
+ old_type_->serialize(old_buf, buf_, count);
+ }
+ }
+ }
+ old_buf_ = old_buf;
+}
+
+bool Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*)