/** Creates and start a data transmission to that mailbox */
CommPtr put_async(void* data, uint64_t simulated_size_in_bytes);
+ smx_activity_t iprobe(int type, int (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data);
/** Blocking data transmission */
void put(void* payload, uint64_t simulated_size_in_bytes);
/** Blocking data transmission with timeout */
#include "simgrid/s4u/Host.hpp"
#include "src/kernel/activity/MailboxImpl.hpp"
#include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_network_private.hpp"
#include "src/surf/network_interface.hpp"
#include "src/surf/surf_interface.hpp"
else
return nullptr;
}
+
/** @brief Returns the mailbox of that name, newly created on need */
MailboxImpl* MailboxImpl::by_name_or_create(const std::string& name)
{
}
xbt_die("Comm %p not found in mailbox %s", comm.get(), this->get_cname());
}
+
+smx_activity_t MailboxImpl::iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data)
+{
+ XBT_DEBUG("iprobe from %p %p", this, &comm_queue_);
+
+ CommImplPtr this_comm;
+ int smx_type;
+ if (type == 1) {
+ this_comm = CommImplPtr(new CommImpl(SIMIX_COMM_SEND));
+ smx_type = SIMIX_COMM_RECEIVE;
+ } else {
+ this_comm = CommImplPtr(new CommImpl(SIMIX_COMM_RECEIVE));
+ smx_type = SIMIX_COMM_SEND;
+ }
+ smx_activity_t other_synchro = nullptr;
+ if (permanent_receiver_ != nullptr && not done_comm_queue_.empty()) {
+ XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
+ other_synchro = find_matching_comm((e_smx_comm_type_t)smx_type, match_fun, data, this_comm, /*done*/ true,
+ /*remove_matching*/ false);
+ }
+ if (not other_synchro) {
+ XBT_DEBUG("check if we have more luck in the normal mailbox");
+ other_synchro = find_matching_comm((e_smx_comm_type_t)smx_type, match_fun, data, this_comm, /*done*/ false,
+ /*remove_matching*/ false);
+ }
+
+ return other_synchro;
+}
+
+/**
+ * @brief Checks if there is a communication activity queued in comm_queue_ matching our needs
+ * @param type The type of communication we are looking for (comm_send, comm_recv)
+ * @param match_fun the function to apply
+ * @param this_user_data additional parameter to the match_fun
+ * @param my_synchro what to compare against
+ * @param remove_matching whether or not to clean the found object from the queue
+ * @return The communication activity if found, nullptr otherwise
+ */
+CommImplPtr MailboxImpl::find_matching_comm(e_smx_comm_type_t type, int (*match_fun)(void*, void*, CommImpl*),
+ void* this_user_data, CommImplPtr my_synchro, bool done,
+ bool remove_matching)
+{
+ void* other_user_data = nullptr;
+ boost::circular_buffer_space_optimized<smx_activity_t>* deque;
+ if (done)
+ deque = &done_comm_queue_;
+ else
+ deque = &comm_queue_;
+
+ for (auto it = deque->begin(); it != deque->end(); it++) {
+ CommImplPtr comm = boost::dynamic_pointer_cast<CommImpl>(std::move(*it));
+
+ if (comm->type == SIMIX_COMM_SEND) {
+ other_user_data = comm->src_data_;
+ } else if (comm->type == SIMIX_COMM_RECEIVE) {
+ other_user_data = comm->dst_data_;
+ }
+ if (comm->type == type && (match_fun == nullptr || match_fun(this_user_data, other_user_data, comm.get())) &&
+ (not comm->match_fun || comm->match_fun(other_user_data, this_user_data, my_synchro.get()))) {
+ XBT_DEBUG("Found a matching communication synchro %p", comm.get());
+ if (remove_matching)
+ deque->erase(it);
+#if SIMGRID_HAVE_MC
+ comm->mbox_cpy = comm->mbox;
+#endif
+ comm->mbox = nullptr;
+ return comm;
+ }
+ XBT_DEBUG("Sorry, communication synchro %p does not match our needs:"
+ " its type is %d but we are looking for a comm of type %d (or maybe the filtering didn't match)",
+ comm.get(), (int)comm->type, (int)type);
+ }
+ XBT_DEBUG("No matching communication synchro found");
+ return nullptr;
+}
}
}
}
void set_receiver(s4u::ActorPtr actor);
void push(activity::CommImplPtr comm);
void remove(smx_activity_t activity);
+ smx_activity_t iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data);
+ CommImplPtr find_matching_comm(e_smx_comm_type_t type, int (*match_fun)(void*, void*, CommImpl*),
+ void* this_user_data, CommImplPtr my_synchro, bool done, bool remove_matching);
private:
simgrid::s4u::Mailbox piface_;
#include "simgrid/s4u/Comm.hpp"
#include "simgrid/s4u/Mailbox.hpp"
#include "src/kernel/activity/MailboxImpl.hpp"
+
#include <simgrid/mailbox.h>
XBT_LOG_EXTERNAL_CATEGORY(s4u);
c->wait_for(timeout);
return res;
}
+
+smx_activity_t Mailbox::iprobe(int type, int (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data)
+{
+ return simix::simcall([this, type, match_fun, data] { return pimpl_->iprobe(type, match_fun, data); });
+}
} // namespace s4u
} // namespace simgrid
#include "src/kernel/activity/ConditionVariableImpl.hpp"
#include "src/kernel/activity/ExecImpl.hpp"
#include "src/kernel/activity/IoImpl.hpp"
+#include "src/kernel/activity/MailboxImpl.hpp"
#include "src/kernel/activity/MutexImpl.hpp"
#include "src/mc/mc_replay.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
#include "src/simix/smx_host_private.hpp"
#include "src/simix/smx_io_private.hpp"
-#include "src/simix/smx_network_private.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
{
xbt_assert(mbox, "No rendez-vous point defined for iprobe");
- return simgrid::simix::simcall(
- [mbox, type, match_fun, data] { return SIMIX_comm_iprobe(mbox, type, match_fun, data); });
+ return simgrid::simix::simcall([mbox, type, match_fun, data] { return mbox->iprobe(type, match_fun, data); });
}
/**
#include "simgrid/Exception.hpp"
#include "src/kernel/activity/MailboxImpl.hpp"
#include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_network_private.hpp"
#include "src/simix/smx_private.hpp"
#include "src/surf/cpu_interface.hpp"
#include "src/surf/network_interface.hpp"
-#include <boost/circular_buffer.hpp>
#include <boost/range/algorithm.hpp>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related synchronization");
static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall);
-/**
- * @brief Checks if there is a communication activity queued in a deque matching our needs
- * @param deque where to search into
- * @param type The type of communication we are looking for (comm_send, comm_recv)
- * @param match_fun the function to apply
- * @param this_user_data additional parameter to the match_fun
- * @param my_synchro what to compare against
- * @param remove_matching whether or not to clean the found object from the queue
- * @return The communication activity if found, nullptr otherwise
- */
-static simgrid::kernel::activity::CommImplPtr
-_find_matching_comm(boost::circular_buffer_space_optimized<smx_activity_t>* deque, e_smx_comm_type_t type,
- int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* this_user_data,
- simgrid::kernel::activity::CommImplPtr my_synchro, bool remove_matching)
-{
- void* other_user_data = nullptr;
-
- for(auto it = deque->begin(); it != deque->end(); it++){
- simgrid::kernel::activity::CommImplPtr comm =
- boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(std::move(*it));
-
- if (comm->type == SIMIX_COMM_SEND) {
- other_user_data = comm->src_data_;
- } else if (comm->type == SIMIX_COMM_RECEIVE) {
- other_user_data = comm->dst_data_;
- }
- if (comm->type == type && (match_fun == nullptr || match_fun(this_user_data, other_user_data, comm.get())) &&
- (not comm->match_fun || comm->match_fun(other_user_data, this_user_data, my_synchro.get()))) {
- XBT_DEBUG("Found a matching communication synchro %p", comm.get());
- if (remove_matching)
- deque->erase(it);
-#if SIMGRID_HAVE_MC
- comm->mbox_cpy = comm->mbox;
-#endif
- comm->mbox = nullptr;
- return comm;
- }
- XBT_DEBUG("Sorry, communication synchro %p does not match our needs:"
- " its type is %d but we are looking for a comm of type %d (or maybe the filtering didn't match)",
- comm.get(), (int)comm->type, (int)type);
- }
- XBT_DEBUG("No matching communication synchro found");
- return nullptr;
-}
-
/******************************************************************************/
/* Communication synchros */
/******************************************************************************/
SIMCALL_SET_MC_VALUE(simcall, 0);
simcall_HANDLER_comm_wait(simcall, comm, timeout);
}
+
XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(
smx_simcall_t /*simcall*/, smx_actor_t src_proc, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
size_t src_buff_size, int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
* ourself so that the other side also gets a chance of choosing if it wants to match with us.
*
* If it is not found then push our communication into the rendez-vous point */
- simgrid::kernel::activity::CommImplPtr other_comm =
- _find_matching_comm(&mbox->comm_queue_, SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*remove_matching*/ true);
+ simgrid::kernel::activity::CommImplPtr other_comm = mbox->find_matching_comm(
+ SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*done*/ false, /*remove_matching*/ true);
if (not other_comm) {
other_comm = std::move(this_comm);
XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
//find a match in the list of already received comms
- other_comm = _find_matching_comm(&mbox->done_comm_queue_, SIMIX_COMM_SEND, match_fun, data, this_synchro,
- /*remove_matching*/ true);
+ other_comm = mbox->find_matching_comm(SIMIX_COMM_SEND, match_fun, data, this_synchro, /*done*/ true,
+ /*remove_matching*/ true);
//if not found, assume the receiver came first, register it to the mailbox in the classical way
if (not other_comm) {
XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request into list");
* ourself so that the other side also gets a chance of choosing if it wants to match with us.
*
* If it is not found then push our communication into the rendez-vous point */
- other_comm = _find_matching_comm(&mbox->comm_queue_, SIMIX_COMM_SEND, match_fun, data, this_synchro,
- /*remove_matching*/ true);
+ other_comm = mbox->find_matching_comm(SIMIX_COMM_SEND, match_fun, data, this_synchro, /*done*/ false,
+ /*remove_matching*/ true);
if (other_comm == nullptr) {
XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->comm_queue_.size());
return other_comm;
}
-smx_activity_t SIMIX_comm_iprobe(smx_mailbox_t mbox, int type, simix_match_func_t match_fun, void* data)
-{
- XBT_DEBUG("iprobe from %p %p", mbox, &mbox->comm_queue_);
- simgrid::kernel::activity::CommImplPtr this_comm;
- int smx_type;
- if(type == 1){
- this_comm = simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl(SIMIX_COMM_SEND));
- smx_type = SIMIX_COMM_RECEIVE;
- } else{
- this_comm = simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl(SIMIX_COMM_RECEIVE));
- smx_type = SIMIX_COMM_SEND;
- }
- smx_activity_t other_synchro=nullptr;
- if (mbox->permanent_receiver_ != nullptr && not mbox->done_comm_queue_.empty()) {
- XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
- other_synchro = _find_matching_comm(&mbox->done_comm_queue_, (e_smx_comm_type_t)smx_type, match_fun, data,
- this_comm, /*remove_matching*/ false);
- }
- if (not other_synchro) {
- XBT_DEBUG("check if we have more luck in the normal mailbox");
- other_synchro = _find_matching_comm(&mbox->comm_queue_, (e_smx_comm_type_t)smx_type, match_fun, data, this_comm,
- /*remove_matching*/ false);
- }
-
- return other_synchro;
-}
-
void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_activity_t synchro, double timeout)
{
/* Associate this simcall to the wait synchro */
}
}
-
void SIMIX_comm_copy_buffer_callback(smx_activity_t synchro, void* buff, size_t buff_size)
{
simgrid::kernel::activity::CommImplPtr comm =
+++ /dev/null
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef SIMIX_NETWORK_PRIVATE_HPP
-#define SIMIX_NETWORK_PRIVATE_HPP
-
-#include "simgrid/forward.h"
-#include "src/simix/popping_private.hpp"
-
-XBT_PRIVATE smx_activity_t SIMIX_comm_iprobe(smx_mailbox_t mbox, int type, simix_match_func_t match_fun, void* data);
-
-#endif
smpi_trace_call_location_t* call_location();
void set_privatized_region(smpi_privatization_region_t region);
smpi_privatization_region_t privatized_region();
- smx_mailbox_t mailbox();
- smx_mailbox_t mailbox_small();
+ s4u::MailboxPtr mailbox() { return mailbox_; }
+ s4u::MailboxPtr mailbox_small() { return mailbox_small_; }
xbt_mutex_t mailboxes_mutex();
#if HAVE_PAPI
int papi_event_set();
return comm_world_ == nullptr ? MPI_COMM_NULL : *comm_world_;
}
-smx_mailbox_t ActorExt::mailbox()
-{
- return mailbox_->get_impl();
-}
-
-smx_mailbox_t ActorExt::mailbox_small()
-{
- return mailbox_small_->get_impl();
-}
-
xbt_mutex_t ActorExt::mailboxes_mutex()
{
return mailboxes_mutex_;
void Request::start()
{
- smx_mailbox_t mailbox;
+ s4u::MailboxPtr mailbox;
xbt_assert(action_ == nullptr, "Cannot (re-)start unfinished communication");
flags_ &= ~MPI_REQ_PREPARED;
//We have to check both mailboxes (because SSEND messages are sent to the large mbox).
//begin with the more appropriate one : the small one.
mailbox = process->mailbox_small();
- XBT_DEBUG("Is there a corresponding send already posted in the small mailbox %p (in case of SSEND)?", mailbox);
- smx_activity_t action = simcall_comm_iprobe(mailbox, 0, &match_recv, static_cast<void*>(this));
+ XBT_DEBUG("Is there a corresponding send already posted in the small mailbox %s (in case of SSEND)?",
+ mailbox->get_cname());
+ smx_activity_t action = mailbox->iprobe(0, &match_recv, static_cast<void*>(this));
if (action == nullptr) {
mailbox = process->mailbox();
- XBT_DEBUG("No, nothing in the small mailbox test the other one : %p", mailbox);
- action = simcall_comm_iprobe(mailbox, 0, &match_recv, static_cast<void*>(this));
+ XBT_DEBUG("No, nothing in the small mailbox test the other one : %s", mailbox->get_cname());
+ action = mailbox->iprobe(0, &match_recv, static_cast<void*>(this));
if (action == nullptr) {
- XBT_DEBUG("Still nothing, switch back to the small mailbox : %p", mailbox);
+ XBT_DEBUG("Still nothing, switch back to the small mailbox : %s", mailbox->get_cname());
mailbox = process->mailbox_small();
}
} else {
} else {
mailbox = process->mailbox_small();
XBT_DEBUG("Is there a corresponding send already posted the small mailbox?");
- smx_activity_t action = simcall_comm_iprobe(mailbox, 0, &match_recv, static_cast<void*>(this));
+ smx_activity_t action = mailbox->iprobe(0, &match_recv, static_cast<void*>(this));
if (action == nullptr) {
XBT_DEBUG("No, nothing in the permanent receive mailbox");
// we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
real_size_=size_;
action_ = simcall_comm_irecv(
- process->get_actor()->get_impl(), mailbox, buf_, &real_size_, &match_recv,
+ process->get_actor()->get_impl(), mailbox->get_impl(), buf_, &real_size_, &match_recv,
process->replaying() ? &smpi_comm_null_copy_buffer_callback : smpi_comm_copy_data_callback, this, -1.0);
XBT_DEBUG("recv simcall posted");
mailbox = process->mailbox();
} else if (((flags_ & MPI_REQ_RMA) != 0) || static_cast<int>(size_) < async_small_thresh) { // eager mode
mailbox = process->mailbox();
- XBT_DEBUG("Is there a corresponding recv already posted in the large mailbox %p?", mailbox);
- smx_activity_t action = simcall_comm_iprobe(mailbox, 1, &match_send, static_cast<void*>(this));
+ XBT_DEBUG("Is there a corresponding recv already posted in the large mailbox %s?", mailbox->get_cname());
+ smx_activity_t action = mailbox->iprobe(1, &match_send, static_cast<void*>(this));
if (action == nullptr) {
if ((flags_ & MPI_REQ_SSEND) == 0) {
mailbox = process->mailbox_small();
- XBT_DEBUG("No, nothing in the large mailbox, message is to be sent on the small one %p", mailbox);
+ XBT_DEBUG("No, nothing in the large mailbox, message is to be sent on the small one %s",
+ mailbox->get_cname());
} else {
mailbox = process->mailbox_small();
- XBT_DEBUG("SSEND : Is there a corresponding recv already posted in the small mailbox %p?", mailbox);
- action = simcall_comm_iprobe(mailbox, 1, &match_send, static_cast<void*>(this));
- if (action == nullptr) {
+ XBT_DEBUG("SSEND : Is there a corresponding recv already posted in the small mailbox %s?",
+ mailbox->get_cname());
+ action = mailbox->iprobe(1, &match_send, static_cast<void*>(this));
+ if (action != nullptr) {
XBT_DEBUG("No, we are first, send to large mailbox");
mailbox = process->mailbox();
}
}
} else {
mailbox = process->mailbox();
- XBT_DEBUG("Send request %p is in the large mailbox %p (buf: %p)",mailbox, this,buf_);
+ XBT_DEBUG("Send request %p is in the large mailbox %s (buf: %p)", this, mailbox->get_cname(), buf_);
}
// we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
real_size_=size_;
action_ = simcall_comm_isend(
- simgrid::s4u::Actor::by_pid(src_)->get_impl(), mailbox, size_, -1.0, buf, real_size_, &match_send,
+ simgrid::s4u::Actor::by_pid(src_)->get_impl(), mailbox->get_impl(), size_, -1.0, buf, real_size_, &match_send,
&xbt_free_f, // how to free the userdata if a detached send fails
not process->replaying() ? smpi_comm_copy_data_callback : &smpi_comm_null_copy_buffer_callback, this,
// detach if msg size < eager/rdv switch limit
->wait();
}
// behave like a receive, but don't do it
- smx_mailbox_t mailbox;
+ s4u::MailboxPtr mailbox;
request->print_request("New iprobe");
// We have to test both mailboxes as we don't know if we will receive one one or another
if (simgrid::config::get_value<int>("smpi/async-small-thresh") > 0) {
mailbox = smpi_process()->mailbox_small();
XBT_DEBUG("Trying to probe the perm recv mailbox");
- request->action_ = simcall_comm_iprobe(mailbox, 0, &match_recv, static_cast<void*>(request));
+ request->action_ = mailbox->iprobe(0, &match_recv, static_cast<void*>(request));
}
if (request->action_ == nullptr){
mailbox = smpi_process()->mailbox();
XBT_DEBUG("trying to probe the other mailbox");
- request->action_ = simcall_comm_iprobe(mailbox, 0, &match_recv, static_cast<void*>(request));
+ request->action_ = mailbox->iprobe(0, &match_recv, static_cast<void*>(request));
}
if (request->action_ != nullptr){
src/simix/popping_accessors.hpp
src/simix/smx_host_private.hpp
src/simix/smx_io_private.hpp
- src/simix/smx_network_private.hpp
src/simix/smx_private.hpp
src/simix/smx_synchro_private.hpp
src/smpi/colls/coll_tuned_topo.hpp