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"
11 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitall, "Messages specific for this msg example");
15 explicit sender(std::vector<std::string> args)
17 xbt_assert(args.size()== 4, "This function expects 5 parameters from the XML deployment file");
18 long number_of_tasks = xbt_str_parse_int(args[0].c_str(), "Invalid amount of tasks: %s");
19 double task_comp_size = xbt_str_parse_double(args[1].c_str(), "Invalid computational size: %s");
20 double task_comm_size = xbt_str_parse_double(args[2].c_str(), "Invalid communication size: %s");
21 long receivers_count = xbt_str_parse_int(args[3].c_str(), "Invalid amount of receivers: %s");
23 simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName("receiver_mailbox");
24 simgrid::s4u::CommPtr* comms = new simgrid::s4u::CommPtr[number_of_tasks + receivers_count] ;
26 for (int i = 0; i < number_of_tasks; i++) {
29 snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
30 snprintf(taskname,79, "Task_%d", i);
31 comms[i] = mbox->put_async((void*)taskname, 42);
32 XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
34 for (int i = 0; i < receivers_count; i++) {
36 snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
38 comms[i + number_of_tasks] = mbox->put_async((void*)"finalize", 42);
40 XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);
43 /* Here we are waiting for the completion of all communications */
44 for (int i = 0; i < number_of_tasks + receivers_count; i++)
51 XBT_INFO("Goodbye now!");
57 explicit receiver(std::vector<std::string> args)
59 xbt_assert(args.size() == 1,"This function expects 1 parameter from the XML deployment file");
60 int id = xbt_str_parse_int(args[0].c_str(), "Any process of this example must have a numerical name, not %s");
63 simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName("receiver_mailbox");
64 snprintf(mailbox,79, "receiver-%d", id);
66 simgrid::s4u::this_actor::sleep_for(10.0);
68 XBT_INFO("Wait to receive a task");
70 simgrid::s4u::CommPtr comm = mbox->get_async(&received);
72 if (strcmp(received, "finalize") == 0) {
77 XBT_INFO("Processing \"%s\"", received);
78 // MSG_task_execute(task);
79 XBT_INFO("\"%s\" done", recieved);
82 XBT_INFO("I'm done. See you!");
86 simgrid::s4u::Mailbox::byName("finalize")->put(nullptr, 1);
87 XBT_INFO("I'm done. See you!");
91 int main(int argc, char *argv[])
93 simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
95 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
96 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
98 e->registerFunction<sender>("sender");
99 e->registerFunction<receiver>("receiver");
101 e->loadDeployment(argv[2]);