- explicit sender(std::vector<std::string> args)
-{
- xbt_assert(args.size() == 4, "This function expects 4 parameters from the XML deployment file but got %zu",
- args.size());
- messages_count = std::stol(args[1]);
- msg_size = std::stod(args[2]);
- receivers_count = std::stol(args[3]);
-
-}
-void operator()()
-{
- std::vector<simgrid::s4u::CommPtr>* pending_comms = new std::vector<simgrid::s4u::CommPtr>();
+ explicit Sender(std::vector<std::string> args)
+ {
+ xbt_assert(args.size() == 4, "Expecting 3 parameters from the XML deployment file but got %zu", args.size());
+ messages_count = std::stol(args[1]);
+ msg_size = std::stod(args[2]);
+ receivers_count = std::stol(args[3]);
+ }
+ void operator()()
+ {
+ // sphinx-doc: init-begin (this line helps the doc to build; ignore it)
+ /* Vector in which we store all ongoing communications */
+ std::vector<simgrid::s4u::CommPtr> pending_comms;
+
+ /* Make a vector of the mailboxes to use */
+ std::vector<simgrid::s4u::Mailbox*> mboxes;
+ for (int i = 0; i < receivers_count; i++)
+ mboxes.push_back(simgrid::s4u::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
+ // sphinx-doc: init-end
+
+ /* Start dispatching all messages to receivers, in a round robin fashion */
+ for (int i = 0; i < messages_count; i++) {
+ std::string msg_content = std::string("Message ") + std::to_string(i);
+ // Copy the data we send: 'msg_content' is not a stable storage location.
+ // It will be destroyed when this actor leaves the loop, ie before the receiver gets it
+ std::string* payload = new std::string(msg_content);
+
+ XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mboxes[i % receivers_count]->get_cname());
+
+ /* Create a communication representing the ongoing communication, and store it in pending_comms */
+ simgrid::s4u::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
+ pending_comms.push_back(comm);
+ }