1 /* Copyright (c) 2010-2017. 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_wait, "Messages specific for this s4u example");
13 /* Main function of the Sender process */
17 double sleep_start_time; /* - start time */
18 double sleep_test_time; /* - test time */
20 simgrid::s4u::MailboxPtr mbox;
23 explicit sender(std::vector<std::string> args)
25 xbt_assert(args.size() == 7, "The sender function expects 6 arguments from the XML deployment file");
26 messages_count = std::stol(args[1]); /* - number of tasks */
27 msg_size = std::stod(args[2]); /* - computational cost */
28 double task_comm_size = std::stod(args[3]); /* - communication cost */
29 receivers_count = std::stol(args[4]); /* - number of receivers */
30 double sleep_start_time = std::stod(args[5]); /* - start time */
31 double sleep_test_time = std::stod(args[6]); /* - test time */
32 XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
36 for (int i = 0; i < messages_count; i++) {
40 std::string mbox_name = std::string("receiver-") + std::to_string(i % receivers_count);
41 mbox = simgrid::s4u::Mailbox::byName(mbox_name);
42 snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
43 snprintf(taskname,79, "Task_%d", i);
45 /* Create a communication */
46 simgrid::s4u::CommPtr comm = mbox->put_async((void*)mailbox, msg_size);
47 XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
50 for (int i = 0; i < receivers_count; i++) {
52 char* payload = xbt_strdup("finalize");
53 snprintf(mailbox, 79, "receiver-%d", i);
54 simgrid::s4u::CommPtr comm = mbox->put_async((void*)payload, 0);
55 XBT_INFO("Send to receiver-%d finalize", i);
58 XBT_INFO("Goodbye now!");
63 /* Receiver process expects 3 arguments: */
66 double sleep_test_time;
67 double sleep_start_time;
68 simgrid::s4u::MailboxPtr mbox;
71 explicit receiver(std::vector<std::string> args)
73 xbt_assert(args.size() == 4, "The relay_runner function does not accept any parameter from the XML deployment file");
74 id = std::stoi(args[1]); /* - unique id */
75 sleep_start_time = std::stod(args[2]); /* - start time */
76 sleep_test_time = std::stod(args[3]); /* - test time */
77 XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
78 std::string mbox_name = std::string("receiver-") + std::to_string(id);
79 mbox = simgrid::s4u::Mailbox::byName(mbox_name);
85 snprintf(mailbox,79, "receiver-%d", id);
87 char* received = static_cast<char*>(mbox->get());
88 XBT_INFO("Wait to receive a task");
89 XBT_INFO("I got a '%s'.", received);
90 if (std::strcmp(received, "finalize") == 0) { /* If it's a finalize message, we're done */
94 /* Otherwise receiving the message was all we were supposed to do */
100 int main(int argc, char *argv[])
102 simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
104 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
106 e->registerFunction<sender>("sender");
107 e->registerFunction<receiver>("receiver");
109 e->loadPlatform(argv[1]);
110 e->loadDeployment(argv[2]);