include examples/c/synchro-semaphore/synchro-semaphore.tesh
include examples/cpp/activityset-testany/s4u-activityset-testany.cpp
include examples/cpp/activityset-testany/s4u-activityset-testany.tesh
+include examples/cpp/activityset-waitall/s4u-activityset-waitall.cpp
+include examples/cpp/activityset-waitall/s4u-activityset-waitall.tesh
include examples/cpp/activityset-waitany/s4u-activityset-waitany.cpp
include examples/cpp/activityset-waitany/s4u-activityset-waitany.tesh
include examples/cpp/actor-create/s4u-actor-create.cpp
include examples/cpp/comm-throttling/s4u-comm-throttling.tesh
include examples/cpp/comm-wait/s4u-comm-wait.cpp
include examples/cpp/comm-wait/s4u-comm-wait.tesh
-include examples/cpp/comm-waitall/s4u-comm-waitall.cpp
-include examples/cpp/comm-waitall/s4u-comm-waitall.tesh
include examples/cpp/comm-waituntil/s4u-comm-waituntil.cpp
include examples/cpp/comm-waituntil/s4u-comm-waituntil.tesh
include examples/cpp/dag-comm/s4u-dag-comm.cpp
# Deal with each example
-foreach (example activityset-testany activityset-waitany
+foreach (example activityset-testany activityset-waitany activityset-waitall
actor-create actor-daemon actor-exiting actor-join actor-kill
actor-lifetime actor-migrate actor-suspend actor-yield actor-stacksize
app-bittorrent app-chainsend app-token-ring
battery-degradation battery-simple battery-energy
- comm-pingpong comm-ready comm-suspend comm-wait comm-waitall comm-waituntil
+ comm-pingpong comm-ready comm-suspend comm-wait comm-waituntil
comm-dependent comm-host2host comm-failure comm-throttling
cloud-capping cloud-migration cloud-simple
dag-comm dag-from-json-simple dag-from-dax-simple dag-from-dax dag-from-dot-simple dag-from-dot dag-failure dag-io dag-scheduling dag-simple dag-tuto
--- /dev/null
+/* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "simgrid/s4u.hpp"
+#include <cstdlib>
+#include <iostream>
+#include <string>
+namespace sg4 = simgrid::s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_activity_waittany, "Messages specific for this s4u example");
+
+static void bob()
+{
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("mbox");
+ const sg4::Disk* disk = sg4::Host::current()->get_disks().front();
+ std::string* payload;
+
+ XBT_INFO("Create my asynchronous activities");
+ auto exec = sg4::this_actor::exec_async(5e9);
+ auto comm = mbox->get_async(&payload);
+ auto io = disk->read_async(3e8);
+
+ sg4::ActivitySet pending_activities({boost::dynamic_pointer_cast<sg4::Activity>(exec),
+ boost::dynamic_pointer_cast<sg4::Activity>(comm),
+ boost::dynamic_pointer_cast<sg4::Activity>(io)});
+
+ XBT_INFO("Wait for asynchrounous activities to complete, all in one shot.");
+ pending_activities.wait_all();
+
+ XBT_INFO("All activities are completed.");
+ delete payload;
+}
+
+static void alice()
+{
+ auto* payload = new std::string("Message");
+ XBT_INFO("Send '%s'", payload->c_str());
+ sg4::Mailbox::by_name("mbox")->put(payload, 6e8);
+}
+
+int main(int argc, char* argv[])
+{
+ sg4::Engine e(&argc, argv);
+
+ e.load_platform(argv[1]);
+
+ sg4::Actor::create("bob", e.host_by_name("bob"), bob);
+ sg4::Actor::create("alice", e.host_by_name("alice"), alice);
+
+ e.run();
+
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-activityset-waitall ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n"
+> [0.000000] [alice] Send 'Message'
+> [0.000000] [ bob] Create my asynchronous activities
+> [0.000000] [ bob] Wait for asynchrounous activities to complete, all in one shot.
+> [5.197828] [ bob] All activities are completed.
+++ /dev/null
-/* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-/* This example shows how to block on the completion of a set of communications.
- *
- * As for the other asynchronous examples, the sender initiate all the messages it wants to send and
- * pack the resulting simgrid::s4u::CommPtr objects in a vector. All messages thus occur concurrently.
- *
- * The sender then blocks until all ongoing communication terminate, using simgrid::s4u::Comm::wait_all()
- *
- */
-
-#include "simgrid/s4u.hpp"
-#include <cstdlib>
-#include <iostream>
-#include <string>
-namespace sg4 = simgrid::s4u;
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_waitall, "Messages specific for this s4u example");
-
-static void sender(unsigned int messages_count, unsigned int receivers_count, long msg_size)
-{
- if (messages_count == 0 || receivers_count == 0) {
- XBT_WARN("Sender has nothing to do. Bail out!");
- return;
- }
- // sphinx-doc: init-begin (this line helps the doc to build; ignore it)
- /* Vector in which we store all ongoing communications */
- std::vector<sg4::CommPtr> pending_comms;
-
- /* Make a vector of the mailboxes to use */
- std::vector<sg4::Mailbox*> mboxes;
- for (unsigned int i = 0; i < receivers_count; i++)
- mboxes.push_back(sg4::Mailbox::by_name("receiver-" + std::to_string(i)));
- // sphinx-doc: init-end
-
- /* Start dispatching all messages to receivers, in a round robin fashion */
- for (unsigned int i = 0; i < messages_count; i++) {
- std::string msg_content = "Message " + std::to_string(i);
- // Copy the data we send: the 'msg_content' variable is not a stable storage location.
- // It will be destroyed when this actor leaves the loop, ie before the receiver gets it
- auto* 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 */
- sg4::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
- pending_comms.push_back(comm);
- }
-
- /* Start sending messages to let the workers know that they should stop */ // sphinx-doc: put-begin
- for (unsigned int i = 0; i < receivers_count; i++) {
- XBT_INFO("Send 'finalize' to 'receiver-%u'", i);
- sg4::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
- pending_comms.push_back(comm);
- }
- XBT_INFO("Done dispatching all messages");
-
- /* Now that all message exchanges were initiated, wait for their completion in one single call */
- sg4::Comm::wait_all(pending_comms);
- // sphinx-doc: put-end
-
- XBT_INFO("Goodbye now!");
-}
-
-/* Receiver actor expects 1 argument: its ID */
-static void receiver(int id)
-{
- sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver-" + std::to_string(id));
- XBT_INFO("Wait for my first message");
- for (bool cont = true; cont;) {
- auto received = mbox->get_unique<std::string>();
- XBT_INFO("I got a '%s'.", received->c_str());
- cont = (*received != "finalize"); // If it's a finalize message, we're done
- // Receiving the message was all we were supposed to do
- }
-}
-
-int main(int argc, char* argv[])
-{
- sg4::Engine e(&argc, argv);
-
- e.load_platform(argv[1]);
-
- sg4::Actor::create("sender", e.host_by_name("Tremblay"), sender, 5, 2, 1e6);
- sg4::Actor::create("receiver", e.host_by_name("Ruby"), receiver, 0);
- sg4::Actor::create("receiver", e.host_by_name("Perl"), receiver, 1);
-
- e.run();
-
- return 0;
-}
+++ /dev/null
-#!/usr/bin/env tesh
-
-$ ${bindir:=.}/s4u-comm-waitall ${platfdir}/small_platform_fatpipe.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
-> [ 0.000000] (2:receiver@Ruby) Wait for my first message
-> [ 0.000000] (3:receiver@Perl) Wait for my first message
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 0' to 'receiver-0'
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 1' to 'receiver-1'
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 2' to 'receiver-0'
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 3' to 'receiver-1'
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 4' to 'receiver-0'
-> [ 0.000000] (1:sender@Tremblay) Send 'finalize' to 'receiver-0'
-> [ 0.000000] (1:sender@Tremblay) Send 'finalize' to 'receiver-1'
-> [ 0.000000] (1:sender@Tremblay) Done dispatching all messages
-> [ 0.004022] (2:receiver@Ruby) I got a 'Message 0'.
-> [ 0.004022] (3:receiver@Perl) I got a 'Message 1'.
-> [ 0.008043] (2:receiver@Ruby) I got a 'Message 2'.
-> [ 0.008043] (3:receiver@Perl) I got a 'Message 3'.
-> [ 0.009995] (3:receiver@Perl) I got a 'finalize'.
-> [ 0.012065] (2:receiver@Ruby) I got a 'Message 4'.
-> [ 0.014016] (2:receiver@Ruby) I got a 'finalize'.
-> [ 0.014016] (1:sender@Tremblay) Goodbye now!
*
* On timeout, an exception is raised, and the completed activities remain in the set. Use test_any() to retrieve
* them.
+ *
+ * When no timeout occures, the set is emptied.
*/
void wait_all_for(double timeout);
- /** Wait for the completion of all activities in the set */
+ /** Wait for the completion of all activities in the set. The set is emptied afterward. */
void wait_all() { wait_all_for(-1); }
/** Returns the first terminated activity if any, or ActivityPtr(nullptr) if no activity is terminated */
ActivityPtr test_any();
for (const auto& act : activities_)
act->wait_until(deadline);
}
+ activities_.clear();
}
ActivityPtr ActivitySet::test_any()