1 /* Copyright (c) 2010-2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u.hpp"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitany, "Messages specific for this msg example");
15 long number_of_tasks = 0; /* - Number of tasks */
16 long receivers_count = 0; /* - Number of workers */
20 explicit sender(std::vector<std::string> args)
22 xbt_assert(args.size()== 5, "This function expects 5 parameters from the XML deployment file");
23 number_of_tasks = std::stol(args[0]);
24 double task_comp_size = std::stod(args[1]);
25 double task_comm_size = std::stod(args[2]);
26 receivers_count = std::stol(args[3]);
27 diff_com = std::stoi(args[4]);
32 std::vector<simgrid::s4u::CommPtr> comms;
33 simgrid::s4u::CommPtr comm;
34 simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName("receiver_mailbox");
35 /* First pack the communications in the dynar */
36 for (int i = 0; i < number_of_tasks; i++) {
37 double coef = (diff_com == 0) ? 1 : (i + 1);
40 snprintf(mailbox,79, "receiver-%ld", (i % receivers_count));
41 snprintf(taskname,79, "Task_%d", i);
42 comm = mbox->put_async((void*)taskname, 42.0);
43 comms.push_back(comm);
46 /* Here we are waiting for the completion of all communications */
47 while (!comms.empty()) {
55 /* Here we are waiting for the completion of all tasks */
56 for (int i = 0; i < receivers_count; i++) {
57 void* received = nullptr;
58 simgrid::s4u::CommPtr comm = mbox->get_async(&received);
62 XBT_INFO("Goodbye now!");
70 explicit receiver(std::vector<std::string> args)
72 xbt_assert(args.size() == 2, "This function expects 2 parameters from the XML deployment file");
73 id = std::stoi(args[0]);
74 task_amount = std::stoi(args[1]);
79 std::vector<simgrid::s4u::CommPtr> comms;
80 simgrid::s4u::CommPtr comm;
81 simgrid::s4u::MailboxPtr mbox;
83 simgrid::s4u::this_actor::sleep_for(10.0);
84 for (int i = 0; i < task_amount; i++) {
85 XBT_INFO("Wait to receive task %d", i);
87 comm = mbox->get_async(&received);
88 comms.push_back(comm);
91 /* Here we are waiting for the receiving of all communications */
92 while (!comms.empty()) {
93 // returns the rank of the comm that just ended. Remove it.
100 /* Here we tell to sender that all tasks are done */
101 simgrid::s4u::Mailbox::byName("finalize")->put(nullptr, 1);
102 XBT_INFO("I'm done. See you!");
106 int main(int argc, char *argv[])
108 simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
110 e->registerFunction<sender>("sender");
111 e->registerFunction<receiver>("receiver");
113 e->loadDeployment(argv[2]);