1 /* Copyright (c) 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. */
8 #include <simgrid/s4u.hpp>
13 XBT_LOG_NEW_DEFAULT_CATEGORY(mwe, "Minimum Working Example");
15 static void receiver()
17 simgrid::s4u::MailboxPtr mymailbox = simgrid::s4u::Mailbox::byName("receiver_mailbox");
19 std::vector<simgrid::s4u::CommPtr> pending_comms;
21 XBT_INFO("Placing %d asynchronous recv requests", NUM_COMMS);
23 for (int i = 0; i < NUM_COMMS; i++) {
24 simgrid::s4u::CommPtr comm = mymailbox->get_async(&data);
25 pending_comms.push_back(comm);
28 for (int i = 0; i < NUM_COMMS; i++) {
29 XBT_INFO("Sleeping for 3 seconds (for the %dth time)...", i + 1);
30 simgrid::s4u::this_actor::sleep_for(3.0);
31 XBT_INFO("Calling wait_any() for %zu pending comms", pending_comms.size());
32 int changed_pos = simgrid::s4u::Comm::wait_any(&pending_comms);
33 XBT_INFO("Counting the number of completed comms...");
35 pending_comms.erase(pending_comms.begin() + changed_pos);
41 simgrid::s4u::MailboxPtr theirmailbox = simgrid::s4u::Mailbox::byName("receiver_mailbox");
43 void* data = (void*)"data";
45 for (int i = 0; i < NUM_COMMS; i++) {
46 XBT_INFO("Sending a message to the receiver");
47 theirmailbox->put(&data, 4);
48 XBT_INFO("Sleeping for 1000 seconds");
49 simgrid::s4u::this_actor::sleep_for(1000.0);
53 int main(int argc, char** argv)
56 simgrid::s4u::Engine* engine = new simgrid::s4u::Engine(&argc, argv);
58 xbt_assert(argc >= 2, "Usage: %s <xml platform file>", argv[0]);
60 engine->loadPlatform(argv[1]);
61 simgrid::s4u::Host** hosts = sg_host_list();
62 simgrid::s4u::Actor::createActor("Receiver", hosts[0], receiver);
63 simgrid::s4u::Actor::createActor("Sender", hosts[1], sender);