* under the terms of the license (GNU LGPL) which comes with this package. */
#include <simgrid/s4u.hpp>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_dependent, "Messages specific for this s4u example");
-static void sender(simgrid::s4u::Mailbox* mailbox)
+static void sender(sg4::Mailbox* mailbox)
{
- auto* computation_amount = new double(simgrid::s4u::this_actor::get_host()->get_speed());
- simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * (*computation_amount));
- simgrid::s4u::CommPtr comm = mailbox->put_init(computation_amount, 7e6);
+ auto* computation_amount = new double(sg4::this_actor::get_host()->get_speed());
+ sg4::ExecPtr exec = sg4::this_actor::exec_init(2 * (*computation_amount));
+ sg4::CommPtr comm = mailbox->put_init(computation_amount, 7e6);
exec->set_name("exec on sender")->add_successor(comm)->start();
comm->set_name("comm to receiver")->vetoable_start();
comm->wait();
}
-static void receiver(simgrid::s4u::Mailbox* mailbox)
+static void receiver(sg4::Mailbox* mailbox)
{
double* received = nullptr;
- double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
- simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
- simgrid::s4u::CommPtr comm = mailbox->get_init()->set_dst_data((void**)&received, sizeof(double));
+ double computation_amount = sg4::this_actor::get_host()->get_speed();
+ sg4::ExecPtr exec = sg4::this_actor::exec_init(2 * computation_amount);
+ sg4::CommPtr comm = mailbox->get_init()->set_dst_data((void**)&received, sizeof(double));
comm->set_name("comm from sender")->add_successor(exec)->start();
exec->set_name("exec on receiver")->vetoable_start();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("Mailbox");
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("Mailbox");
- simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Tremblay"), sender, mbox);
- simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver, mbox);
+ sg4::Actor::create("sender", sg4::Host::by_name("Tremblay"), sender, mbox);
+ sg4::Actor::create("receiver", sg4::Host::by_name("Jupiter"), receiver, mbox);
e.run();
* under the terms of the license (GNU LGPL) which comes with this package. */
#include <simgrid/s4u.hpp>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_pingpong, "Messages specific for this s4u example");
-static void pinger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
+static void pinger(sg4::Mailbox* mailbox_in, sg4::Mailbox* mailbox_out)
{
XBT_INFO("Ping from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
/* - Do the ping with a 1-Byte payload (latency bound) ... */
- auto* payload = new double(simgrid::s4u::Engine::get_clock());
+ auto* payload = new double(sg4::Engine::get_clock());
mailbox_out->put(payload, 1);
/* - ... then wait for the (large) pong */
auto sender_time = mailbox_in->get_unique<double>();
- double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
+ double communication_time = sg4::Engine::get_clock() - *sender_time;
XBT_INFO("Payload received : large communication (bandwidth bound)");
XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
}
-static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
+static void ponger(sg4::Mailbox* mailbox_in, sg4::Mailbox* mailbox_out)
{
XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
/* - Receive the (small) ping first ....*/
auto sender_time = mailbox_in->get_unique<double>();
- double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
+ double communication_time = sg4::Engine::get_clock() - *sender_time;
XBT_INFO("Payload received : small communication (latency bound)");
XBT_INFO("Ping time (latency bound) %f", communication_time);
/* - ... Then send a 1GB pong back (bandwidth bound) */
- auto* payload = new double(simgrid::s4u::Engine::get_clock());
+ auto* payload = new double(sg4::Engine::get_clock());
XBT_INFO("payload = %.3f", *payload);
mailbox_out->put(payload, 1e9);
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Mailbox* mb1 = simgrid::s4u::Mailbox::by_name("Mailbox 1");
- simgrid::s4u::Mailbox* mb2 = simgrid::s4u::Mailbox::by_name("Mailbox 2");
+ sg4::Mailbox* mb1 = sg4::Mailbox::by_name("Mailbox 1");
+ sg4::Mailbox* mb2 = sg4::Mailbox::by_name("Mailbox 2");
- simgrid::s4u::Actor::create("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, mb1, mb2);
- simgrid::s4u::Actor::create("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, mb2, mb1);
+ sg4::Actor::create("pinger", sg4::Host::by_name("Tremblay"), pinger, mb1, mb2);
+ sg4::Actor::create("ponger", sg4::Host::by_name("Jupiter"), ponger, mb2, mb1);
e.run();
#include <cstdlib>
#include <iostream>
#include <string>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_ready, "Messages specific for this s4u example");
/* Set myself as the persistent receiver of my mailbox so that messages start flowing to me as soon as they are put
* into it */
- simgrid::s4u::Mailbox* my_mbox = simgrid::s4u::Mailbox::by_name(std::string("peer-") + std::to_string(my_id));
- my_mbox->set_receiver(simgrid::s4u::Actor::self());
+ sg4::Mailbox* my_mbox = sg4::Mailbox::by_name(std::string("peer-") + std::to_string(my_id));
+ my_mbox->set_receiver(sg4::Actor::self());
- std::vector<simgrid::s4u::CommPtr> pending_comms;
+ std::vector<sg4::CommPtr> pending_comms;
/* Start dispatching all messages to peers others that myself */
for (int i = 0; i < messages_count; i++) {
for (int peer_id = 0; peer_id < peers_count; peer_id++) {
if (peer_id != my_id) {
std::string mboxName = std::string("peer-") + std::to_string(peer_id);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(mboxName);
std::string msgName =
std::string("Message ") + std::to_string(i) + std::string(" from peer ") + std::to_string(my_id);
auto* payload = new std::string(msgName); // copy the data we send:
for (int peer_id = 0; peer_id < peers_count; peer_id++) {
if (peer_id != my_id) {
std::string mboxName = std::string("peer-") + std::to_string(peer_id);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(mboxName);
auto* payload = new std::string("finalize"); // Make a copy of the data we will send
pending_comms.push_back(mbox->put_async(payload, msg_size));
XBT_INFO("Send 'finalize' to 'peer-%d'", peer_id);
long pending_finalize_messages = peers_count - 1;
while (pending_finalize_messages > 0) {
if (my_mbox->ready()) {
- double start = simgrid::s4u::Engine::get_clock();
+ double start = sg4::Engine::get_clock();
auto received = my_mbox->get_unique<std::string>();
- double waiting_time = simgrid::s4u::Engine::get_clock() - start;
+ double waiting_time = sg4::Engine::get_clock() - start;
xbt_assert(
waiting_time == 0,
"Expecting the waiting time to be 0 because the communication was supposedly ready, but got %f instead",
}
} else {
XBT_INFO("Nothing ready to consume yet, I better sleep for a while");
- simgrid::s4u::this_actor::sleep_for(.01);
+ sg4::this_actor::sleep_for(.01);
}
}
XBT_INFO("I'm done, just waiting for my peers to receive the messages before exiting");
- simgrid::s4u::Comm::wait_all(&pending_comms);
+ sg4::Comm::wait_all(&pending_comms);
XBT_INFO("Goodbye now!");
}
{
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.register_function("peer", &peer);
e.load_platform(argv[1]);
#include <cstdlib>
#include <iostream>
#include <string>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_wait, "Messages specific for this s4u example");
{
xbt_assert(argc == 1, "Expecting no parameter from the XML deployment file but got %d", argc - 1);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
// 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 the data
auto* payload = new std::string("Sent message");
/* Create a communication representing the ongoing communication and then */
- simgrid::s4u::CommPtr comm = mbox->put_init(payload, 13194230);
+ sg4::CommPtr comm = mbox->put_init(payload, 13194230);
XBT_INFO("Suspend the communication before it starts (remaining: %.0f bytes) and wait a second.",
comm->get_remaining());
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
XBT_INFO("Now, start the communication (remaining: %.0f bytes) and wait another second.", comm->get_remaining());
comm->start();
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
XBT_INFO("There is still %.0f bytes to transfer in this communication. Suspend it for one second.",
comm->get_remaining());
static void receiver(int, char**)
{
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
XBT_INFO("Wait for the message.");
auto received = mbox->get_unique<std::string>();
{
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.register_function("sender", &sender);
e.register_function("receiver", &receiver);
#include <cstdlib>
#include <iostream>
#include <string>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_wait, "Messages specific for this s4u example");
double sleep_start_time = 5.0;
double sleep_test_time = 0;
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
- simgrid::s4u::this_actor::sleep_for(sleep_start_time);
+ sg4::this_actor::sleep_for(sleep_start_time);
for (int i = 0; i < messages_count; i++) {
std::string msg_content = std::string("Message ") + std::to_string(i);
auto* payload = new std::string(msg_content);
/* Create a communication representing the ongoing communication and then */
- simgrid::s4u::CommPtr comm = mbox->put_async(payload, msg_size);
+ sg4::CommPtr comm = mbox->put_async(payload, msg_size);
XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mbox->get_cname());
if (sleep_test_time > 0) { /* - "test_time" is set to 0, wait */
while (not comm->test()) { /* - Call test() every "sleep_test_time" otherwise */
- simgrid::s4u::this_actor::sleep_for(sleep_test_time);
+ sg4::this_actor::sleep_for(sleep_test_time);
}
} else {
comm->wait();
double sleep_start_time = 1.0;
double sleep_test_time = 0.1;
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
- simgrid::s4u::this_actor::sleep_for(sleep_start_time);
+ sg4::this_actor::sleep_for(sleep_start_time);
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
std::string* received;
- simgrid::s4u::CommPtr comm = mbox->get_async<std::string>(&received);
+ sg4::CommPtr comm = mbox->get_async<std::string>(&received);
if (sleep_test_time > 0) { /* - "test_time" is set to 0, wait */
while (not comm->test()) { /* - Call test() every "sleep_test_time" otherwise */
- simgrid::s4u::this_actor::sleep_for(sleep_test_time);
+ sg4::this_actor::sleep_for(sleep_test_time);
}
} else {
comm->wait();
{
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.register_function("sender", &sender);
e.register_function("receiver", &receiver);
#include <cstdlib>
#include <iostream>
#include <string>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_waitall, "Messages specific for this s4u example");
{
// sphinx-doc: init-begin (this line helps the doc to build; ignore it)
/* Vector in which we store all ongoing communications */
- std::vector<simgrid::s4u::CommPtr> pending_comms;
+ std::vector<sg4::CommPtr> pending_comms;
/* Make a vector of the mailboxes to use */
- std::vector<simgrid::s4u::Mailbox*> mboxes;
+ std::vector<sg4::Mailbox*> mboxes;
for (int i = 0; i < receivers_count; i++)
- mboxes.push_back(simgrid::s4u::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
+ mboxes.push_back(sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
// sphinx-doc: init-end
/* Start dispatching all messages to receivers, in a round robin fashion */
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 */
- simgrid::s4u::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
+ 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 (int i = 0; i < receivers_count; i++) {
XBT_INFO("Send 'finalize' to 'receiver-%d'", i);
- simgrid::s4u::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
+ 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 */
- simgrid::s4u::Comm::wait_all(&pending_comms);
+ sg4::Comm::wait_all(&pending_comms);
// sphinx-doc: put-end
XBT_INFO("Goodbye now!");
/* Receiver actor expects 1 argument: its ID */
class Receiver {
- simgrid::s4u::Mailbox* mbox;
+ sg4::Mailbox* mbox;
public:
explicit Receiver(std::vector<std::string> args)
{
xbt_assert(args.size() == 2, "Expecting one parameter from the XML deployment file but got %zu", args.size());
std::string mboxName = std::string("receiver-") + args[1];
- mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+ mbox = sg4::Mailbox::by_name(mboxName);
}
void operator()()
{
{
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.register_actor<Sender>("sender");
e.register_actor<Receiver>("receiver");
#include <cstdlib>
#include <iostream>
#include <string>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_waitall, "Messages specific for this s4u example");
void operator()() const
{
/* Vector in which we store all ongoing communications */
- std::vector<simgrid::s4u::CommPtr> pending_comms;
+ std::vector<sg4::CommPtr> pending_comms;
/* Make a vector of the mailboxes to use */
- std::vector<simgrid::s4u::Mailbox*> mboxes;
+ std::vector<sg4::Mailbox*> mboxes;
for (int i = 0; i < receivers_count; i++)
- mboxes.push_back(simgrid::s4u::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
+ mboxes.push_back(sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
/* Start dispatching all messages to receivers, in a round robin fashion */
for (int i = 0; i < messages_count; i++) {
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 */
- simgrid::s4u::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
+ 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 */
for (int i = 0; i < receivers_count; i++) {
XBT_INFO("Send 'finalize' to 'receiver-%d'", i);
- simgrid::s4u::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
+ sg4::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
pending_comms.push_back(comm);
}
XBT_INFO("Done dispatching all messages");
* Even in this simple example, the pending comms do not terminate in the exact same order of creation.
*/
while (not pending_comms.empty()) {
- int changed_pos = simgrid::s4u::Comm::wait_any(&pending_comms);
+ int changed_pos = sg4::Comm::wait_any(&pending_comms);
pending_comms.erase(pending_comms.begin() + changed_pos);
if (changed_pos != 0)
XBT_INFO("Remove the %dth pending comm: it terminated earlier than another comm that was initiated first.",
/* Receiver actor expects 1 argument: its ID */
class Receiver {
- simgrid::s4u::Mailbox* mbox;
+ sg4::Mailbox* mbox;
public:
explicit Receiver(std::vector<std::string> args)
{
xbt_assert(args.size() == 2, "Expecting one parameter from the XML deployment file but got %zu", args.size());
std::string mboxName = std::string("receiver-") + args[1];
- mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+ mbox = sg4::Mailbox::by_name(mboxName);
}
void operator()()
{
{
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.register_actor<Sender>("sender");
e.register_actor<Receiver>("receiver");
#include <cstdlib>
#include <iostream>
#include <string>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_waituntil, "Messages specific for this s4u example");
long msg_size = std::stol(argv[2]); /* - message size in bytes */
long receivers_count = std::stol(argv[3]); /* - number of receivers */
- std::vector<simgrid::s4u::CommPtr> pending_comms;
+ std::vector<sg4::CommPtr> pending_comms;
/* Start dispatching all messages to receivers, in a round robin fashion */
for (int i = 0; i < messages_count; i++) {
std::string mboxName = std::string("receiver-") + std::to_string(i % receivers_count);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(mboxName);
std::string msgName = std::string("Message ") + std::to_string(i);
auto* payload = new std::string(msgName); // copy the data we send:
// 'msgName' is not a stable storage location
XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
/* Create a communication representing the ongoing communication */
- simgrid::s4u::CommPtr comm = mbox->put_async(payload, msg_size);
+ sg4::CommPtr comm = mbox->put_async(payload, msg_size);
/* Add this comm to the vector of all known comms */
pending_comms.push_back(comm);
}
/* Start sending messages to let the workers know that they should stop */
for (int i = 0; i < receivers_count; i++) {
std::string mboxName = std::string("receiver-") + std::to_string(i % receivers_count);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(mboxName);
auto* payload = new std::string("finalize"); // Make a copy of the data we will send
- simgrid::s4u::CommPtr comm = mbox->put_async(payload, 0);
+ sg4::CommPtr comm = mbox->put_async(payload, 0);
pending_comms.push_back(comm);
XBT_INFO("Send 'finalize' to 'receiver-%ld'", i % receivers_count);
}
/* Now that all message exchanges were initiated, wait for their completion, in order of creation. */
while (not pending_comms.empty()) {
- simgrid::s4u::CommPtr comm = pending_comms.back();
+ sg4::CommPtr comm = pending_comms.back();
comm->wait_for(1);
pending_comms.pop_back(); // remove it from the list
}
static void receiver(int argc, char** argv)
{
xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(std::string("receiver-") + argv[1]);
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("receiver-") + argv[1]);
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
{
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.register_function("sender", &sender);
e.register_function("receiver", &receiver);