-/* Copyright (c) 2012-2022. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2012-2022. 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 "s4u-tracker.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_peer, "Messages specific for the peers");
+namespace sg4 = simgrid::s4u;
/*
* User parameters for transferred file data. For the test, the default values are :
xbt_assert(args.size() == 3 || args.size() == 4, "Wrong number of arguments");
try {
id = std::stoi(args[1]);
- mailbox_ = simgrid::s4u::Mailbox::by_name(std::to_string(id));
+ mailbox_ = sg4::Mailbox::by_name(std::to_string(id));
} catch (const std::invalid_argument&) {
throw std::invalid_argument("Invalid ID:" + args[1]);
}
// Getting peer data from the tracker.
if (getPeersFromTracker()) {
XBT_DEBUG("Got %zu peers from the tracker. Current status is: %s", connected_peers.size(), getStatus().c_str());
- begin_receive_time = simgrid::s4u::Engine::get_clock();
- mailbox_->set_receiver(simgrid::s4u::Actor::self());
+ begin_receive_time = sg4::Engine::get_clock();
+ mailbox_->set_receiver(sg4::Actor::self());
if (hasFinished()) {
sendHandshakeToAllPeers();
} else {
bool Peer::getPeersFromTracker()
{
- simgrid::s4u::Mailbox* tracker_mailbox = simgrid::s4u::Mailbox::by_name(TRACKER_MAILBOX);
+ sg4::Mailbox* tracker_mailbox = sg4::Mailbox::by_name(TRACKER_MAILBOX);
// Build the task to send to the tracker
auto* peer_request = new TrackerQuery(id, mailbox_);
try {
}
}
-void Peer::sendMessage(simgrid::s4u::Mailbox* mailbox, MessageType type, uint64_t size)
+void Peer::sendMessage(sg4::Mailbox* mailbox, MessageType type, uint64_t size)
{
XBT_DEBUG("Sending %s to %s", message_name(type), mailbox->get_cname());
mailbox->put_init(new Message(type, id, bitfield_, mailbox_), size)->detach();
}
-void Peer::sendBitfield(simgrid::s4u::Mailbox* mailbox)
+void Peer::sendBitfield(sg4::Mailbox* mailbox)
{
XBT_DEBUG("Sending a BITFIELD to %s", mailbox->get_cname());
mailbox
->detach();
}
-void Peer::sendPiece(simgrid::s4u::Mailbox* mailbox, unsigned int piece, int block_index, int block_length)
+void Peer::sendPiece(sg4::Mailbox* mailbox, unsigned int piece, int block_index, int block_length)
{
xbt_assert(not hasNotPiece(piece), "Tried to send a unavailable piece.");
XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->get_cname());
void Peer::leech()
{
- double next_choked_update = simgrid::s4u::Engine::get_clock() + UPDATE_CHOKED_INTERVAL;
+ double next_choked_update = sg4::Engine::get_clock() + UPDATE_CHOKED_INTERVAL;
XBT_DEBUG("Start downloading.");
/* Send a "handshake" message to all the peers it got (since it couldn't have gotten more than 50 peers) */
sendHandshakeToAllPeers();
XBT_DEBUG("Starting main leech loop listening on mailbox: %s", mailbox_->get_cname());
- while (simgrid::s4u::Engine::get_clock() < deadline && countPieces(bitfield_) < FILE_PIECES) {
+ while (sg4::Engine::get_clock() < deadline && countPieces(bitfield_) < FILE_PIECES) {
if (comm_received == nullptr) {
comm_received = mailbox_->get_async<Message>(&message);
}
comm_received = nullptr;
} else {
// We don't execute the choke algorithm if we don't already have a piece
- if (simgrid::s4u::Engine::get_clock() >= next_choked_update && countPieces(bitfield_) > 0) {
+ if (sg4::Engine::get_clock() >= next_choked_update && countPieces(bitfield_) > 0) {
updateChokedPeers();
next_choked_update += UPDATE_CHOKED_INTERVAL;
} else {
- simgrid::s4u::this_actor::sleep_for(SLEEP_DURATION);
+ sg4::this_actor::sleep_for(SLEEP_DURATION);
}
}
}
void Peer::seed()
{
- double next_choked_update = simgrid::s4u::Engine::get_clock() + UPDATE_CHOKED_INTERVAL;
+ double next_choked_update = sg4::Engine::get_clock() + UPDATE_CHOKED_INTERVAL;
XBT_DEBUG("Start seeding.");
// start the main seed loop
- while (simgrid::s4u::Engine::get_clock() < deadline) {
+ while (sg4::Engine::get_clock() < deadline) {
if (comm_received == nullptr) {
comm_received = mailbox_->get_async<Message>(&message);
}
delete message;
comm_received = nullptr;
} else {
- if (simgrid::s4u::Engine::get_clock() >= next_choked_update) {
+ if (sg4::Engine::get_clock() >= next_choked_update) {
updateChokedPeers();
// TODO: Change the choked peer algorithm when seeding.
next_choked_update += UPDATE_CHOKED_INTERVAL;
} else {
- simgrid::s4u::this_actor::sleep_for(SLEEP_DURATION);
+ sg4::this_actor::sleep_for(SLEEP_DURATION);
}
}
}
}
// Update the peer speed.
if (remote_peer) {
- remote_peer->addSpeedValue(1.0 / (simgrid::s4u::Engine::get_clock() - begin_receive_time));
+ remote_peer->addSpeedValue(1.0 / (sg4::Engine::get_clock() - begin_receive_time));
}
- begin_receive_time = simgrid::s4u::Engine::get_clock();
+ begin_receive_time = sg4::Engine::get_clock();
}
/** Selects the appropriate piece to download and requests it to the remote_peer */
/**If we are currently seeding, we unchoke the peer which has been unchoked the last time.*/
if (hasFinished()) {
- double unchoke_time = simgrid::s4u::Engine::get_clock() + 1;
+ double unchoke_time = sg4::Engine::get_clock() + 1;
for (auto& kv : connected_peers) {
Connection& remote_peer = kv.second;
if (remote_peer.last_unchoke < unchoke_time && remote_peer.interested && remote_peer.choked_upload) {
xbt_assert((chosen_peer->choked_upload), "Tries to unchoked an unchoked peer");
chosen_peer->choked_upload = false;
active_peers.insert(chosen_peer);
- chosen_peer->last_unchoke = simgrid::s4u::Engine::get_clock();
+ chosen_peer->last_unchoke = sg4::Engine::get_clock();
XBT_DEBUG("(%d) Sending a UNCHOKE to %d", id, chosen_peer->id);
updateActivePeersSet(chosen_peer);
sendMessage(chosen_peer->mailbox_, MessageType::UNCHOKE, message_size(MessageType::UNCHOKE));
-/* Copyright (c) 2012-2022. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2012-2022. 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 <algorithm>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_tracker, "Messages specific for the tracker");
+namespace sg4 = simgrid::s4u;
Tracker::Tracker(std::vector<std::string> args)
{
}
xbt_assert(deadline > 0, "Wrong deadline supplied");
- mailbox = simgrid::s4u::Mailbox::by_name(TRACKER_MAILBOX);
+ mailbox = sg4::Mailbox::by_name(TRACKER_MAILBOX);
XBT_INFO("Tracker launched.");
}
void Tracker::operator()()
{
- simgrid::s4u::CommPtr comm = nullptr;
+ sg4::CommPtr comm = nullptr;
TrackerQuery* query = nullptr;
- while (simgrid::s4u::Engine::get_clock() < deadline) {
+ while (sg4::Engine::get_clock() < deadline) {
if (comm == nullptr)
comm = mailbox->get_async<TrackerQuery>(&query);
if (comm->test()) {
delete query;
comm = nullptr;
} else {
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
}
}
XBT_INFO("Tracker is leaving");
constexpr unsigned MESSAGE_SEND_DATA_HEADER_SIZE = 1;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_chainsend, "Messages specific for chainsend");
+namespace sg4 = simgrid::s4u;
class ChainMessage {
public:
- simgrid::s4u::Mailbox* prev_ = nullptr;
- simgrid::s4u::Mailbox* next_ = nullptr;
+ sg4::Mailbox* prev_ = nullptr;
+ sg4::Mailbox* next_ = nullptr;
unsigned int num_pieces = 0;
- explicit ChainMessage(simgrid::s4u::Mailbox* prev, simgrid::s4u::Mailbox* next, const unsigned int num_pieces)
+ explicit ChainMessage(sg4::Mailbox* prev, sg4::Mailbox* next, const unsigned int num_pieces)
: prev_(prev), next_(next), num_pieces(num_pieces)
{
}
class Peer {
public:
- simgrid::s4u::Mailbox* prev = nullptr;
- simgrid::s4u::Mailbox* next = nullptr;
- simgrid::s4u::Mailbox* me = nullptr;
- std::vector<simgrid::s4u::CommPtr> pending_recvs;
- std::vector<simgrid::s4u::CommPtr> pending_sends;
+ sg4::Mailbox* prev = nullptr;
+ sg4::Mailbox* next = nullptr;
+ sg4::Mailbox* me = nullptr;
+ std::vector<sg4::CommPtr> pending_recvs;
+ std::vector<sg4::CommPtr> pending_sends;
unsigned long long received_bytes = 0;
unsigned int received_pieces = 0;
unsigned int total_pieces = 0;
- Peer() { me = simgrid::s4u::Mailbox::by_name(simgrid::s4u::Host::current()->get_cname()); }
+ Peer() { me = sg4::Mailbox::by_name(sg4::Host::current()->get_cname()); }
void joinChain()
{
bool done = false;
while (not done) {
- simgrid::s4u::CommPtr comm = me->get_async<FilePiece>(&received);
+ sg4::CommPtr comm = me->get_async<FilePiece>(&received);
pending_recvs.push_back(comm);
- ssize_t idx = simgrid::s4u::Comm::wait_any(pending_recvs);
+ ssize_t idx = sg4::Comm::wait_any(pending_recvs);
if (idx != -1) {
comm = pending_recvs.at(idx);
XBT_DEBUG("Peer %s got a 'SEND_DATA' message", me->get_cname());
pending_recvs.erase(pending_recvs.begin() + idx);
if (next != nullptr) {
XBT_DEBUG("Sending (asynchronously) from %s to %s", me->get_cname(), next->get_cname());
- simgrid::s4u::CommPtr send = next->put_async(received, MESSAGE_SEND_DATA_HEADER_SIZE + PIECE_SIZE);
+ sg4::CommPtr send = next->put_async(received, MESSAGE_SEND_DATA_HEADER_SIZE + PIECE_SIZE);
pending_sends.push_back(send);
} else
delete received;
class Broadcaster {
public:
- simgrid::s4u::Mailbox* first = nullptr;
- std::vector<simgrid::s4u::Mailbox*> mailboxes;
+ sg4::Mailbox* first = nullptr;
+ std::vector<sg4::Mailbox*> mailboxes;
unsigned int piece_count;
void buildChain()
first = mailboxes.front();
for (unsigned i = 0; i < mailboxes.size(); i++) {
- simgrid::s4u::Mailbox* prev = i > 0 ? mailboxes[i - 1] : nullptr;
- simgrid::s4u::Mailbox* next = i < mailboxes.size() - 1 ? mailboxes[i + 1] : nullptr;
+ sg4::Mailbox* prev = i > 0 ? mailboxes[i - 1] : nullptr;
+ sg4::Mailbox* next = i < mailboxes.size() - 1 ? mailboxes[i + 1] : nullptr;
XBT_DEBUG("Building chain--broadcaster:\"%s\" dest:\"%s\" prev:\"%s\" next:\"%s\"",
- simgrid::s4u::Host::current()->get_cname(), mailboxes[i]->get_cname(),
- prev ? prev->get_cname() : nullptr, next ? next->get_cname() : nullptr);
+ sg4::Host::current()->get_cname(), mailboxes[i]->get_cname(), prev ? prev->get_cname() : nullptr,
+ next ? next->get_cname() : nullptr);
/* Send message to current peer */
mailboxes[i]->put(new ChainMessage(prev, next, piece_count), MESSAGE_BUILD_CHAIN_SIZE);
}
void sendFile()
{
- std::vector<simgrid::s4u::CommPtr> pending_sends;
+ std::vector<sg4::CommPtr> pending_sends;
for (unsigned int current_piece = 0; current_piece < piece_count; current_piece++) {
- XBT_DEBUG("Sending (send) piece %u from %s into mailbox %s", current_piece,
- simgrid::s4u::Host::current()->get_cname(), first->get_cname());
- simgrid::s4u::CommPtr comm = first->put_async(new FilePiece(), MESSAGE_SEND_DATA_HEADER_SIZE + PIECE_SIZE);
+ XBT_DEBUG("Sending (send) piece %u from %s into mailbox %s", current_piece, sg4::Host::current()->get_cname(),
+ first->get_cname());
+ sg4::CommPtr comm = first->put_async(new FilePiece(), MESSAGE_SEND_DATA_HEADER_SIZE + PIECE_SIZE);
pending_sends.push_back(comm);
}
- simgrid::s4u::Comm::wait_all(pending_sends);
+ sg4::Comm::wait_all(pending_sends);
}
Broadcaster(int hostcount, unsigned int piece_count) : piece_count(piece_count)
for (int i = 1; i <= hostcount; i++) {
std::string name = std::string("node-") + std::to_string(i) + ".simgrid.org";
XBT_DEBUG("%s", name.c_str());
- mailboxes.push_back(simgrid::s4u::Mailbox::by_name(name));
+ mailboxes.push_back(sg4::Mailbox::by_name(name));
}
}
};
Peer p;
- double start_time = simgrid::s4u::Engine::get_clock();
+ double start_time = sg4::Engine::get_clock();
p.joinChain();
p.forwardFile();
- simgrid::s4u::Comm::wait_all(p.pending_sends);
- double end_time = simgrid::s4u::Engine::get_clock();
+ sg4::Comm::wait_all(p.pending_sends);
+ double end_time = sg4::Engine::get_clock();
XBT_INFO("### %f %llu bytes (Avg %f MB/s); copy finished (simulated).", end_time - start_time, p.received_bytes,
p.received_bytes / 1024.0 / 1024.0 / (end_time - start_time));
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("broadcaster", e.host_by_name("node-0.simgrid.org"), broadcaster, 8, 256);
+ sg4::Actor::create("broadcaster", e.host_by_name("node-0.simgrid.org"), broadcaster, 8, 256);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-1.simgrid.org"), peer);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-2.simgrid.org"), peer);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-3.simgrid.org"), peer);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-4.simgrid.org"), peer);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-5.simgrid.org"), peer);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-6.simgrid.org"), peer);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-7.simgrid.org"), peer);
- simgrid::s4u::Actor::create("peer", e.host_by_name("node-8.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-1.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-2.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-3.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-4.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-5.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-6.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-7.simgrid.org"), peer);
+ sg4::Actor::create("peer", e.host_by_name("node-8.simgrid.org"), peer);
e.run();
- XBT_INFO("Total simulation time: %e", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Total simulation time: %e", sg4::Engine::get_clock());
return 0;
}
#include <simgrid/s4u.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
class Master {
long tasks_count = 0;
double compute_cost = 0;
long communicate_cost = 0;
- std::vector<simgrid::s4u::Mailbox*> workers;
+ std::vector<sg4::Mailbox*> workers;
public:
explicit Master(std::vector<std::string> args)
compute_cost = std::stod(args[2]);
communicate_cost = std::stol(args[3]);
for (unsigned int i = 4; i < args.size(); i++)
- workers.push_back(simgrid::s4u::Mailbox::by_name(args[i]));
+ workers.push_back(sg4::Mailbox::by_name(args[i]));
XBT_INFO("Got %zu workers and %ld tasks to process", workers.size(), tasks_count);
}
{
for (int i = 0; i < tasks_count; i++) { /* For each task to be executed: */
/* - Select a worker in a round-robin way */
- simgrid::s4u::Mailbox* mailbox = workers[i % workers.size()];
+ sg4::Mailbox* mailbox = workers[i % workers.size()];
/* - Send the computation amount to the worker */
if (tasks_count < 10000 || (tasks_count < 100000 && i % 10000 == 0) || i % 100000 == 0)
XBT_INFO("All tasks have been dispatched. Request all workers to stop.");
for (unsigned int i = 0; i < workers.size(); i++) {
/* The workers stop when receiving a negative compute_cost */
- simgrid::s4u::Mailbox* mailbox = workers[i % workers.size()];
+ sg4::Mailbox* mailbox = workers[i % workers.size()];
mailbox->put(new double(-1.0), 0);
}
}
};
class Worker {
- simgrid::s4u::Mailbox* mailbox = nullptr;
+ sg4::Mailbox* mailbox = nullptr;
public:
explicit Worker(std::vector<std::string> args)
{
xbt_assert(args.size() == 1, "The worker expects to not get any argument");
- mailbox = simgrid::s4u::Mailbox::by_name(simgrid::s4u::this_actor::get_host()->get_name());
+ mailbox = sg4::Mailbox::by_name(sg4::this_actor::get_host()->get_name());
}
void operator()()
compute_cost = *msg;
if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
- simgrid::s4u::this_actor::execute(compute_cost);
+ sg4::this_actor::execute(compute_cost);
} while (compute_cost > 0); /* Stop when receiving an invalid compute_cost */
XBT_INFO("Exiting now.");
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
/* Register the classes representing the actors */
/* ************************************************************************* */
#include <simgrid/s4u.hpp>
+namespace sg4 = simgrid::s4u;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this example");
long tasks_count = std::stol(args[1]);
double compute_cost = std::stod(args[2]);
long communication_cost = std::stol(args[3]);
- std::vector<simgrid::s4u::Mailbox*> workers;
+ std::vector<sg4::Mailbox*> workers;
for (unsigned int i = 4; i < args.size(); i++)
- workers.push_back(simgrid::s4u::Mailbox::by_name(args[i]));
+ workers.push_back(sg4::Mailbox::by_name(args[i]));
XBT_INFO("Got %zu workers and %ld tasks to process", workers.size(), tasks_count);
for (int i = 0; i < tasks_count; i++) { /* For each task to be executed: */
/* - Select a worker in a round-robin way */
- simgrid::s4u::Mailbox* mailbox = workers[i % workers.size()];
+ sg4::Mailbox* mailbox = workers[i % workers.size()];
/* - Send the computation cost to that worker */
XBT_INFO("Sending task %d of %ld to mailbox '%s'", i, tasks_count, mailbox->get_cname());
XBT_INFO("All tasks have been dispatched. Request all workers to stop.");
for (unsigned int i = 0; i < workers.size(); i++) {
/* The workers stop when receiving a negative compute_cost */
- simgrid::s4u::Mailbox* mailbox = workers[i % workers.size()];
+ sg4::Mailbox* mailbox = workers[i % workers.size()];
mailbox->put(new double(-1.0), 0);
}
{
xbt_assert(args.size() == 1, "The worker expects no argument");
- const simgrid::s4u::Host* my_host = simgrid::s4u::this_actor::get_host();
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(my_host->get_name());
+ const sg4::Host* my_host = sg4::this_actor::get_host();
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(my_host->get_name());
double compute_cost;
do {
compute_cost = *msg;
if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
- simgrid::s4u::this_actor::execute(compute_cost);
+ sg4::this_actor::execute(compute_cost);
} while (compute_cost > 0); /* Stop when receiving an invalid compute_cost */
XBT_INFO("Exiting now.");
// main-begin
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
/* Register the functions representing the actors */
#include <vector>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_token_ring, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
class RelayRunner {
public:
void operator()() const
{
size_t token_size = 1000000; /* The token is 1MB long*/
- simgrid::s4u::Mailbox* my_mailbox;
- simgrid::s4u::Mailbox* neighbor_mailbox;
+ sg4::Mailbox* my_mailbox;
+ sg4::Mailbox* neighbor_mailbox;
unsigned int rank = 0;
try {
- rank = std::stoi(simgrid::s4u::this_actor::get_name());
+ rank = std::stoi(sg4::this_actor::get_name());
} catch (const std::invalid_argument& ia) {
throw std::invalid_argument(std::string("Actors of this example must have a numerical name, not ") + ia.what());
}
- my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(rank));
- if (rank + 1 == simgrid::s4u::Engine::get_instance()->get_host_count())
+ my_mailbox = sg4::Mailbox::by_name(std::to_string(rank));
+ if (rank + 1 == sg4::Engine::get_instance()->get_host_count())
/* The last actor sends the token back to rank 0 */
- neighbor_mailbox = simgrid::s4u::Mailbox::by_name("0");
+ neighbor_mailbox = sg4::Mailbox::by_name("0");
else
/* The others actors send to their right neighbor (rank+1) */
- neighbor_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(rank + 1));
+ neighbor_mailbox = sg4::Mailbox::by_name(std::to_string(rank + 1));
if (rank == 0) {
/* The root actor (rank 0) first sends the token then waits to receive it back */
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
e.load_platform(argv[1]);
XBT_INFO("Number of hosts '%zu'", e.get_host_count());
int id = 0;
- std::vector<simgrid::s4u::Host*> list = e.get_all_hosts();
+ std::vector<sg4::Host*> list = e.get_all_hosts();
for (auto const& host : list) {
/* - Give a unique rank to each host and create a @ref relay_runner actor on each */
- simgrid::s4u::Actor::create((std::to_string(id)).c_str(), host, RelayRunner());
+ sg4::Actor::create((std::to_string(id)).c_str(), host, RelayRunner());
id++;
}
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u/VirtualMachine.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void worker(double computation_amount, bool use_bound, double bound)
{
- double clock_start = simgrid::s4u::Engine::get_clock();
+ double clock_start = sg4::Engine::get_clock();
- simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(computation_amount);
+ sg4::ExecPtr exec = sg4::this_actor::exec_init(computation_amount);
if (use_bound) {
if (bound < 1e-12) /* close enough to 0 without any floating precision surprise */
}
exec->start();
exec->wait();
- double clock_end = simgrid::s4u::Engine::get_clock();
+ double clock_end = sg4::Engine::get_clock();
double duration = clock_end - clock_start;
double flops_per_sec = computation_amount / duration;
static void worker_busy_loop(const char* name, double speed)
{
double exec_remain_prev = 1e11;
- simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_async(exec_remain_prev);
+ sg4::ExecPtr exec = sg4::this_actor::exec_async(exec_remain_prev);
for (int i = 0; i < 10; i++) {
if (speed > 0) {
double new_bound = (speed / 10) * i;
XBT_INFO("set bound of VM1 to %f", new_bound);
- static_cast<simgrid::s4u::VirtualMachine*>(simgrid::s4u::this_actor::get_host())->set_bound(new_bound);
+ static_cast<sg4::VirtualMachine*>(sg4::this_actor::get_host())->set_bound(new_bound);
}
- simgrid::s4u::this_actor::sleep_for(100);
+ sg4::this_actor::sleep_for(100);
double exec_remain_now = exec->get_remaining();
double flops_per_sec = exec_remain_prev - exec_remain_now;
- XBT_INFO("%s@%s: %.0f flops/s", name, simgrid::s4u::this_actor::get_host()->get_cname(), flops_per_sec / 100);
+ XBT_INFO("%s@%s: %.0f flops/s", name, sg4::this_actor::get_host()->get_cname(), flops_per_sec / 100);
exec_remain_prev = exec_remain_now;
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
}
exec->wait();
}
static void test_dynamic_change()
{
- simgrid::s4u::Host* pm0 = simgrid::s4u::Host::by_name("Fafard");
+ sg4::Host* pm0 = sg4::Host::by_name("Fafard");
auto* vm0 = pm0->create_vm("VM0", 1);
auto* vm1 = pm0->create_vm("VM1", 1);
vm0->start();
vm1->start();
- simgrid::s4u::Actor::create("worker0", vm0, worker_busy_loop, "Task0", -1);
- simgrid::s4u::Actor::create("worker1", vm1, worker_busy_loop, "Task1", pm0->get_speed());
+ sg4::Actor::create("worker0", vm0, worker_busy_loop, "Task0", -1);
+ sg4::Actor::create("worker1", vm1, worker_busy_loop, "Task1", pm0->get_speed());
- simgrid::s4u::this_actor::sleep_for(3000); // let the activities end
+ sg4::this_actor::sleep_for(3000); // let the activities end
vm0->destroy();
vm1->destroy();
}
-static void test_one_activity(simgrid::s4u::Host* host)
+static void test_one_activity(sg4::Host* host)
{
const double cpu_speed = host->get_speed();
const double computation_amount = cpu_speed * 10;
XBT_INFO("### Test: with/without activity set_bound");
XBT_INFO("### Test: no bound for Task1@%s", host->get_cname());
- simgrid::s4u::Actor::create("worker0", host, worker, computation_amount, false, 0);
+ sg4::Actor::create("worker0", host, worker, computation_amount, false, 0);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 50%% for Task1@%s", host->get_cname());
- simgrid::s4u::Actor::create("worker0", host, worker, computation_amount, true, cpu_speed / 2);
+ sg4::Actor::create("worker0", host, worker, computation_amount, true, cpu_speed / 2);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 33%% for Task1@%s", host->get_cname());
- simgrid::s4u::Actor::create("worker0", host, worker, computation_amount, true, cpu_speed / 3);
+ sg4::Actor::create("worker0", host, worker, computation_amount, true, cpu_speed / 3);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: zero for Task1@%s (i.e., unlimited)", host->get_cname());
- simgrid::s4u::Actor::create("worker0", host, worker, computation_amount, true, 0);
+ sg4::Actor::create("worker0", host, worker, computation_amount, true, 0);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 200%% for Task1@%s (i.e., meaningless)", host->get_cname());
- simgrid::s4u::Actor::create("worker0", host, worker, computation_amount, true, cpu_speed * 2);
+ sg4::Actor::create("worker0", host, worker, computation_amount, true, cpu_speed * 2);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
}
-static void test_two_activities(simgrid::s4u::Host* hostA, simgrid::s4u::Host* hostB)
+static void test_two_activities(sg4::Host* hostA, sg4::Host* hostB)
{
const double cpu_speed = hostA->get_speed();
xbt_assert(cpu_speed == hostB->get_speed());
const char* hostB_name = hostB->get_cname();
XBT_INFO("### Test: no bound for Task1@%s, no bound for Task2@%s", hostA_name, hostB_name);
- simgrid::s4u::Actor::create("worker0", hostA, worker, computation_amount, false, 0);
- simgrid::s4u::Actor::create("worker1", hostB, worker, computation_amount, false, 0);
+ sg4::Actor::create("worker0", hostA, worker, computation_amount, false, 0);
+ sg4::Actor::create("worker1", hostB, worker, computation_amount, false, 0);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 0 for Task1@%s, 0 for Task2@%s (i.e., unlimited)", hostA_name, hostB_name);
- simgrid::s4u::Actor::create("worker0", hostA, worker, computation_amount, true, 0);
- simgrid::s4u::Actor::create("worker1", hostB, worker, computation_amount, true, 0);
+ sg4::Actor::create("worker0", hostA, worker, computation_amount, true, 0);
+ sg4::Actor::create("worker1", hostB, worker, computation_amount, true, 0);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 50%% for Task1@%s, 50%% for Task2@%s", hostA_name, hostB_name);
- simgrid::s4u::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed / 2);
- simgrid::s4u::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 2);
+ sg4::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed / 2);
+ sg4::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 2);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 25%% for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name);
- simgrid::s4u::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed / 4);
- simgrid::s4u::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 4);
+ sg4::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed / 4);
+ sg4::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 4);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 75%% for Task1@%s, 100%% for Task2@%s", hostA_name, hostB_name);
- simgrid::s4u::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed * 0.75);
- simgrid::s4u::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed);
+ sg4::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed * 0.75);
+ sg4::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: no bound for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name);
- simgrid::s4u::Actor::create("worker0", hostA, worker, computation_amount, false, 0);
- simgrid::s4u::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 4);
+ sg4::Actor::create("worker0", hostA, worker, computation_amount, false, 0);
+ sg4::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 4);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO("### Test: 75%% for Task1@%s, 25%% for Task2@%s", hostA_name, hostB_name);
- simgrid::s4u::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed * 0.75);
- simgrid::s4u::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 4);
+ sg4::Actor::create("worker0", hostA, worker, computation_amount, true, cpu_speed * 0.75);
+ sg4::Actor::create("worker1", hostB, worker, computation_amount, true, cpu_speed / 4);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::this_actor::sleep_for(1000);
}
static void master_main()
{
- simgrid::s4u::Host* pm0 = simgrid::s4u::Host::by_name("Fafard");
+ sg4::Host* pm0 = sg4::Host::by_name("Fafard");
XBT_INFO("# 1. Put a single activity on a PM.");
test_one_activity(pm0);
const double computation_amount = cpu_speed * 10;
XBT_INFO("# 10. (a) Put an activity on a VM without any bound.");
- simgrid::s4u::Actor::create("worker0", vm0, worker, computation_amount, false, 0);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::Actor::create("worker0", vm0, worker, computation_amount, false, 0);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO(".");
XBT_INFO("# 10. (b) set 10%% bound to the VM, and then put an activity on the VM.");
vm0->set_bound(cpu_speed / 10);
- simgrid::s4u::Actor::create("worker0", vm0, worker, computation_amount, false, 0);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::Actor::create("worker0", vm0, worker, computation_amount, false, 0);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO(".");
XBT_INFO("# 10. (c) migrate");
- simgrid::s4u::Host* pm1 = simgrid::s4u::Host::by_name("Fafard");
+ sg4::Host* pm1 = sg4::Host::by_name("Fafard");
sg_vm_migrate(vm0, pm1);
XBT_INFO(".");
XBT_INFO("# 10. (d) Put an activity again on the VM.");
- simgrid::s4u::Actor::create("worker0", vm0, worker, computation_amount, false, 0);
- simgrid::s4u::this_actor::sleep_for(1000);
+ sg4::Actor::create("worker0", vm0, worker, computation_amount, false, 0);
+ sg4::this_actor::sleep_for(1000);
XBT_INFO(".");
vm0->destroy();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_vm_live_migration_plugin_init();
/* load the platform file */
xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/small_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("master_", e.host_by_name("Fafard"), master_main);
+ sg4::Actor::create("master_", e.host_by_name("Fafard"), master_main);
e.run();
- XBT_INFO("Bye (simulation time %g)", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Bye (simulation time %g)", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u/VirtualMachine.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_cloud_migration, "Messages specific for this example");
+namespace sg4 = simgrid::s4u;
-static void vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm)
+static void vm_migrate(sg4::VirtualMachine* vm, sg4::Host* dst_pm)
{
- const simgrid::s4u::Host* src_pm = vm->get_pm();
- double mig_sta = simgrid::s4u::Engine::get_clock();
+ const sg4::Host* src_pm = vm->get_pm();
+ double mig_sta = sg4::Engine::get_clock();
sg_vm_migrate(vm, dst_pm);
- double mig_end = simgrid::s4u::Engine::get_clock();
+ double mig_end = sg4::Engine::get_clock();
XBT_INFO("%s migrated: %s->%s in %g s", vm->get_cname(), src_pm->get_cname(), dst_pm->get_cname(), mig_end - mig_sta);
}
-static void vm_migrate_async(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm)
+static void vm_migrate_async(sg4::VirtualMachine* vm, sg4::Host* dst_pm)
{
- simgrid::s4u::Actor::create("mig_wrk", simgrid::s4u::Host::current(), vm_migrate, vm, dst_pm);
+ sg4::Actor::create("mig_wrk", sg4::Host::current(), vm_migrate, vm, dst_pm);
}
static void master_main()
{
- simgrid::s4u::Host* pm0 = simgrid::s4u::Host::by_name("Fafard");
- simgrid::s4u::Host* pm1 = simgrid::s4u::Host::by_name("Tremblay");
- simgrid::s4u::Host* pm2 = simgrid::s4u::Host::by_name("Bourassa");
+ sg4::Host* pm0 = sg4::Host::by_name("Fafard");
+ sg4::Host* pm1 = sg4::Host::by_name("Tremblay");
+ sg4::Host* pm2 = sg4::Host::by_name("Bourassa");
auto* vm0 = pm0->create_vm("VM0", 1);
vm0->set_ramsize(1e9); // 1Gbytes
XBT_INFO("Test: Migrate two VMs at once from PM0 to PM1");
vm_migrate_async(vm0, pm1);
vm_migrate_async(vm1, pm1);
- simgrid::s4u::this_actor::sleep_for(10000);
+ sg4::this_actor::sleep_for(10000);
vm0->destroy();
vm1->destroy();
XBT_INFO("Test: Migrate two VMs at once to different PMs");
vm_migrate_async(vm0, pm1);
vm_migrate_async(vm1, pm2);
- simgrid::s4u::this_actor::sleep_for(10000);
+ sg4::this_actor::sleep_for(10000);
vm0->destroy();
vm1->destroy();
int main(int argc, char* argv[])
{
/* Get the arguments */
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_vm_live_migration_plugin_init();
/* load the platform file */
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("master_", simgrid::s4u::Host::by_name("Fafard"), master_main);
+ sg4::Actor::create("master_", sg4::Host::by_name("Fafard"), master_main);
e.run();
- XBT_INFO("Bye (simulation time %g)", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Bye (simulation time %g)", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u/VirtualMachine.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void computation_fun()
{
- double clock_sta = simgrid::s4u::Engine::get_clock();
- simgrid::s4u::this_actor::execute(1000000);
- double clock_end = simgrid::s4u::Engine::get_clock();
+ double clock_sta = sg4::Engine::get_clock();
+ sg4::this_actor::execute(1000000);
+ double clock_end = sg4::Engine::get_clock();
- XBT_INFO("%s:%s executed %g", simgrid::s4u::this_actor::get_host()->get_cname(),
- simgrid::s4u::this_actor::get_cname(), clock_end - clock_sta);
+ XBT_INFO("%s:%s executed %g", sg4::this_actor::get_host()->get_cname(), sg4::this_actor::get_cname(),
+ clock_end - clock_sta);
}
static void launch_computation_worker(s4u_Host* host)
{
- simgrid::s4u::Actor::create("compute", host, computation_fun);
+ sg4::Actor::create("compute", host, computation_fun);
}
struct s_payload {
static void communication_tx_fun(std::vector<std::string> args)
{
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0));
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(args.at(0));
auto* payload = new s_payload;
- payload->tx_actor_name = simgrid::s4u::Actor::self()->get_cname();
- payload->tx_host = simgrid::s4u::this_actor::get_host();
- payload->clock_sta = simgrid::s4u::Engine::get_clock();
+ payload->tx_actor_name = sg4::Actor::self()->get_cname();
+ payload->tx_host = sg4::this_actor::get_host();
+ payload->clock_sta = sg4::Engine::get_clock();
mbox->put(payload, 1000000);
}
static void communication_rx_fun(std::vector<std::string> args)
{
- const char* actor_name = simgrid::s4u::Actor::self()->get_cname();
- const char* host_name = simgrid::s4u::this_actor::get_host()->get_cname();
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0));
+ const char* actor_name = sg4::Actor::self()->get_cname();
+ const char* host_name = sg4::this_actor::get_host()->get_cname();
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(args.at(0));
auto payload = mbox->get_unique<struct s_payload>();
- double clock_end = simgrid::s4u::Engine::get_clock();
+ double clock_end = sg4::Engine::get_clock();
XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name,
clock_end - payload->clock_sta);
std::vector<std::string> args;
args.push_back(mbox_name);
- simgrid::s4u::Actor::create("comm_tx", tx_host, communication_tx_fun, args);
+ sg4::Actor::create("comm_tx", tx_host, communication_tx_fun, args);
- simgrid::s4u::Actor::create("comm_rx", rx_host, communication_rx_fun, args);
+ sg4::Actor::create("comm_rx", rx_host, communication_rx_fun, args);
}
static void master_main()
{
- s4u_Host* pm0 = simgrid::s4u::Host::by_name("Fafard");
- s4u_Host* pm1 = simgrid::s4u::Host::by_name("Tremblay");
- s4u_Host* pm2 = simgrid::s4u::Host::by_name("Bourassa");
+ s4u_Host* pm0 = sg4::Host::by_name("Fafard");
+ s4u_Host* pm1 = sg4::Host::by_name("Tremblay");
+ s4u_Host* pm2 = sg4::Host::by_name("Bourassa");
XBT_INFO("## Test 1 (started): check computation on normal PMs");
XBT_INFO("### Put an activity on a PM");
launch_computation_worker(pm0);
- simgrid::s4u::this_actor::sleep_for(2);
+ sg4::this_actor::sleep_for(2);
XBT_INFO("### Put two activities on a PM");
launch_computation_worker(pm0);
launch_computation_worker(pm0);
- simgrid::s4u::this_actor::sleep_for(2);
+ sg4::this_actor::sleep_for(2);
XBT_INFO("### Put an activity on each PM");
launch_computation_worker(pm0);
launch_computation_worker(pm1);
- simgrid::s4u::this_actor::sleep_for(2);
+ sg4::this_actor::sleep_for(2);
XBT_INFO("## Test 1 (ended)");
auto* vm0 = pm0->create_vm("VM0", 1);
vm0->start();
launch_computation_worker(vm0);
- simgrid::s4u::this_actor::sleep_for(2);
+ sg4::this_actor::sleep_for(2);
vm0->destroy();
XBT_INFO("## Test 2 (ended)");
vm0 = pm0->create_vm("VM0", 1);
vm0->start();
launch_computation_worker(pm0);
- simgrid::s4u::this_actor::sleep_for(2);
+ sg4::this_actor::sleep_for(2);
vm0->destroy();
XBT_INFO("## Test 3 (ended)");
auto* vm1 = pm0->create_vm("VM1", 1);
launch_computation_worker(vm0);
launch_computation_worker(vm1);
- simgrid::s4u::this_actor::sleep_for(2);
+ sg4::this_actor::sleep_for(2);
vm0->destroy();
vm1->destroy();
vm1->start();
launch_computation_worker(vm0);
launch_computation_worker(vm1);
- simgrid::s4u::this_actor::sleep_for(2);
+ sg4::this_actor::sleep_for(2);
vm0->destroy();
vm1->destroy();
XBT_INFO("## Test 4 (ended)");
XBT_INFO("## Test 5 (started): Analyse network impact");
XBT_INFO("### Make a connection between PM0 and PM1");
launch_communication_worker(pm0, pm1);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
XBT_INFO("### Make two connection between PM0 and PM1");
launch_communication_worker(pm0, pm1);
launch_communication_worker(pm0, pm1);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
XBT_INFO("### Make a connection between PM0 and VM0@PM0");
vm0 = pm0->create_vm("VM0", 1);
vm0->start();
launch_communication_worker(pm0, vm0);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
vm0->destroy();
XBT_INFO("### Make a connection between PM0 and VM0@PM1");
vm0 = pm1->create_vm("VM0", 1);
launch_communication_worker(pm0, vm0);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
vm0->destroy();
XBT_INFO("### Make two connections between PM0 and VM0@PM1");
vm0->start();
launch_communication_worker(pm0, vm0);
launch_communication_worker(pm0, vm0);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
vm0->destroy();
XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
vm0->start();
launch_communication_worker(pm0, vm0);
launch_communication_worker(pm0, pm1);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
vm0->destroy();
XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
vm1->start();
launch_communication_worker(vm0, vm1);
launch_communication_worker(vm0, vm1);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
vm0->destroy();
vm1->destroy();
vm0->start();
launch_communication_worker(vm0, pm2);
- simgrid::s4u::this_actor::sleep_for(0.01);
+ sg4::this_actor::sleep_for(0.01);
sg_vm_migrate(vm0, pm1);
- simgrid::s4u::this_actor::sleep_for(0.01);
+ sg4::this_actor::sleep_for(0.01);
sg_vm_migrate(vm0, pm0);
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
vm0->destroy();
XBT_INFO("## Test 6 (ended)");
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_vm_live_migration_plugin_init();
e.load_platform(argv[1]); /* - Load the platform description */
- simgrid::s4u::Actor::create("master_", e.host_by_name("Fafard"), master_main);
+ sg4::Actor::create("master_", e.host_by_name("Fafard"), master_main);
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
}
XBT_INFO("Wait for remaining comm, just to be nice");
pending_comms.erase(pending_comms.begin());
- simgrid::s4u::Comm::wait_any(pending_comms);
+ sg4::Comm::wait_any(pending_comms);
}
};
#include <vector>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_storage_file_system_init();
e.load_platform(argv[1]);
auto jupiter = e.host_by_name("Jupiter");
// Display the details on vetoed activities
- simgrid::s4u::Activity::on_veto_cb([](const simgrid::s4u::Activity& a) {
+ sg4::Activity::on_veto_cb([](const sg4::Activity& a) {
XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(),
(a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned"));
});
- simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity const& activity) {
- const auto* exec = dynamic_cast<simgrid::s4u::Exec const*>(&activity);
+ sg4::Activity::on_completion_cb([](sg4::Activity const& activity) {
+ const auto* exec = dynamic_cast<sg4::Exec const*>(&activity);
if (exec != nullptr)
XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec->get_cname(), exec->get_start_time(),
exec->get_finish_time());
- const auto* comm = dynamic_cast<simgrid::s4u::Comm const*>(&activity);
+ const auto* comm = dynamic_cast<sg4::Comm const*>(&activity);
if (comm != nullptr)
XBT_INFO("Activity '%s' is complete", comm->get_cname());
});
// Create a small DAG: parent->transfert->child
- simgrid::s4u::ExecPtr parent = simgrid::s4u::Exec::init();
- simgrid::s4u::CommPtr transfert = simgrid::s4u::Comm::sendto_init();
- simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init();
+ sg4::ExecPtr parent = sg4::Exec::init();
+ sg4::CommPtr transfert = sg4::Comm::sendto_init();
+ sg4::ExecPtr child = sg4::Exec::init();
parent->add_successor(transfert);
transfert->add_successor(child);
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
auto* faulty = e.host_by_name("Faulty Host");
auto* safe = e.host_by_name("Safe Host");
sg4::Activity::on_completion_cb([](sg4::Activity const& activity) {
- const auto* exec = dynamic_cast<simgrid::s4u::Exec const*>(&activity);
+ const auto* exec = dynamic_cast<sg4::Exec const*>(&activity);
if (exec == nullptr) // Only Execs are concerned here
return;
if (exec->get_state() == sg4::Activity::State::FINISHED)
/* simple test trying to load a DAX file. */
-/* Copyright (c) 2009-2022. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2009-2022. 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 <string.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(dag_from_dax, "Logging specific to this example");
+namespace sg4 = simgrid::s4u;
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- std::vector<simgrid::s4u::ActivityPtr> dag = simgrid::s4u::create_DAG_from_DAX(argv[2]);
+ std::vector<sg4::ActivityPtr> dag = sg4::create_DAG_from_DAX(argv[2]);
if (dag.empty()) {
XBT_ERROR("A problem occurred during DAX parsing (cycle or syntax). Do not continue this test");
for (const auto& a : dag) {
std::string type = "an Exec";
std::string task = "flops to execute";
- if (dynamic_cast<simgrid::s4u::Comm*>(a.get()) != nullptr) {
+ if (dynamic_cast<sg4::Comm*>(a.get()) != nullptr) {
type = "a Comm";
task = "bytes to transfer";
}
auto count = e.get_host_count();
int cursor = 0;
// Schedule end first
- static_cast<simgrid::s4u::Exec*>(dag.back().get())->set_host(hosts[0]);
+ static_cast<sg4::Exec*>(dag.back().get())->set_host(hosts[0]);
for (const auto& a : dag) {
- auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
+ auto* exec = dynamic_cast<sg4::Exec*>(a.get());
if (exec != nullptr && exec->get_name() != "end") {
exec->set_host(hosts[cursor % count]);
cursor++;
}
- auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
+ auto* comm = dynamic_cast<sg4::Comm*>(a.get());
if (comm != nullptr) {
- auto pred = dynamic_cast<simgrid::s4u::Exec*>((*comm->get_dependencies().begin()).get());
- auto succ = dynamic_cast<simgrid::s4u::Exec*>(comm->get_successors().front().get());
+ auto pred = dynamic_cast<sg4::Exec*>((*comm->get_dependencies().begin()).get());
+ auto succ = dynamic_cast<sg4::Exec*>(comm->get_successors().front().get());
comm->set_source(pred->get_host())->set_destination(succ->get_host());
}
}
XBT_INFO("-------------- Summary of executed schedule ------------------");
for (const auto& a : dag) {
- const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
+ const auto* exec = dynamic_cast<sg4::Exec*>(a.get());
if (exec != nullptr) {
XBT_INFO("[%f->%f] '%s' executed on %s", exec->get_start_time(), exec->get_finish_time(), exec->get_cname(),
exec->get_host()->get_cname());
}
- const auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
+ const auto* comm = dynamic_cast<sg4::Comm*>(a.get());
if (comm != nullptr) {
XBT_INFO("[%f->%f] '%s' transferred from %s to %s", comm->get_start_time(), comm->get_finish_time(),
comm->get_cname(), comm->get_source()->get_cname(), comm->get_destination()->get_cname());
/* simple test trying to load a DOT file. */
-/* Copyright (c) 2010-2022. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2010-2022. 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 <stdio.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(dag_from_dot, "Logging specific to this example");
+namespace sg4 = simgrid::s4u;
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- std::vector<simgrid::s4u::ActivityPtr> dag = simgrid::s4u::create_DAG_from_dot(argv[2]);
+ std::vector<sg4::ActivityPtr> dag = sg4::create_DAG_from_dot(argv[2]);
if (dag.empty()) {
XBT_CRITICAL("No dot loaded. Do you have a cycle in your graph?");
for (const auto& a : dag) {
std::string type = "an Exec";
std::string task = "flops to execute";
- if (dynamic_cast<simgrid::s4u::Comm*>(a.get()) != nullptr) {
+ if (dynamic_cast<sg4::Comm*>(a.get()) != nullptr) {
type = "a Comm";
task = "bytes to transfer";
}
auto count = e.get_host_count();
int cursor = 0;
// Schedule end first
- static_cast<simgrid::s4u::Exec*>(dag.back().get())->set_host(hosts[0]);
+ static_cast<sg4::Exec*>(dag.back().get())->set_host(hosts[0]);
for (const auto& a : dag) {
- auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
+ auto* exec = dynamic_cast<sg4::Exec*>(a.get());
if (exec != nullptr && exec->get_name() != "end") {
exec->set_host(hosts[cursor % count]);
cursor++;
}
- auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
+ auto* comm = dynamic_cast<sg4::Comm*>(a.get());
if (comm != nullptr) {
- auto pred = dynamic_cast<simgrid::s4u::Exec*>((*comm->get_dependencies().begin()).get());
- auto succ = dynamic_cast<simgrid::s4u::Exec*>(comm->get_successors().front().get());
+ auto pred = dynamic_cast<sg4::Exec*>((*comm->get_dependencies().begin()).get());
+ auto succ = dynamic_cast<sg4::Exec*>(comm->get_successors().front().get());
comm->set_source(pred->get_host())->set_destination(succ->get_host());
}
}
XBT_INFO("-------------- Summary of executed schedule ------------------");
for (const auto& a : dag) {
- const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
+ const auto* exec = dynamic_cast<sg4::Exec*>(a.get());
if (exec != nullptr) {
XBT_INFO("[%f->%f] '%s' executed on %s", exec->get_start_time(), exec->get_finish_time(), exec->get_cname(),
exec->get_host()->get_cname());
}
- const auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
+ const auto* comm = dynamic_cast<sg4::Comm*>(a.get());
if (comm != nullptr) {
XBT_INFO("[%f->%f] '%s' transferred from %s to %s", comm->get_start_time(), comm->get_finish_time(),
comm->get_cname(), comm->get_source()->get_cname(), comm->get_destination()->get_cname());
#include <vector>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_storage_file_system_init();
e.load_platform(argv[1]);
auto carl = e.host_by_name("carl");
// Display the details on vetoed activities
- simgrid::s4u::Activity::on_veto_cb([](const simgrid::s4u::Activity& a) {
+ sg4::Activity::on_veto_cb([](const sg4::Activity& a) {
XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(),
(a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned"));
});
- simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity const& activity) {
- const auto* exec = dynamic_cast<simgrid::s4u::Exec const*>(&activity);
+ sg4::Activity::on_completion_cb([](sg4::Activity const& activity) {
+ const auto* exec = dynamic_cast<sg4::Exec const*>(&activity);
if (exec == nullptr) // Only Execs are concerned here
return;
XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec->get_cname(), exec->get_start_time(),
});
// Create a small DAG: parent->write_output->read_input->child
- simgrid::s4u::ExecPtr parent = simgrid::s4u::Exec::init();
- simgrid::s4u::IoPtr write_output = simgrid::s4u::Io::init();
- simgrid::s4u::IoPtr read_input = simgrid::s4u::Io::init();
- simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init();
+ sg4::ExecPtr parent = sg4::Exec::init();
+ sg4::IoPtr write_output = sg4::Io::init();
+ sg4::IoPtr read_input = sg4::Io::init();
+ sg4::ExecPtr child = sg4::Exec::init();
parent->add_successor(write_output);
write_output->add_successor(read_input);
read_input->add_successor(child);
// Set the parameters (the name is for logging purposes only)
// + parent and chile end after 1 second
parent->set_name("parent")->set_flops_amount(bob->get_speed());
- write_output->set_name("write")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::WRITE);
- read_input->set_name("read")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::READ);
+ write_output->set_name("write")->set_size(1e9)->set_op_type(sg4::Io::OpType::WRITE);
+ read_input->set_name("read")->set_size(1e9)->set_op_type(sg4::Io::OpType::READ);
child->set_name("child")->set_flops_amount(carl->get_speed());
// Schedule and try to start the different activities
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
-/* Copyright (c) 2009-2022. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2009-2022. 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 <string.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(dag_scheduling, "Logging specific to this example");
+namespace sg4 = simgrid::s4u;
struct HostAttribute {
/* Earliest time at which a host is ready to execute a task */
double available_at = 0.0;
- simgrid::s4u::Exec* last_scheduled_task = nullptr;
+ sg4::Exec* last_scheduled_task = nullptr;
};
-static double sg_host_get_available_at(const simgrid::s4u::Host* host)
+static double sg_host_get_available_at(const sg4::Host* host)
{
return host->get_data<HostAttribute>()->available_at;
}
-static void sg_host_set_available_at(const simgrid::s4u::Host* host, double time)
+static void sg_host_set_available_at(const sg4::Host* host, double time)
{
host->get_data<HostAttribute>()->available_at = time;
}
-static simgrid::s4u::Exec* sg_host_get_last_scheduled_task(const simgrid::s4u::Host* host)
+static sg4::Exec* sg_host_get_last_scheduled_task(const sg4::Host* host)
{
return host->get_data<HostAttribute>()->last_scheduled_task;
}
-static void sg_host_set_last_scheduled_task(const simgrid::s4u::Host* host, simgrid::s4u::ExecPtr task)
+static void sg_host_set_last_scheduled_task(const sg4::Host* host, sg4::ExecPtr task)
{
host->get_data<HostAttribute>()->last_scheduled_task = task.get();
}
-static bool dependency_exists(const simgrid::s4u::Exec* src, simgrid::s4u::Exec* dst)
+static bool dependency_exists(const sg4::Exec* src, sg4::Exec* dst)
{
const auto& dependencies = src->get_dependencies();
const auto& successors = src->get_successors();
dependencies.find(dst) != dependencies.end());
}
-static std::vector<simgrid::s4u::Exec*> get_ready_tasks(const std::vector<simgrid::s4u::ActivityPtr>& dax)
+static std::vector<sg4::Exec*> get_ready_tasks(const std::vector<sg4::ActivityPtr>& dax)
{
- std::vector<simgrid::s4u::Exec*> ready_tasks;
- std::map<simgrid::s4u::Exec*, unsigned int> candidate_execs;
+ std::vector<sg4::Exec*> ready_tasks;
+ std::map<sg4::Exec*, unsigned int> candidate_execs;
for (auto& a : dax) {
// Only loot at activity that have their dependencies solved but are not assigned
if (a->dependencies_solved() && not a->is_assigned()) {
// if it is an exec, it's ready
- auto* exec = dynamic_cast<simgrid::s4u::Exec*>(a.get());
+ auto* exec = dynamic_cast<sg4::Exec*>(a.get());
if (exec != nullptr)
ready_tasks.push_back(exec);
// if it a comm, we consider its successor as a candidate. If a candidate solves all its dependencies,
// i.e., get all its input data, it's ready
- const auto* comm = dynamic_cast<simgrid::s4u::Comm*>(a.get());
+ const auto* comm = dynamic_cast<sg4::Comm*>(a.get());
if (comm != nullptr) {
- auto* next_exec = static_cast<simgrid::s4u::Exec*>(comm->get_successors().front().get());
+ auto* next_exec = static_cast<sg4::Exec*>(comm->get_successors().front().get());
candidate_execs[next_exec]++;
if (next_exec->get_dependencies().size() == candidate_execs[next_exec])
ready_tasks.push_back(next_exec);
return ready_tasks;
}
-static double finish_on_at(const simgrid::s4u::ExecPtr task, const simgrid::s4u::Host* host)
+static double finish_on_at(const sg4::ExecPtr task, const sg4::Host* host)
{
double result;
last_data_available = -1.0;
for (const auto& parent : parents) {
/* normal case */
- const auto* comm = dynamic_cast<simgrid::s4u::Comm*>(parent.get());
+ const auto* comm = dynamic_cast<sg4::Comm*>(parent.get());
if (comm != nullptr) {
auto source = comm->get_source();
XBT_DEBUG("transfer from %s to %s", source->get_cname(), host->get_cname());
data_available = *comm->get_data<double>() + redist_time;
}
- const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(parent.get());
+ const auto* exec = dynamic_cast<sg4::Exec*>(parent.get());
/* no transfer, control dependency */
if (exec != nullptr) {
data_available = exec->get_finish_time();
return result;
}
-static simgrid::s4u::Host* get_best_host(const simgrid::s4u::ExecPtr exec)
+static sg4::Host* get_best_host(const sg4::ExecPtr exec)
{
- std::vector<simgrid::s4u::Host*> hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
+ std::vector<sg4::Host*> hosts = sg4::Engine::get_instance()->get_all_hosts();
auto best_host = hosts.front();
double min_EFT = finish_on_at(exec, best_host);
return best_host;
}
-static void schedule_on(simgrid::s4u::ExecPtr exec, simgrid::s4u::Host* host)
+static void schedule_on(sg4::ExecPtr exec, sg4::Host* host)
{
exec->set_host(host);
// we can also set the destination of all the input comms of this exec
for (const auto& pred : exec->get_dependencies()) {
- auto* comm = dynamic_cast<simgrid::s4u::Comm*>(pred.get());
+ auto* comm = dynamic_cast<sg4::Comm*>(pred.get());
if (comm != nullptr) {
comm->set_destination(host);
delete comm->get_data<double>();
}
// we can also set the source of all the output comms of this exec
for (const auto& succ : exec->get_successors()) {
- auto* comm = dynamic_cast<simgrid::s4u::Comm*>(succ.get());
+ auto* comm = dynamic_cast<sg4::Comm*>(succ.get());
if (comm != nullptr)
comm->set_source(host);
}
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
- std::set<simgrid::s4u::Activity*> vetoed;
+ sg4::Engine e(&argc, argv);
+ std::set<sg4::Activity*> vetoed;
e.track_vetoed_activities(&vetoed);
- simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity const& activity) {
+ sg4::Activity::on_completion_cb([](sg4::Activity const& activity) {
// when an Exec completes, we need to set the potential start time of all its ouput comms
- const auto* exec = dynamic_cast<simgrid::s4u::Exec const*>(&activity);
+ const auto* exec = dynamic_cast<sg4::Exec const*>(&activity);
if (exec == nullptr) // Only Execs are concerned here
return;
for (const auto& succ : exec->get_successors()) {
- auto* comm = dynamic_cast<simgrid::s4u::Comm*>(succ.get());
+ auto* comm = dynamic_cast<sg4::Comm*>(succ.get());
if (comm != nullptr) {
auto* finish_time = new double(exec->get_finish_time());
// We use the user data field to store the finish time of the predecessor of the comm, i.e., its potential start
hosts[i]->set_data(&host_attributes[i]);
/* load the DAX file */
- auto dax = simgrid::s4u::create_DAG_from_DAX(argv[2]);
+ auto dax = sg4::create_DAG_from_DAX(argv[2]);
/* Schedule the root first */
- auto* root = static_cast<simgrid::s4u::Exec*>(dax.front().get());
+ auto* root = static_cast<sg4::Exec*>(dax.front().get());
auto host = get_best_host(root);
schedule_on(root, host);
* select the task that has the minimum completion time on its best host.
*/
double min_finish_time = -1.0;
- simgrid::s4u::Exec* selected_task = nullptr;
- simgrid::s4u::Host* selected_host = nullptr;
+ sg4::Exec* selected_task = nullptr;
+ sg4::Host* selected_host = nullptr;
for (auto task : ready_tasks) {
XBT_DEBUG("%s is ready", task->get_cname());
*/
auto last_scheduled_task = sg_host_get_last_scheduled_task(selected_host);
- if (last_scheduled_task && (last_scheduled_task->get_state() != simgrid::s4u::Activity::State::FINISHED) &&
- (last_scheduled_task->get_state() != simgrid::s4u::Activity::State::FAILED) &&
+ if (last_scheduled_task && (last_scheduled_task->get_state() != sg4::Activity::State::FINISHED) &&
+ (last_scheduled_task->get_state() != sg4::Activity::State::FAILED) &&
not dependency_exists(sg_host_get_last_scheduled_task(selected_host), selected_task))
last_scheduled_task->add_successor(selected_task);
#include <vector>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- std::set<simgrid::s4u::Activity*> vetoed;
+ std::set<sg4::Activity*> vetoed;
e.track_vetoed_activities(&vetoed);
auto fafard = e.host_by_name("Fafard");
// Display the details on vetoed activities
- simgrid::s4u::Activity::on_veto_cb([](const simgrid::s4u::Activity& a) {
- const auto& exec = static_cast<const simgrid::s4u::Exec&>(a); // all activities are execs in this example
+ sg4::Activity::on_veto_cb([](const sg4::Activity& a) {
+ const auto& exec = static_cast<const sg4::Exec&>(a); // all activities are execs in this example
XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
(exec.dependencies_solved() ? "solved" : "NOT solved"),
(exec.is_assigned() ? "assigned" : "NOT assigned"));
});
- simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity const& activity) {
- const auto* exec = dynamic_cast<simgrid::s4u::Exec const*>(&activity);
+ sg4::Activity::on_completion_cb([](sg4::Activity const& activity) {
+ const auto* exec = dynamic_cast<sg4::Exec const*>(&activity);
if (exec == nullptr) // Only Execs are concerned here
return;
XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec->get_cname(), exec->get_start_time(),
double computation_amount = fafard->get_speed();
// Create a small DAG: Two parents and a child
- simgrid::s4u::ExecPtr first_parent = simgrid::s4u::Exec::init();
- simgrid::s4u::ExecPtr second_parent = simgrid::s4u::Exec::init();
- simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init();
+ sg4::ExecPtr first_parent = sg4::Exec::init();
+ sg4::ExecPtr second_parent = sg4::Exec::init();
+ sg4::ExecPtr child = sg4::Exec::init();
first_parent->add_successor(child);
second_parent->add_successor(child);
second_parent->vetoable_start();
child->vetoable_start();
- while (child->get_state() != simgrid::s4u::Activity::State::FINISHED) {
+ while (child->get_state() != sg4::Activity::State::FINISHED) {
e.run();
for (auto* a : vetoed) {
- auto* exec = static_cast<simgrid::s4u::Exec*>(a);
+ auto* exec = static_cast<sg4::Exec*>(a);
// In this simple case, we just assign the child task to a resource when its dependencies are solved
if (exec->dependencies_solved() && not exec->is_assigned()) {
vetoed.clear(); // DON'T FORGET TO CLEAR this set between two calls to run
}
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include "s4u-dht-chord.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(s4u_chord);
+namespace sg4 = simgrid::s4u;
/* Returns whether an id belongs to the interval [start, end].
*
id_ = std::stoi(args[1]);
XBT_DEBUG("Initialize node with id: %d", id_);
random.set_seed(id_);
- mailbox_ = simgrid::s4u::Mailbox::by_name(std::to_string(id_));
+ mailbox_ = sg4::Mailbox::by_name(std::to_string(id_));
next_finger_to_fix = 0;
fingers_.resize(nb_bits, id_);
if (args.size() == 3) { // first ring
deadline_ = std::stod(args[2]);
- start_time_ = simgrid::s4u::Engine::get_clock();
+ start_time_ = sg4::Engine::get_clock();
XBT_DEBUG("Create a new Chord ring...");
} else {
known_id_ = std::stoi(args[2]);
XBT_DEBUG("Sending a 'PREDECESSOR_LEAVING' to my successor %d", fingers_[0]);
try {
- simgrid::s4u::Mailbox::by_name(std::to_string(fingers_[0]))->put(pred_msg, 10, timeout);
+ sg4::Mailbox::by_name(std::to_string(fingers_[0]))->put(pred_msg, 10, timeout);
} catch (const simgrid::TimeoutException&) {
XBT_DEBUG("Timeout expired when sending a 'PREDECESSOR_LEAVING' to my successor %d", fingers_[0]);
delete pred_msg;
XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
try {
- simgrid::s4u::Mailbox::by_name(std::to_string(pred_id_))->put(succ_msg, 10, timeout);
+ sg4::Mailbox::by_name(std::to_string(pred_id_))->put(succ_msg, 10, timeout);
} catch (const simgrid::TimeoutException&) {
XBT_DEBUG("Timeout expired when sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
delete succ_msg;
if (pred_id_ == -1)
return;
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(pred_id_));
- simgrid::s4u::Mailbox* return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_is_alive");
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(pred_id_));
+ sg4::Mailbox* return_mailbox = sg4::Mailbox::by_name(std::to_string(id_) + "_is_alive");
auto* message = new ChordMessage(MessageType::PREDECESSOR_ALIVE);
message->request_id = pred_id_;
XBT_DEBUG("Sent 'Predecessor Alive' request to %d, waiting for the answer on my mailbox '%s'", pred_id_,
message->answer_to->get_cname());
ChordMessage* answer = nullptr;
- simgrid::s4u::CommPtr comm = return_mailbox->get_async<ChordMessage>(&answer);
+ sg4::CommPtr comm = return_mailbox->get_async<ChordMessage>(&answer);
try {
comm->wait_for(timeout);
int Node::remoteGetPredecessor(int ask_to)
{
int predecessor_id = -1;
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(ask_to));
- simgrid::s4u::Mailbox* return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_pred");
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(ask_to));
+ sg4::Mailbox* return_mailbox = sg4::Mailbox::by_name(std::to_string(id_) + "_pred");
auto* message = new ChordMessage(MessageType::GET_PREDECESSOR);
message->request_id = id_;
XBT_DEBUG("Sent 'Get Predecessor' request to %d, waiting for the answer on my mailbox '%s'", ask_to,
message->answer_to->get_cname());
ChordMessage* answer = nullptr;
- simgrid::s4u::CommPtr comm = return_mailbox->get_async<ChordMessage>(&answer);
+ sg4::CommPtr comm = return_mailbox->get_async<ChordMessage>(&answer);
try {
comm->wait_for(timeout);
int Node::remoteFindSuccessor(int ask_to, int id)
{
int successor = -1;
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(ask_to));
- simgrid::s4u::Mailbox* return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_succ");
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(ask_to));
+ sg4::Mailbox* return_mailbox = sg4::Mailbox::by_name(std::to_string(id_) + "_succ");
auto* message = new ChordMessage(MessageType::FIND_SUCCESSOR);
message->request_id = id_;
// receive the answer
XBT_DEBUG("Sent a 'Find Successor' request to %d for key %d, waiting for the answer", ask_to, id);
ChordMessage* answer = nullptr;
- simgrid::s4u::CommPtr comm = return_mailbox->get_async<ChordMessage>(&answer);
+ sg4::CommPtr comm = return_mailbox->get_async<ChordMessage>(&answer);
try {
comm->wait_for(timeout);
// send a "Notify" request to notify_id
XBT_DEBUG("Sending a 'Notify' request to %d", notify_id);
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(notify_id));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(notify_id));
mailbox->put_init(message, 10)->detach(ChordMessage::destroy);
}
int closest = closestPrecedingFinger(message->request_id);
XBT_DEBUG("Forwarding the 'Find Successor' request for id %d to my closest preceding finger %d",
message->request_id, closest);
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(closest));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(closest));
mailbox->put_init(message, 10)->detach(ChordMessage::destroy);
}
break;
void Node::operator()()
{
- simgrid::s4u::this_actor::sleep_for(start_time_);
+ sg4::this_actor::sleep_for(start_time_);
if (known_id_ == -1) {
setPredecessor(-1); // -1 means that I have no predecessor
printFingerTable();
if (not joined)
return;
ChordMessage* message = nullptr;
- double now = simgrid::s4u::Engine::get_clock();
+ double now = sg4::Engine::get_clock();
double next_stabilize_date = start_time_ + PERIODIC_STABILIZE_DELAY;
double next_fix_fingers_date = start_time_ + PERIODIC_FIX_FINGERS_DELAY;
double next_check_predecessor_date = start_time_ + PERIODIC_CHECK_PREDECESSOR_DELAY;
double next_lookup_date = start_time_ + PERIODIC_LOOKUP_DELAY;
- simgrid::s4u::CommPtr comm_receive = nullptr;
+ sg4::CommPtr comm_receive = nullptr;
while (now < std::min(start_time_ + deadline_, MAX_SIMULATION_TIME)) {
if (comm_receive == nullptr)
comm_receive = mailbox_->get_async<ChordMessage>(&message);
// no task was received: make some periodic calls
if (now >= next_stabilize_date) {
stabilize();
- next_stabilize_date = simgrid::s4u::Engine::get_clock() + PERIODIC_STABILIZE_DELAY;
+ next_stabilize_date = sg4::Engine::get_clock() + PERIODIC_STABILIZE_DELAY;
} else if (now >= next_fix_fingers_date) {
fixFingers();
- next_fix_fingers_date = simgrid::s4u::Engine::get_clock() + PERIODIC_FIX_FINGERS_DELAY;
+ next_fix_fingers_date = sg4::Engine::get_clock() + PERIODIC_FIX_FINGERS_DELAY;
} else if (now >= next_check_predecessor_date) {
checkPredecessor();
- next_check_predecessor_date = simgrid::s4u::Engine::get_clock() + PERIODIC_CHECK_PREDECESSOR_DELAY;
+ next_check_predecessor_date = sg4::Engine::get_clock() + PERIODIC_CHECK_PREDECESSOR_DELAY;
} else if (now >= next_lookup_date) {
randomLookup();
- next_lookup_date = simgrid::s4u::Engine::get_clock() + PERIODIC_LOOKUP_DELAY;
+ next_lookup_date = sg4::Engine::get_clock() + PERIODIC_LOOKUP_DELAY;
} else {
// nothing to do: sleep for a while
- simgrid::s4u::this_actor::sleep_for(SLEEP_DELAY);
+ sg4::this_actor::sleep_for(SLEEP_DELAY);
}
}
- now = simgrid::s4u::Engine::get_clock();
+ now = sg4::Engine::get_clock();
}
if (comm_receive != nullptr) {
try {
#include <xbt/random.hpp>
#include <xbt/str.h>
+namespace sg4 = simgrid::s4u;
+
constexpr double MAX_SIMULATION_TIME = 1000;
constexpr double PERIODIC_STABILIZE_DELAY = 20;
constexpr double PERIODIC_FIX_FINGERS_DELAY = 120;
class ChordMessage {
public:
MessageType type; // type of message
- std::string issuer_host_name = simgrid::s4u::this_actor::get_host()->get_name(); // used for logging
+ std::string issuer_host_name = sg4::this_actor::get_host()->get_name(); // used for logging
int request_id = -1; // id (used by some types of messages)
int request_finger = 1; // finger parameter (used by some types of messages)
int answer_id = -1; // answer (used by some types of messages)
- simgrid::s4u::Mailbox* answer_to = nullptr; // mailbox to send an answer to (if any)
+ sg4::Mailbox* answer_to = nullptr; // mailbox to send an answer to (if any)
explicit ChordMessage(MessageType type) : type(type) {}
int id_; // my id
int pred_id_ = -1; // predecessor id
simgrid::xbt::random::XbtRandom random; // random number generator for this node
- simgrid::s4u::Mailbox* mailbox_; // my mailbox
+ sg4::Mailbox* mailbox_; // my mailbox
std::vector<int> fingers_; // finger table,(fingers[0] is my successor)
int next_finger_to_fix; // index of the next finger to fix in fix_fingers()
#include "routing_table.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(kademlia_node, "Messages specific for this example");
+namespace sg4 = simgrid::s4u;
namespace kademlia {
static void destroy(void* message)
/**
* Try to asynchronously get a new message from given mailbox. Return null if none available.
*/
-Message* Node::receive(simgrid::s4u::Mailbox* mailbox)
+Message* Node::receive(sg4::Mailbox* mailbox)
{
if (receive_comm == nullptr)
receive_comm = mailbox->get_async<kademlia::Message>(&received_msg);
/* First step: Send a "FIND_NODE" request to the node we know */
sendFindNode(known_id, id_);
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(id_));
do {
if (Message* msg = receive(mailbox)) {
XBT_DEBUG("Received an answer from the node I know.");
}
delete msg;
} else
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
} while (not got_answer);
/* Second step: Send a FIND_NODE to a random node in buckets */
void Node::sendFindNode(unsigned int id, unsigned int destination) const
{
/* Gets the mailbox to send to */
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(id));
/* Build the task */
- auto* msg = new Message(id_, destination, simgrid::s4u::Mailbox::by_name(std::to_string(id_)),
- simgrid::s4u::Host::current()->get_cname());
+ auto* msg =
+ new Message(id_, destination, sg4::Mailbox::by_name(std::to_string(id_)), sg4::Host::current()->get_cname());
/* Send the task */
mailbox->put_init(msg, 1)->detach(kademlia::destroy);
unsigned int answers;
bool destination_found = false;
unsigned int nodes_added = 0;
- double global_timeout = simgrid::s4u::Engine::get_clock() + FIND_NODE_GLOBAL_TIMEOUT;
+ double global_timeout = sg4::Engine::get_clock() + FIND_NODE_GLOBAL_TIMEOUT;
unsigned int steps = 0;
/* First we build a list of who we already know */
answers = 0;
queries = sendFindNodeToBest(node_list.get());
nodes_added = 0;
- double timeout = simgrid::s4u::Engine::get_clock() + FIND_NODE_TIMEOUT;
+ double timeout = sg4::Engine::get_clock() + FIND_NODE_TIMEOUT;
steps++;
- double time_beginreceive = simgrid::s4u::Engine::get_clock();
+ double time_beginreceive = sg4::Engine::get_clock();
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(id_));
do {
if (Message* msg = receive(mailbox)) {
// Check if what we have received is what we are looking for.
handleFindNode(msg);
}
// Update the timeout if we didn't have our answer
- timeout += simgrid::s4u::Engine::get_clock() - time_beginreceive;
- time_beginreceive = simgrid::s4u::Engine::get_clock();
+ timeout += sg4::Engine::get_clock() - time_beginreceive;
+ time_beginreceive = sg4::Engine::get_clock();
}
delete msg;
} else {
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
}
- } while (simgrid::s4u::Engine::get_clock() < timeout && answers < queries);
+ } while (sg4::Engine::get_clock() < timeout && answers < queries);
destination_found = node_list->destinationFound();
- } while (not destination_found && (nodes_added > 0 || answers == 0) &&
- simgrid::s4u::Engine::get_clock() < global_timeout && steps < MAX_STEPS);
+ } while (not destination_found && (nodes_added > 0 || answers == 0) && sg4::Engine::get_clock() < global_timeout &&
+ steps < MAX_STEPS);
if (destination_found) {
if (count_in_stats)
XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x", msg->answer_to_->get_cname(),
msg->issuer_host_name_.c_str(), msg->destination_id_);
// Building the answer to the request
- auto* answer =
- new Message(id_, msg->destination_id_, findClosest(msg->destination_id_),
- simgrid::s4u::Mailbox::by_name(std::to_string(id_)), simgrid::s4u::Host::current()->get_cname());
+ auto* answer = new Message(id_, msg->destination_id_, findClosest(msg->destination_id_),
+ sg4::Mailbox::by_name(std::to_string(id_)), sg4::Host::current()->get_cname());
// Sending the answer
msg->answer_to_->put_init(answer, 1)->detach(kademlia::destroy);
}
-/* Copyright (c) 2012-2022. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2012-2022. 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"
XBT_LOG_NEW_DEFAULT_CATEGORY(kademlia, "Messages specific for this example");
+namespace sg4 = simgrid::s4u;
/** @brief Node function
* @param my node ID
if (join_success) {
XBT_VERB("Ok, I'm joining the network with id %u", node.getId());
// We start the main loop
- double next_lookup_time = simgrid::s4u::Engine::get_clock() + RANDOM_LOOKUP_INTERVAL;
+ double next_lookup_time = sg4::Engine::get_clock() + RANDOM_LOOKUP_INTERVAL;
XBT_VERB("Main loop start");
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(node.getId()));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(node.getId()));
- while (simgrid::s4u::Engine::get_clock() < deadline) {
+ while (sg4::Engine::get_clock() < deadline) {
if (kademlia::Message* msg = node.receive(mailbox)) {
// There has been a message, we need to handle it !
node.handleFindNode(msg);
delete msg;
} else {
/* We search for a pseudo random node */
- if (simgrid::s4u::Engine::get_clock() >= next_lookup_time) {
+ if (sg4::Engine::get_clock() >= next_lookup_time) {
node.randomLookup();
next_lookup_time += RANDOM_LOOKUP_INTERVAL;
} else {
// Didn't get a message: sleep for a while...
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
}
}
}
/** @brief Main function */
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
/* Check the arguments */
xbt_assert(argc > 2,
e.run();
- XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulated time: %g", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/plugins/energy.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this example");
+namespace sg4 = simgrid::s4u;
-static void simulate_bootup(simgrid::s4u::Host* host)
+static void simulate_bootup(sg4::Host* host)
{
unsigned long previous_pstate = host->get_pstate();
host->turn_on();
XBT_INFO("Wait 150s to simulate the boot time.");
- simgrid::s4u::this_actor::sleep_for(150);
+ sg4::this_actor::sleep_for(150);
XBT_INFO("The host is now up and running. Switch back to previous pstate %lu", previous_pstate);
host->set_pstate(previous_pstate);
}
-static void simulate_shutdown(simgrid::s4u::Host* host)
+static void simulate_shutdown(sg4::Host* host)
{
unsigned long previous_pstate = host->get_pstate();
host->set_pstate(4);
XBT_INFO("Wait 7 seconds to simulate the shutdown time.");
- simgrid::s4u::this_actor::sleep_for(7);
+ sg4::this_actor::sleep_for(7);
XBT_INFO("Switch back to previous pstate %lu, that will be used on reboot.", previous_pstate);
host->set_pstate(previous_pstate);
static void monitor()
{
- simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
+ sg4::Host* host1 = sg4::Host::by_name("MyHost1");
XBT_INFO("Initial pstate: %lu; Energy dissipated so far:%.0E J", host1->get_pstate(),
sg_host_get_consumed_energy(host1));
XBT_INFO("Sleep for 10 seconds");
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
XBT_INFO("Done sleeping. Current pstate: %lu; Energy dissipated so far: %.2f J", host1->get_pstate(),
sg_host_get_consumed_energy(host1));
sg_host_get_consumed_energy(host1));
XBT_INFO("Sleep for 10 seconds");
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
XBT_INFO("Done sleeping. Current pstate: %lu; Energy dissipated so far: %.2f J", host1->get_pstate(),
sg_host_get_consumed_energy(host1));
int main(int argc, char* argv[])
{
sg_host_energy_plugin_init();
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("Boot Monitor", e.host_by_name("MyHost2"), monitor);
+ sg4::Actor::create("Boot Monitor", e.host_by_name("MyHost2"), monitor);
e.run();
#include "simgrid/plugins/energy.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void runner()
{
- simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
- simgrid::s4u::Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
- std::vector<simgrid::s4u::Host*> hosts{host1, host2};
+ sg4::Host* host1 = sg4::Host::by_name("MyHost1");
+ sg4::Host* host2 = sg4::Host::by_name("MyHost2");
+ std::vector<sg4::Host*> hosts{host1, host2};
double old_energy_host1 = sg_host_get_consumed_energy(host1);
double old_energy_host2 = sg_host_get_consumed_energy(host2);
XBT_INFO("[%s] Initial peak speed=%.0E flop/s; Total energy dissipated =%.0E J", host2->get_cname(), host2->get_speed(),
old_energy_host2);
- double start = simgrid::s4u::Engine::get_clock();
+ double start = sg4::Engine::get_clock();
XBT_INFO("Sleep for 10 seconds");
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
double new_energy_host1 = sg_host_get_consumed_energy(host1);
double new_energy_host2 = sg_host_get_consumed_energy(host2);
XBT_INFO("Done sleeping (duration: %.2f s).\n"
"[%s] Current peak speed=%.0E; Energy dissipated during this step=%.2f J; Total energy dissipated=%.2f J\n"
"[%s] Current peak speed=%.0E; Energy dissipated during this step=%.2f J; Total energy dissipated=%.2f J\n",
- simgrid::s4u::Engine::get_clock() - start,
- host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1), sg_host_get_consumed_energy(host1),
- host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2), sg_host_get_consumed_energy(host2));
+ sg4::Engine::get_clock() - start, host1->get_cname(), host1->get_speed(),
+ (new_energy_host1 - old_energy_host1), sg_host_get_consumed_energy(host1), host2->get_cname(),
+ host2->get_speed(), (new_energy_host2 - old_energy_host2), sg_host_get_consumed_energy(host2));
old_energy_host1 = new_energy_host1;
old_energy_host2 = new_energy_host2;
// ========= Execute something =========
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
double flopAmount = 1E9;
std::vector<double> cpu_amounts{flopAmount, flopAmount};
std::vector<double> com_amounts{0, 0, 0, 0};
XBT_INFO("Run a task of %.0E flops on two hosts", flopAmount);
- simgrid::s4u::this_actor::parallel_execute(hosts, cpu_amounts, com_amounts);
+ sg4::this_actor::parallel_execute(hosts, cpu_amounts, com_amounts);
new_energy_host1 = sg_host_get_consumed_energy(host1);
new_energy_host2 = sg_host_get_consumed_energy(host2);
- XBT_INFO("Task done (duration: %.2f s).\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n",
- simgrid::s4u::Engine::get_clock() - start,
- host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1), sg_host_get_consumed_energy(host1),
- host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2), sg_host_get_consumed_energy(host2));
+ XBT_INFO(
+ "Task done (duration: %.2f s).\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f "
+ "J\n",
+ sg4::Engine::get_clock() - start, host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1),
+ sg_host_get_consumed_energy(host1), host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2),
+ sg_host_get_consumed_energy(host2));
old_energy_host1 = new_energy_host1;
old_energy_host2 = new_energy_host2;
// ========= Run another ptask =========
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
std::vector<double> cpu_amounts2{flopAmount, flopAmount};
std::vector<double> com_amounts2{0, 0, 0, 0};
XBT_INFO("Run a task of %.0E flops on %s and %.0E flops on %s.", flopAmount, host1->get_cname(), flopAmount, host2->get_cname());
- simgrid::s4u::this_actor::parallel_execute(hosts, cpu_amounts2, com_amounts2);
+ sg4::this_actor::parallel_execute(hosts, cpu_amounts2, com_amounts2);
new_energy_host1 = sg_host_get_consumed_energy(host1);
new_energy_host2 = sg_host_get_consumed_energy(host2);
- XBT_INFO("Task done (duration: %.2f s).\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n",
- simgrid::s4u::Engine::get_clock() - start,
- host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1), sg_host_get_consumed_energy(host1),
- host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2), sg_host_get_consumed_energy(host2));
+ XBT_INFO(
+ "Task done (duration: %.2f s).\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f "
+ "J\n",
+ sg4::Engine::get_clock() - start, host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1),
+ sg_host_get_consumed_energy(host1), host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2),
+ sg_host_get_consumed_energy(host2));
old_energy_host1 = new_energy_host1;
old_energy_host2 = new_energy_host2;
// ========= A new ptask with computation and communication =========
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
double comAmount = 1E7;
std::vector<double> cpu_amounts3{flopAmount, flopAmount};
std::vector<double> com_amounts3{0, comAmount, comAmount, 0};
XBT_INFO("Run a task with computation and communication on two hosts.");
- simgrid::s4u::this_actor::parallel_execute(hosts, cpu_amounts3, com_amounts3);
+ sg4::this_actor::parallel_execute(hosts, cpu_amounts3, com_amounts3);
new_energy_host1 = sg_host_get_consumed_energy(host1);
new_energy_host2 = sg_host_get_consumed_energy(host2);
- XBT_INFO("Task done (duration: %.2f s).\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n",
- simgrid::s4u::Engine::get_clock() - start,
- host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1), sg_host_get_consumed_energy(host1),
- host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2), sg_host_get_consumed_energy(host2));
+ XBT_INFO(
+ "Task done (duration: %.2f s).\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f "
+ "J\n",
+ sg4::Engine::get_clock() - start, host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1),
+ sg_host_get_consumed_energy(host1), host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2),
+ sg_host_get_consumed_energy(host2));
old_energy_host1 = new_energy_host1;
old_energy_host2 = new_energy_host2;
// ========= A new ptask with communication only =========
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
std::vector<double> cpu_amounts4{0, 0};
std::vector<double> com_amounts4{0, comAmount, comAmount, 0};
XBT_INFO("Run a task with only communication on two hosts.");
- simgrid::s4u::this_actor::parallel_execute(hosts, cpu_amounts4, com_amounts4);
+ sg4::this_actor::parallel_execute(hosts, cpu_amounts4, com_amounts4);
new_energy_host1 = sg_host_get_consumed_energy(host1);
new_energy_host2 = sg_host_get_consumed_energy(host2);
- XBT_INFO("Task done (duration: %.2f s).\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n",
- simgrid::s4u::Engine::get_clock() - start,
- host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1), sg_host_get_consumed_energy(host1),
- host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2), sg_host_get_consumed_energy(host2));
+ XBT_INFO(
+ "Task done (duration: %.2f s).\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f "
+ "J\n",
+ sg4::Engine::get_clock() - start, host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1),
+ sg_host_get_consumed_energy(host1), host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2),
+ sg_host_get_consumed_energy(host2));
old_energy_host1 = new_energy_host1;
old_energy_host2 = new_energy_host2;
// ========= A new ptask with computation and a timeout =========
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
std::vector<double> cpu_amounts5{flopAmount, flopAmount};
std::vector<double> com_amounts5{0, 0, 0, 0};
XBT_INFO("Run a task with computation on two hosts and a timeout of 20s.");
try {
- simgrid::s4u::this_actor::exec_init(hosts, cpu_amounts5, com_amounts5)->wait_for(20);
+ sg4::this_actor::exec_init(hosts, cpu_amounts5, com_amounts5)->wait_for(20);
} catch (const simgrid::TimeoutException &){
XBT_INFO("Finished WITH timeout");
}
new_energy_host1 = sg_host_get_consumed_energy(host1);
new_energy_host2 = sg_host_get_consumed_energy(host2);
- XBT_INFO("Task ended (duration: %.2f s).\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
- "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n",
- simgrid::s4u::Engine::get_clock() - start,
- host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1), sg_host_get_consumed_energy(host1),
- host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2), sg_host_get_consumed_energy(host2));
+ XBT_INFO(
+ "Task ended (duration: %.2f s).\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f J\n"
+ "[%s] Current peak speed=%.0E flop/s; Energy dissipated during this step=%.2f J; Total energy dissipated=%.0f "
+ "J\n",
+ sg4::Engine::get_clock() - start, host1->get_cname(), host1->get_speed(), (new_energy_host1 - old_energy_host1),
+ sg_host_get_consumed_energy(host1), host2->get_cname(), host2->get_speed(), (new_energy_host2 - old_energy_host2),
+ sg_host_get_consumed_energy(host2));
XBT_INFO("Now is time to quit!");
}
int main(int argc, char* argv[])
{
sg_host_energy_plugin_init();
- simgrid::s4u::Engine e(&argc, argv);
- simgrid::s4u::Engine::set_config("host/model:ptask_L07");
+ sg4::Engine e(&argc, argv);
+ sg4::Engine::set_config("host/model:ptask_L07");
xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("energy_ptask_test", e.host_by_name("MyHost1"), runner);
+ sg4::Actor::create("energy_ptask_test", e.host_by_name("MyHost1"), runner);
e.run();
XBT_INFO("End of simulation.");
#include "simgrid/plugins/energy.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void dvfs()
{
- simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
- simgrid::s4u::Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
+ sg4::Host* host1 = sg4::Host::by_name("MyHost1");
+ sg4::Host* host2 = sg4::Host::by_name("MyHost2");
XBT_INFO("Energetic profile: %s", host1->get_property("wattage_per_state"));
XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", host1->get_speed(),
sg_host_get_consumed_energy(host1));
- double start = simgrid::s4u::Engine::get_clock();
+ double start = sg4::Engine::get_clock();
XBT_INFO("Sleep for 10 seconds");
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J",
- simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
+ sg4::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
// Execute something
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
double flopAmount = 100E6;
XBT_INFO("Run a computation of %.0E flops", flopAmount);
- simgrid::s4u::this_actor::execute(flopAmount);
+ sg4::this_actor::execute(flopAmount);
XBT_INFO(
"Computation done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW"
" depending on load; Energy dissipated=%.0f J",
- simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_wattmin_at(host1, host1->get_pstate()),
+ sg4::Engine::get_clock() - start, host1->get_speed(), sg_host_get_wattmin_at(host1, host1->get_pstate()),
sg_host_get_wattmax_at(host1, host1->get_pstate()), sg_host_get_consumed_energy(host1));
// ========= Change power peak =========
host1->get_pstate_speed(pstate), host1->get_speed());
// Run another computation
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
XBT_INFO("Run a computation of %.0E flops", flopAmount);
- simgrid::s4u::this_actor::execute(flopAmount);
+ sg4::this_actor::execute(flopAmount);
XBT_INFO("Computation done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
+ sg4::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
XBT_INFO("Sleep for 4 seconds");
- simgrid::s4u::this_actor::sleep_for(4);
+ sg4::this_actor::sleep_for(4);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
+ sg4::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
// =========== Turn the other host off ==========
XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.",
sg_host_get_consumed_energy(host2));
host2->turn_off();
- start = simgrid::s4u::Engine::get_clock();
- simgrid::s4u::this_actor::sleep_for(10);
+ start = sg4::Engine::get_clock();
+ sg4::this_actor::sleep_for(10);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
+ sg4::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
}
int main(int argc, char* argv[])
{
sg_host_energy_plugin_init();
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("dvfs_test", e.host_by_name("MyHost1"), dvfs);
+ sg4::Actor::create("dvfs_test", e.host_by_name("MyHost1"), dvfs);
e.run();
static const int max_size = 1e9;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_energyconsumption, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void sender(std::vector<std::string> args)
{
long comm_size = std::stol(args.at(1));
XBT_INFO("Send %ld bytes, in %d flows", comm_size, flow_amount);
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::string("message"));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::string("message"));
/* Sleep a while before starting the example */
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
if (flow_amount == 1) {
/* - Send the task to the @ref worker */
mailbox->put(payload, comm_size);
} else {
// Start all comms in parallel, and wait for all completions in one shot
- std::vector<simgrid::s4u::CommPtr> comms;
+ std::vector<sg4::CommPtr> comms;
for (int i = 0; i < flow_amount; i++)
comms.push_back(mailbox->put_async(bprintf("%d", i), comm_size));
- simgrid::s4u::Comm::wait_all(comms);
+ sg4::Comm::wait_all(comms);
}
XBT_INFO("sender done.");
}
XBT_INFO("Receiving %d flows ...", flow_amount);
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::string("message"));
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::string("message"));
if (flow_amount == 1) {
char* res = mailbox->get<char>();
std::vector<char*> data(flow_amount);
// Start all comms in parallel, and wait for their completion in one shot
- std::vector<simgrid::s4u::CommPtr> comms;
+ std::vector<sg4::CommPtr> comms;
for (int i = 0; i < flow_amount; i++)
comms.push_back(mailbox->get_async<char>(&data[i]));
- simgrid::s4u::Comm::wait_all(comms);
+ sg4::Comm::wait_all(comms);
for (int i = 0; i < flow_amount; i++)
xbt_free(data[i]);
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
XBT_INFO("Activating the SimGrid link energy plugin");
sg_link_energy_plugin_init();
} else { // No parameter at all? Then use the default value
argSender.emplace_back("25000");
}
- simgrid::s4u::Actor::create("sender", e.host_by_name("MyHost1"), sender, argSender);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("MyHost2"), receiver, argReceiver);
+ sg4::Actor::create("sender", e.host_by_name("MyHost1"), sender, argSender);
+ sg4::Actor::create("receiver", e.host_by_name("MyHost2"), receiver, argReceiver);
/* And now, launch the simulation */
e.run();
#include "simgrid/s4u/VirtualMachine.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(energy_vm, "Messages of this example");
+namespace sg4 = simgrid::s4u;
static void executor()
{
- simgrid::s4u::this_actor::execute(300E6);
+ sg4::this_actor::execute(300E6);
XBT_INFO("This worker is done.");
}
static void dvfs()
{
- simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
- simgrid::s4u::Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
- simgrid::s4u::Host* host3 = simgrid::s4u::Host::by_name("MyHost3");
+ sg4::Host* host1 = sg4::Host::by_name("MyHost1");
+ sg4::Host* host2 = sg4::Host::by_name("MyHost2");
+ sg4::Host* host3 = sg4::Host::by_name("MyHost3");
/* Host 1 */
XBT_INFO("Creating and starting two VMs");
vm_host2->start();
XBT_INFO("Create two activities on Host1: both inside a VM");
- simgrid::s4u::Actor::create("p11", vm_host1, executor);
- simgrid::s4u::Actor::create("p12", vm_host1, executor);
+ sg4::Actor::create("p11", vm_host1, executor);
+ sg4::Actor::create("p12", vm_host1, executor);
XBT_INFO("Create two activities on Host2: one inside a VM, the other directly on the host");
- simgrid::s4u::Actor::create("p21", vm_host2, executor);
- simgrid::s4u::Actor::create("p22", host2, executor);
+ sg4::Actor::create("p21", vm_host2, executor);
+ sg4::Actor::create("p22", host2, executor);
XBT_INFO("Create two activities on Host3: both directly on the host");
- simgrid::s4u::Actor::create("p31", host3, executor);
- simgrid::s4u::Actor::create("p32", host3, executor);
+ sg4::Actor::create("p31", host3, executor);
+ sg4::Actor::create("p32", host3, executor);
XBT_INFO("Wait 5 seconds. The activities are still running (they run for 3 seconds, but 2 activities are co-located, "
"so they run for 6 seconds)");
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
XBT_INFO("Wait another 5 seconds. The activities stop at some point in between");
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
vm_host1->destroy();
vm_host2->destroy();
int main(int argc, char* argv[])
{
sg_host_energy_plugin_init();
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("dvfs", e.host_by_name("MyHost1"), dvfs);
+ sg4::Actor::create("dvfs", e.host_by_name("MyHost1"), dvfs);
e.run();
XBT_INFO("Total simulation time: %.2f; Host2 and Host3 must have the exact same energy consumption; Host1 is "
"multi-core and will differ.",
- simgrid::s4u::Engine::get_clock());
+ sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u/Mailbox.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(test_wifi, "Wifi energy demo");
+namespace sg4 = simgrid::s4u;
static void sender()
{
// start sending after 5 seconds
- simgrid::s4u::this_actor::sleep_until(5);
+ sg4::this_actor::sleep_until(5);
std::string mbName = "MailBoxRCV";
- simgrid::s4u::Mailbox *dst = simgrid::s4u::Mailbox::by_name(mbName);
+ sg4::Mailbox* dst = sg4::Mailbox::by_name(mbName);
int size = 6750000;
{
std::string mbName = "MailBoxRCV";
XBT_INFO("RECEIVING on mb %s", mbName.c_str());
- simgrid::s4u::Mailbox *myBox = simgrid::s4u::Mailbox::by_name(mbName);
+ sg4::Mailbox* myBox = sg4::Mailbox::by_name(mbName);
myBox->get<std::string>();
XBT_INFO("received all messages");
int main(int argc, char** argv)
{
- simgrid::s4u::Engine engine(&argc, argv);
+ sg4::Engine engine(&argc, argv);
sg_wifi_energy_plugin_init();
engine.load_platform(argv[1]);
l->set_host_wifi_rate(engine.host_by_name("Station 2"), 0);
// create the two actors for the test
- simgrid::s4u::Actor::create("act0", engine.host_by_name("Station 1"), sender);
- simgrid::s4u::Actor::create("act1", engine.host_by_name("Station 2"), receiver);
+ sg4::Actor::create("act0", engine.host_by_name("Station 1"), sender);
+ sg4::Actor::create("act1", engine.host_by_name("Station 2"), receiver);
engine.run();
#include <simgrid/s4u.hpp>
-/* This example shows how to use simgrid::s4u::Engine::get_filtered_hosts() to retrieve
+/* This example shows how to use sg4::Engine::get_filtered_hosts() to retrieve
* all hosts that match a given criteria. This criteria can be specified either with:
* - an inlined callback
* - a boolean function, such as filter_speed_more_than_50Mf() below
*/
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_engine_filtering, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
namespace filter {
/* First example of thing that we can use as a filtering criteria: a simple boolean function */
-static bool filter_speed_more_than_50Mf(const simgrid::s4u::Host* host)
+static bool filter_speed_more_than_50Mf(const sg4::Host* host)
{
return host->get_speed() > 50E6;
}
*/
class SingleCore {
public:
- bool operator()(const simgrid::s4u::Host* host) const { return host->get_core_count() == 1; }
+ bool operator()(const sg4::Host* host) const { return host->get_core_count() == 1; }
};
/* This functor is a bit more complex, as it saves the current state when created.
* Then, it allows one to easily retrieve the hosts which frequency changed since the functor creation.
*/
class FrequencyChanged {
- std::map<simgrid::s4u::Host*, unsigned long> host_list;
+ std::map<sg4::Host*, unsigned long> host_list;
public:
- explicit FrequencyChanged(const simgrid::s4u::Engine& e)
+ explicit FrequencyChanged(const sg4::Engine& e)
{
- std::vector<simgrid::s4u::Host*> list = e.get_all_hosts();
+ std::vector<sg4::Host*> list = e.get_all_hosts();
for (auto& host : list) {
host_list.insert({host, host->get_pstate()});
}
}
- bool operator()(simgrid::s4u::Host* host) { return host->get_pstate() != host_list.at(host); }
+ bool operator()(sg4::Host* host) { return host->get_pstate() != host_list.at(host); }
- unsigned long get_old_speed_state(simgrid::s4u::Host* host) { return host_list.at(host); }
+ unsigned long get_old_speed_state(sg4::Host* host) { return host_list.at(host); }
};
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
/* Use a lambda function to filter hosts: We only want multicore hosts */
XBT_INFO("Hosts currently registered with this engine: %zu", e.get_host_count());
- std::vector<simgrid::s4u::Host*> list =
- e.get_filtered_hosts([](const simgrid::s4u::Host* host) { return host->get_core_count() > 1; });
+ std::vector<sg4::Host*> list = e.get_filtered_hosts([](const sg4::Host* host) { return host->get_core_count() > 1; });
for (auto& host : list)
XBT_INFO("The following hosts have more than one core: %s", host->get_cname());
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
/* This actor simply executes and waits the activity it got as a parameter. */
-static void runner(simgrid::s4u::ExecPtr activity)
+static void runner(sg4::ExecPtr activity)
{
activity->start();
activity->wait();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Host* fafard = e.host_by_name("Fafard");
+ sg4::Host* fafard = e.host_by_name("Fafard");
- simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_init(fafard->get_speed() * 10.)->set_host(fafard);
- simgrid::s4u::Actor::create("runner", fafard, runner, activity);
+ sg4::ExecPtr activity = sg4::this_actor::exec_init(fafard->get_speed() * 10.)->set_host(fafard);
+ sg4::Actor::create("runner", fafard, runner, activity);
while (activity->get_remaining() > 0) {
XBT_INFO("Remaining amount of flops: %g (%.0f%%)", activity->get_remaining(),
100 * activity->get_remaining_ratio());
- e.run_until(simgrid::s4u::Engine::get_clock() + 1);
+ e.run_until(sg4::Engine::get_clock() + 1);
}
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
/* This actor simply waits for its activity completion after starting it.
* That's exactly equivalent to synchronous execution. */
static void waiter()
{
- double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+ double computation_amount = sg4::this_actor::get_host()->get_speed();
XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
- simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_init(computation_amount);
+ sg4::ExecPtr activity = sg4::this_actor::exec_init(computation_amount);
activity->start();
activity->wait();
/* This actor tests the ongoing execution until its completion, and don't wait before it's terminated. */
static void monitor()
{
- double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+ double computation_amount = sg4::this_actor::get_host()->get_speed();
XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
- simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_init(computation_amount);
+ sg4::ExecPtr activity = sg4::this_actor::exec_init(computation_amount);
activity->start();
while (not activity->test()) {
XBT_INFO("Remaining amount of flops: %g (%.0f%%)", activity->get_remaining(),
100 * activity->get_remaining_ratio());
- simgrid::s4u::this_actor::sleep_for(0.3);
+ sg4::this_actor::sleep_for(0.3);
}
XBT_INFO("Goodbye now!");
/* This actor cancels the ongoing execution after a while. */
static void canceller()
{
- double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+ double computation_amount = sg4::this_actor::get_host()->get_speed();
XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
- simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_async(computation_amount);
- simgrid::s4u::this_actor::sleep_for(0.5);
+ sg4::ExecPtr activity = sg4::this_actor::exec_async(computation_amount);
+ sg4::this_actor::sleep_for(0.5);
XBT_INFO("I changed my mind, cancel!");
activity->cancel();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Host* fafard = e.host_by_name("Fafard");
- simgrid::s4u::Host* ginette = e.host_by_name("Ginette");
- simgrid::s4u::Host* boivin = e.host_by_name("Boivin");
+ sg4::Host* fafard = e.host_by_name("Fafard");
+ sg4::Host* ginette = e.host_by_name("Ginette");
+ sg4::Host* boivin = e.host_by_name("Boivin");
- simgrid::s4u::Actor::create("wait", fafard, waiter);
- simgrid::s4u::Actor::create("monitor", ginette, monitor);
- simgrid::s4u::Actor::create("cancel", boivin, canceller);
+ sg4::Actor::create("wait", fafard, waiter);
+ sg4::Actor::create("monitor", ginette, monitor);
+ sg4::Actor::create("cancel", boivin, canceller);
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void executor()
{
/* this_actor::execute() tells SimGrid to pause the calling actor
* until its host has computed the amount of flops passed as a parameter */
- simgrid::s4u::this_actor::execute(98095);
+ sg4::this_actor::execute(98095);
XBT_INFO("Done.");
/* This simple example does not do anything beyond that */
* Since the priority is 2, it computes twice as fast as a regular one.
*
* So instead of a half/half sharing between the two executions, we get a 1/3 vs 2/3 sharing. */
- simgrid::s4u::this_actor::execute(98095, 2);
+ sg4::this_actor::execute(98095, 2);
XBT_INFO("Done.");
/* Note that the timings printed when running this example are a bit misleading, because the uneven sharing only last
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("executor", e.host_by_name("Tremblay"), executor);
- simgrid::s4u::Actor::create("privileged", e.host_by_name("Tremblay"), privileged);
+ sg4::Actor::create("executor", e.host_by_name("Tremblay"), executor);
+ sg4::Actor::create("privileged", e.host_by_name("Tremblay"), privileged);
e.run();
#include <vector>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void worker()
{
// Define an amount of work that should take 1 second to execute.
- double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+ double computation_amount = sg4::this_actor::get_host()->get_speed();
- std::vector<simgrid::s4u::ExecPtr> pending_execs;
+ std::vector<sg4::ExecPtr> pending_execs;
// Create a small DAG
// + Two parents and a child
// + First parent ends after 1 second and the Second parent after 2 seconds.
- simgrid::s4u::ExecPtr first_parent = simgrid::s4u::this_actor::exec_init(computation_amount);
+ sg4::ExecPtr first_parent = sg4::this_actor::exec_init(computation_amount);
pending_execs.push_back(first_parent);
- simgrid::s4u::ExecPtr second_parent = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
+ sg4::ExecPtr second_parent = sg4::this_actor::exec_init(2 * computation_amount);
pending_execs.push_back(second_parent);
- simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init()->set_flops_amount(computation_amount);
+ sg4::ExecPtr child = sg4::Exec::init()->set_flops_amount(computation_amount);
pending_execs.push_back(child);
// Name the activities (for logging purposes only)
// wait for the completion of all activities
while (not pending_execs.empty()) {
- ssize_t changed_pos = simgrid::s4u::Exec::wait_any_for(pending_execs, -1);
+ ssize_t changed_pos = sg4::Exec::wait_any_for(pending_execs, -1);
XBT_INFO("Exec '%s' is complete", pending_execs[changed_pos]->get_cname());
pending_execs.erase(pending_execs.begin() + changed_pos);
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Fafard"), worker);
+ sg4::Actor::create("worker", e.host_by_name("Fafard"), worker);
- simgrid::s4u::Activity::on_veto_cb([&e](simgrid::s4u::Activity& a) {
- auto& exec = static_cast<simgrid::s4u::Exec&>(a);
+ sg4::Activity::on_veto_cb([&e](sg4::Activity& a) {
+ auto& exec = static_cast<sg4::Exec&>(a);
// First display the situation
XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Pstate properties test");
+namespace sg4 = simgrid::s4u;
static int dvfs()
{
double workload = 100E6;
- simgrid::s4u::Host* host = simgrid::s4u::this_actor::get_host();
+ sg4::Host* host = sg4::this_actor::get_host();
unsigned long nb = host->get_pstate_count();
XBT_INFO("Count of Processor states=%lu", nb);
XBT_INFO("Current power peak=%f", host->get_speed());
// Run a Computation
- simgrid::s4u::this_actor::execute(workload);
+ sg4::this_actor::execute(workload);
- double exec_time = simgrid::s4u::Engine::get_clock();
+ double exec_time = sg4::Engine::get_clock();
XBT_INFO("Computation1 duration: %.2f", exec_time);
// Change power peak
XBT_INFO("Current power peak=%f", host->get_speed());
// Run a second Computation
- simgrid::s4u::this_actor::execute(workload);
+ sg4::this_actor::execute(workload);
- exec_time = simgrid::s4u::Engine::get_clock() - exec_time;
+ exec_time = sg4::Engine::get_clock() - exec_time;
XBT_INFO("Computation2 duration: %.2f", exec_time);
// Verify that the default pstate is set to 0
- host = simgrid::s4u::Host::by_name_or_null("MyHost2");
+ host = sg4::Host::by_name_or_null("MyHost2");
XBT_INFO("Count of Processor states=%lu", host->get_pstate_count());
XBT_INFO("Current power peak=%f", host->get_speed());
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("dvfs_test", e.host_by_name("MyHost1"), dvfs);
- simgrid::s4u::Actor::create("dvfs_test", e.host_by_name("MyHost2"), dvfs);
+ sg4::Actor::create("dvfs_test", e.host_by_name("MyHost1"), dvfs);
+ sg4::Actor::create("dvfs_test", e.host_by_name("MyHost2"), dvfs);
e.run();
- XBT_INFO("Total simulation time: %e", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Total simulation time: %e", sg4::Engine::get_clock());
return 0;
}
}
pending_execs.pop_back();
XBT_INFO("Wait for remaining exec, just to be nice");
- simgrid::s4u::Exec::wait_any(pending_execs);
+ sg4::Exec::wait_any(pending_execs);
XBT_INFO("Dispatcher ends");
}
#include <simgrid/s4u.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_ptask_multicore, "Messages specific for this s4u example");
-
namespace sg4 = simgrid::s4u;
static void runner()
// Add a background task and change ptask on the fly
auto MyHost1 = e->host_by_name("MyHost1");
- simgrid::s4u::ExecPtr background_task = MyHost1->exec_async(5e9);
+ sg4::ExecPtr background_task = MyHost1->exec_async(5e9);
XBT_INFO("Start a 1-core background task on the 4-core host.");
start_time = sg4::Engine::get_clock();
#include <simgrid/s4u.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_ptask, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void runner()
{
/* Retrieve the list of all hosts as an array of hosts */
- auto hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
+ auto hosts = sg4::Engine::get_instance()->get_all_hosts();
size_t hosts_count = hosts.size();
std::vector<double> computation_amounts;
for (size_t j = i + 1; j < hosts_count; j++)
communication_amounts[i * hosts_count + j] = 1e7; // 10 MB
- simgrid::s4u::this_actor::parallel_execute(hosts, computation_amounts, communication_amounts);
+ sg4::this_actor::parallel_execute(hosts, computation_amounts, communication_amounts);
/* ------[ test 2 ]----------------- */
XBT_INFO("We can do the same with a timeout of 10 seconds enabled.");
for (size_t j = i + 1; j < hosts_count; j++)
communication_amounts[i * hosts_count + j] = 1e7; // 10 MB
- simgrid::s4u::ExecPtr activity =
- simgrid::s4u::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
+ sg4::ExecPtr activity = sg4::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
try {
activity->wait_for(10.0 /* timeout (in seconds)*/);
xbt_die("Woops, this did not timeout as expected... Please report that bug.");
XBT_INFO("Then, build a parallel activity involving only computations (of different amounts) and no communication");
computation_amounts = {3e8, 6e8, 1e9}; // 300Mflop, 600Mflop, 1Gflop
communication_amounts.clear(); // no comm
- simgrid::s4u::this_actor::parallel_execute(hosts, computation_amounts, communication_amounts);
+ sg4::this_actor::parallel_execute(hosts, computation_amounts, communication_amounts);
/* ------[ test 4 ]----------------- */
XBT_INFO("Then, build a parallel activity with no computation nor communication (synchro only)");
computation_amounts.clear();
communication_amounts.clear();
- simgrid::s4u::this_actor::parallel_execute(hosts, computation_amounts, communication_amounts);
+ sg4::this_actor::parallel_execute(hosts, computation_amounts, communication_amounts);
/* ------[ test 5 ]----------------- */
XBT_INFO("Then, Monitor the execution of a parallel activity");
computation_amounts.assign(hosts_count, 1e6 /*1Mflop*/);
communication_amounts = {0, 1e6, 0, 0, 0, 1e6, 1e6, 0, 0};
- activity = simgrid::s4u::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
+ activity = sg4::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
activity->start();
while (not activity->test()) {
XBT_INFO("Remaining flop ratio: %.0f%%", 100 * activity->get_remaining_ratio());
- simgrid::s4u::this_actor::sleep_for(5);
+ sg4::this_actor::sleep_for(5);
}
activity->wait();
XBT_INFO(" - Start a regular parallel execution, with both comm and computation");
computation_amounts.assign(hosts_count, 1e6 /*1Mflop*/);
communication_amounts = {0, 1e6, 0, 0, 1e6, 0, 1e6, 0, 0};
- activity = simgrid::s4u::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
+ activity = sg4::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
activity->start();
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
double remaining_ratio = activity->get_remaining_ratio();
XBT_INFO(" - After 10 seconds, %.2f%% remains to be done. Change it from 3 hosts to 2 hosts only.",
remaining_ratio * 100);
XBT_INFO(" - Now, simulate the reconfiguration (modeled as a comm from the removed host to the remaining ones).");
std::vector<double> rescheduling_comp{0, 0, 0};
std::vector<double> rescheduling_comm{0, 0, 0, 0, 0, 0, 25000, 25000, 0};
- simgrid::s4u::this_actor::parallel_execute(hosts, rescheduling_comp, rescheduling_comm);
+ sg4::this_actor::parallel_execute(hosts, rescheduling_comp, rescheduling_comm);
XBT_INFO(" - Now, let's cancel the old task and create a new task with modified comm and computation vectors:");
XBT_INFO(" What was already done is removed, and the load of the removed host is shared between remaining ones.");
communication_amounts = {0, remaining_comm, remaining_comm, 0}; // Resizing a linearized matrix is hairly
activity->cancel();
- activity = simgrid::s4u::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
+ activity = sg4::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
XBT_INFO(" - Done, let's wait for the task completion");
activity->wait();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc == 2, "Usage: %s <platform file>", argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("test", e.host_by_name("MyHost1"), runner);
+ sg4::Actor::create("test", e.host_by_name("MyHost1"), runner);
e.run();
XBT_INFO("Simulation done.");
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void wizard()
{
- const simgrid::s4u::Host* fafard = simgrid::s4u::Host::by_name("Fafard");
- simgrid::s4u::Host* ginette = simgrid::s4u::Host::by_name("Ginette");
- simgrid::s4u::Host* boivin = simgrid::s4u::Host::by_name("Boivin");
+ const sg4::Host* fafard = sg4::Host::by_name("Fafard");
+ sg4::Host* ginette = sg4::Host::by_name("Ginette");
+ sg4::Host* boivin = sg4::Host::by_name("Boivin");
XBT_INFO("I'm a wizard! I can run an activity on the Ginette host from the Fafard one! Look!");
- simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(48.492e6);
+ sg4::ExecPtr exec = sg4::this_actor::exec_init(48.492e6);
exec->set_host(ginette);
exec->start();
XBT_INFO("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard).");
- simgrid::s4u::this_actor::sleep_for(0.1);
+ sg4::this_actor::sleep_for(0.1);
XBT_INFO("Loads in flops/s: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", boivin->get_load(), fafard->get_load(),
ginette->get_load());
XBT_INFO("Done!");
XBT_INFO("And now, harder. Start a remote activity on Ginette and move it to Boivin after 0.5 sec");
- exec = simgrid::s4u::this_actor::exec_init(73293500)->set_host(ginette);
+ exec = sg4::this_actor::exec_init(73293500)->set_host(ginette);
exec->start();
- simgrid::s4u::this_actor::sleep_for(0.5);
+ sg4::this_actor::sleep_for(0.5);
XBT_INFO("Loads before the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", boivin->get_load(), fafard->get_load(),
ginette->get_load());
exec->set_host(boivin);
- simgrid::s4u::this_actor::sleep_for(0.1);
+ sg4::this_actor::sleep_for(0.1);
XBT_INFO("Loads after the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", boivin->get_load(), fafard->get_load(),
ginette->get_load());
XBT_INFO("Done!");
XBT_INFO("And now, even harder. Start a remote activity on Ginette and turn off the host after 0.5 sec");
- exec = simgrid::s4u::this_actor::exec_init(48.492e6)->set_host(ginette);
+ exec = sg4::this_actor::exec_init(48.492e6)->set_host(ginette);
exec->start();
- simgrid::s4u::this_actor::sleep_for(0.5);
+ sg4::this_actor::sleep_for(0.5);
ginette->turn_off();
try {
exec->wait();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("test", e.host_by_name("Fafard"), wizard);
+ sg4::Actor::create("test", e.host_by_name("Fafard"), wizard);
e.run();
#include <vector>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void worker()
{
// Define an amount of work that should take 1 second to execute.
- double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+ double computation_amount = sg4::this_actor::get_host()->get_speed();
// Create an unassigned activity and start it
- simgrid::s4u::ExecPtr exec =
- simgrid::s4u::Exec::init()->set_flops_amount(computation_amount)->set_name("exec")->vetoable_start();
+ sg4::ExecPtr exec = sg4::Exec::init()->set_flops_amount(computation_amount)->set_name("exec")->vetoable_start();
// Wait for a while
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
// Assign the activity to the current host. This triggers its start, then waits for it completion.
- exec->set_host(simgrid::s4u::Host::current())->wait();
+ exec->set_host(sg4::Host::current())->wait();
XBT_INFO("Exec '%s' is complete", exec->get_cname());
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Fafard"), worker);
+ sg4::Actor::create("worker", e.host_by_name("Fafard"), worker);
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include <string>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_exec_waitany, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void worker(bool with_timeout)
{
/* Vector in which we store all pending executions*/
- std::vector<simgrid::s4u::ExecPtr> pending_executions;
+ std::vector<sg4::ExecPtr> pending_executions;
for (int i = 0; i < 3; i++) {
std::string name = std::string("Exec-") + std::to_string(i);
- double amount = (6 * (i % 2) + i + 1) * simgrid::s4u::this_actor::get_host()->get_speed();
+ double amount = (6 * (i % 2) + i + 1) * sg4::this_actor::get_host()->get_speed();
- simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(amount)->set_name(name);
+ sg4::ExecPtr exec = sg4::this_actor::exec_init(amount)->set_name(name);
pending_executions.push_back(exec);
exec->start();
XBT_INFO("Activity %s has started for %.0f seconds", name.c_str(),
- amount / simgrid::s4u::this_actor::get_host()->get_speed());
+ amount / sg4::this_actor::get_host()->get_speed());
}
/* Now that executions were initiated, wait for their completion, in order of termination.
while (not pending_executions.empty()) {
ssize_t pos;
if (with_timeout)
- pos = simgrid::s4u::Exec::wait_any_for(pending_executions, 4);
+ pos = sg4::Exec::wait_any_for(pending_executions, 4);
else
- pos = simgrid::s4u::Exec::wait_any(pending_executions);
+ pos = sg4::Exec::wait_any(pending_executions);
if (pos < 0) {
XBT_INFO("Do not wait any longer for an activity");
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Tremblay"), worker, false);
- simgrid::s4u::Actor::create("worker_timeout", e.host_by_name("Tremblay"), worker, true);
+ sg4::Actor::create("worker", e.host_by_name("Tremblay"), worker, false);
+ sg4::Actor::create("worker_timeout", e.host_by_name("Tremblay"), worker, true);
e.run();
return 0;
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_exec_waitfor, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void worker()
{
- simgrid::s4u::ExecPtr exec;
- double amount = 5 * simgrid::s4u::this_actor::get_host()->get_speed();
+ sg4::ExecPtr exec;
+ double amount = 5 * sg4::this_actor::get_host()->get_speed();
XBT_INFO("Create an activity that should run for 5 seconds");
- exec = simgrid::s4u::this_actor::exec_async(amount);
+ exec = sg4::this_actor::exec_async(amount);
/* Now that execution is started, wait for 3 seconds. */
XBT_INFO("But let it end after 3 seconds");
/* do it again, but this time with a timeout greater than the duration of the execution */
XBT_INFO("Create another activity that should run for 5 seconds and wait for it for 6 seconds");
- exec = simgrid::s4u::this_actor::exec_async(amount);
+ exec = sg4::this_actor::exec_async(amount);
try {
exec->wait_for(6);
XBT_INFO("Execution complete");
}
XBT_INFO("Finally test with a parallel execution");
- auto hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
+ auto hosts = sg4::Engine::get_instance()->get_all_hosts();
size_t hosts_count = hosts.size();
std::vector<double> computation_amounts;
std::vector<double> communication_amounts;
for (size_t j = i + 1; j < hosts_count; j++)
communication_amounts[i * hosts_count + j] = 1e7; // 10 MB
- exec = simgrid::s4u::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
+ exec = sg4::this_actor::exec_init(hosts, computation_amounts, communication_amounts);
try {
exec->wait_for(2);
XBT_INFO("Parallel Execution complete");
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Tremblay"), worker);
+ sg4::Actor::create("worker", e.host_by_name("Tremblay"), worker);
e.run();
return 0;
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void test(sg_size_t size)
{
- const simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front();
+ const sg4::Disk* disk = sg4::Host::current()->get_disks().front();
XBT_INFO("Hello! read %llu bytes from %s", size, disk->get_cname());
- simgrid::s4u::IoPtr activity = disk->io_init(size, simgrid::s4u::Io::OpType::READ);
+ sg4::IoPtr activity = disk->io_init(size, sg4::Io::OpType::READ);
activity->start();
activity->wait();
static void test_waitfor(sg_size_t size)
{
- const simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front();
+ const sg4::Disk* disk = sg4::Host::current()->get_disks().front();
XBT_INFO("Hello! write %llu bytes from %s", size, disk->get_cname());
- simgrid::s4u::IoPtr activity = disk->write_async(size);
+ sg4::IoPtr activity = disk->write_async(size);
try {
activity->wait_for(0.5);
} catch (const simgrid::TimeoutException&) {
static void test_cancel(sg_size_t size)
{
- const simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front();
- simgrid::s4u::this_actor::sleep_for(0.5);
+ const sg4::Disk* disk = sg4::Host::current()->get_disks().front();
+ sg4::this_actor::sleep_for(0.5);
XBT_INFO("Hello! write %llu bytes from %s", size, disk->get_cname());
- simgrid::s4u::IoPtr activity = disk->write_async(size);
- simgrid::s4u::this_actor::sleep_for(0.5);
+ sg4::IoPtr activity = disk->write_async(size);
+ sg4::this_actor::sleep_for(0.5);
XBT_INFO("I changed my mind, cancel!");
activity->cancel();
static void test_monitor(sg_size_t size)
{
- const simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front();
- simgrid::s4u::this_actor::sleep_for(1);
- simgrid::s4u::IoPtr activity = disk->write_async(size);
+ const sg4::Disk* disk = sg4::Host::current()->get_disks().front();
+ sg4::this_actor::sleep_for(1);
+ sg4::IoPtr activity = disk->write_async(size);
while (not activity->test()) {
XBT_INFO("Remaining amount of bytes to write: %g", activity->get_remaining());
- simgrid::s4u::this_actor::sleep_for(0.2);
+ sg4::this_actor::sleep_for(0.2);
}
activity->wait();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("test", e.host_by_name("bob"), test, 2e7);
- simgrid::s4u::Actor::create("test_waitfor", e.host_by_name("alice"), test_waitfor, 5e7);
- simgrid::s4u::Actor::create("test_cancel", e.host_by_name("alice"), test_cancel, 5e7);
- simgrid::s4u::Actor::create("test_monitor", e.host_by_name("alice"), test_monitor, 5e7);
+ sg4::Actor::create("test", e.host_by_name("bob"), test, 2e7);
+ sg4::Actor::create("test_waitfor", e.host_by_name("alice"), test_waitfor, 5e7);
+ sg4::Actor::create("test_cancel", e.host_by_name("alice"), test_cancel, 5e7);
+ sg4::Actor::create("test_monitor", e.host_by_name("alice"), test_monitor, 5e7);
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include <simgrid/s4u.hpp>
-namespace sg4 = simgrid::s4u;
-
XBT_LOG_NEW_DEFAULT_CATEGORY(disk_test, "Messages specific for this simulation");
+namespace sg4 = simgrid::s4u;
/** @brief Calculates the bandwidth for disk doing async operations */
static void estimate_bw(const sg4::Disk* disk, int n_flows, bool read)
create_sata_disk(bob, "Griffon (SATA II)");
zone->seal();
- simgrid::s4u::Actor::create("", bob, host);
+ sg4::Actor::create("", bob, host);
e.run();
- XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulated time: %g", sg4::Engine::get_clock());
return 0;
}
#include <vector>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void test()
{
- std::vector<simgrid::s4u::ActivityPtr> pending_activities;
+ std::vector<sg4::ActivityPtr> pending_activities;
- simgrid::s4u::ExecPtr bob_compute = simgrid::s4u::this_actor::exec_init(1e9);
- pending_activities.push_back(boost::dynamic_pointer_cast<simgrid::s4u::Activity>(bob_compute));
- simgrid::s4u::IoPtr bob_write =
- simgrid::s4u::Host::current()->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::WRITE);
- pending_activities.push_back(boost::dynamic_pointer_cast<simgrid::s4u::Activity>(bob_write));
- simgrid::s4u::IoPtr carl_read =
- simgrid::s4u::Host::by_name("carl")->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::READ);
- pending_activities.push_back(boost::dynamic_pointer_cast<simgrid::s4u::Activity>(carl_read));
- simgrid::s4u::ExecPtr carl_compute = simgrid::s4u::Host::by_name("carl")->exec_init(1e9);
- pending_activities.push_back(boost::dynamic_pointer_cast<simgrid::s4u::Activity>(carl_compute));
+ sg4::ExecPtr bob_compute = sg4::this_actor::exec_init(1e9);
+ pending_activities.push_back(boost::dynamic_pointer_cast<sg4::Activity>(bob_compute));
+ sg4::IoPtr bob_write = sg4::Host::current()->get_disks().front()->io_init(4000000, sg4::Io::OpType::WRITE);
+ pending_activities.push_back(boost::dynamic_pointer_cast<sg4::Activity>(bob_write));
+ sg4::IoPtr carl_read = sg4::Host::by_name("carl")->get_disks().front()->io_init(4000000, sg4::Io::OpType::READ);
+ pending_activities.push_back(boost::dynamic_pointer_cast<sg4::Activity>(carl_read));
+ sg4::ExecPtr carl_compute = sg4::Host::by_name("carl")->exec_init(1e9);
+ pending_activities.push_back(boost::dynamic_pointer_cast<sg4::Activity>(carl_compute));
// Name the activities (for logging purposes only)
bob_compute->set_name("bob compute");
// wait for the completion of all activities
while (not pending_activities.empty()) {
- ssize_t changed_pos = simgrid::s4u::Activity::wait_any(pending_activities);
+ ssize_t changed_pos = sg4::Activity::wait_any(pending_activities);
XBT_INFO("Activity '%s' is complete", pending_activities[changed_pos]->get_cname());
pending_activities.erase(pending_activities.begin() + changed_pos);
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_storage_file_system_init();
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("bob", e.host_by_name("bob"), test);
+ sg4::Actor::create("bob", e.host_by_name("bob"), test);
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include <unordered_map>
XBT_LOG_NEW_DEFAULT_CATEGORY(disk_test, "Messages specific for this simulation");
+namespace sg4 = simgrid::s4u;
static void host()
{
/* -Add an extra disk in a programmatic way */
- simgrid::s4u::Host::current()->create_disk("Disk3", /*read bandwidth*/ 9.6e7, /*write bandwidth*/6.4e7)->seal();
+ sg4::Host::current()->create_disk("Disk3", /*read bandwidth*/ 9.6e7, /*write bandwidth*/ 6.4e7)->seal();
/* - Display information on the disks mounted by the current host */
- XBT_INFO("*** Storage info on %s ***", simgrid::s4u::Host::current()->get_cname());
+ XBT_INFO("*** Storage info on %s ***", sg4::Host::current()->get_cname());
/* - Retrieve all disks from current host */
- std::vector<simgrid::s4u::Disk*> const& disk_list = simgrid::s4u::Host::current()->get_disks();
+ std::vector<sg4::Disk*> const& disk_list = sg4::Host::current()->get_disks();
/* - For each disk mounted on host, display disk name and mount point */
for (auto const& disk : disk_list)
disk->get_write_bandwidth());
/* - Write 400,000 bytes on Disk1 */
- simgrid::s4u::Disk* disk = disk_list.front();
+ sg4::Disk* disk = disk_list.front();
sg_size_t write = disk->write(400000);
XBT_INFO("Wrote %llu bytes on '%s'", write, disk->get_cname());
XBT_INFO("Read %llu bytes on '%s'", read, disk->get_cname());
/* - Write 800,000 bytes on Disk3 */
- const simgrid::s4u::Disk* disk3 = disk_list.back();
+ const sg4::Disk* disk3 = disk_list.back();
sg_size_t write_on_disk3 = disk3->write(800000);
XBT_INFO("Wrote %llu bytes on '%s'", write_on_disk3, disk3->get_cname());
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
/* - Display Host properties */
XBT_INFO(" %s -> %s", kv.first.c_str(), kv.second.c_str());
}
- simgrid::s4u::Actor::create("", e.host_by_name("bob"), host);
+ sg4::Actor::create("", e.host_by_name("bob"), host);
e.run();
- XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulated time: %g", sg4::Engine::get_clock());
return 0;
}
#define INMEGA (1024 * 1024)
XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example");
+namespace sg4 = simgrid::s4u;
static void host(std::vector<std::string> args)
{
- simgrid::s4u::File* file = simgrid::s4u::File::open(args[1], nullptr);
+ sg4::File* file = sg4::File::open(args[1], nullptr);
const char* filename = file->get_path();
XBT_INFO("Opened file '%s'", filename);
file->dump();
if (args.size() > 4) {
if (std::stoi(args[4]) != 0) {
- XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(),
- simgrid::s4u::Host::current()->get_cname(), args[2].c_str());
- file->remote_move(simgrid::s4u::Host::by_name(args[2]), args[3]);
+ XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), sg4::Host::current()->get_cname(),
+ args[2].c_str());
+ file->remote_move(sg4::Host::by_name(args[2]), args[3]);
} else {
- XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(),
- simgrid::s4u::Host::current()->get_cname(), args[2].c_str());
- file->remote_copy(simgrid::s4u::Host::by_name(args[2]), args[3]);
+ XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), sg4::Host::current()->get_cname(),
+ args[2].c_str());
+ file->remote_copy(sg4::Host::by_name(args[2]), args[3]);
}
}
file->close();
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_storage_file_system_init();
e.load_platform(argv[1]);
e.register_function("host", host);
e.load_deployment(argv[2]);
- std::vector<simgrid::s4u::Host*> all_hosts = e.get_all_hosts();
+ std::vector<sg4::Host*> all_hosts = e.get_all_hosts();
for (auto const& h : all_hosts) {
for (auto const& d : h->get_disks())
sg_disk_get_size_free(d) / INMEGA, d->get_cname(), h->get_cname());
}
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
+namespace sg4 = simgrid::s4u;
class MyHost {
public:
- void show_info(std::vector<simgrid::s4u::Disk*> const& disks) const
+ void show_info(std::vector<sg4::Disk*> const& disks) const
{
- XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->get_cname());
+ XBT_INFO("Storage info on %s:", sg4::Host::current()->get_cname());
for (auto const& d : disks) {
// Retrieve disk's information
void operator()() const
{
- std::vector<simgrid::s4u::Disk*> const& disks = simgrid::s4u::Host::current()->get_disks();
+ std::vector<sg4::Disk*> const& disks = sg4::Host::current()->get_disks();
show_info(disks);
// Open a non-existing file to create it
std::string filename = "/scratch/tmp/data.txt";
- auto* file = simgrid::s4u::File::open(filename, nullptr);
+ auto* file = sg4::File::open(filename, nullptr);
sg_size_t write = file->write(200000); // Write 200,000 bytes
XBT_INFO("Create a %llu bytes file named '%s' on /scratch", write, filename.c_str());
show_info(disks);
// Reopen the file and then unlink it
- file = simgrid::s4u::File::open("/scratch/tmp/simgrid.readme", nullptr);
+ file = sg4::File::open("/scratch/tmp/simgrid.readme", nullptr);
XBT_INFO("Unlink file: '%s'", file->get_path());
file->unlink();
file->close(); // Unlinking the file on "disk" does not close the file and free the object
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_storage_file_system_init();
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("host", e.host_by_name("bob"), MyHost());
+ sg4::Actor::create("host", e.host_by_name("bob"), MyHost());
e.run();
return 0;
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void writer()
{
/* - Retrieve all disks from current host */
- std::vector<simgrid::s4u::Disk*> const& disk_list = simgrid::s4u::Host::current()->get_disks();
+ std::vector<sg4::Disk*> const& disk_list = sg4::Host::current()->get_disks();
/* - Write 4,000,000 bytes on Disk1 */
disk_list.front()->write(4000000);
XBT_INFO("First write done.");
static void privileged_writer()
{
/* - Retrieve all disks from current host */
- std::vector<simgrid::s4u::Disk*> const& disk_list = simgrid::s4u::Host::current()->get_disks();
+ std::vector<sg4::Disk*> const& disk_list = sg4::Host::current()->get_disks();
/* - Write 4,000,000 bytes on Disk1 but specifies that this I/O operation gets a larger share of the resource.
*
* quickly. */
/* Resynchronize actors before second write */
- simgrid::s4u::this_actor::sleep_for(0.05);
+ sg4::this_actor::sleep_for(0.05);
/* - Write 4,000,000 bytes on Disk1 again and this time :
* - Start the I/O operation asynchronously to get an IoPtr
* 0.025s to write the last MB.
*/
- simgrid::s4u::IoPtr io = disk_list.front()->write_async(4000000);
- simgrid::s4u::this_actor::sleep_for(0.1);
+ sg4::IoPtr io = disk_list.front()->write_async(4000000);
+ sg4::this_actor::sleep_for(0.1);
XBT_INFO("Increase priority for the priviledged writer (%.0f bytes remaining to write)", io->get_remaining());
io->update_priority(2);
io->wait();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("writer", e.host_by_name("bob"), writer);
- simgrid::s4u::Actor::create("privileged_writer", e.host_by_name("bob"), privileged_writer);
+ sg4::Actor::create("writer", e.host_by_name("bob"), writer);
+ sg4::Actor::create("privileged_writer", e.host_by_name("bob"), privileged_writer);
e.run();
/* 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. */
-/** @addtogroup S4U_examples
+/** Switch the system thread hosting our maestro.
*
- * - <b>maestro-set/maestro-set.cpp: Switch the system thread hosting our maestro</b>.
- * That's a very advanced example in which we move the maestro context to another system thread.
- * Not many users need it (maybe only one, actually), but this example is also a regression test.
+ * That's a very advanced example in which we move the maestro context to another system thread.
+ * Not many users need it (maybe only one, actually), but this example is also a regression test.
*
- * This example is in C++ because we use C++11 threads to ensure that the feature is working as
- * expected. You can still use that feature from a C code.
+ * This example is in C++ because we use C++11 threads to ensure that the feature is working as
+ * expected. You can still use that feature from a C code.
*/
#include "simgrid/Exception.hpp"
#include <thread>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
const std::thread::id root_id = std::this_thread::get_id();
{
ensure_root_tid();
auto* payload = new std::string("some message");
- simgrid::s4u::Mailbox::by_name("some mailbox")->put(payload, 10e8);
+ sg4::Mailbox::by_name("some mailbox")->put(payload, 10e8);
}
static void receiver()
{
ensure_other_tid();
- simgrid::s4u::Mailbox::by_name("some mailbox")->get_unique<std::string>();
+ sg4::Mailbox::by_name("some mailbox")->get_unique<std::string>();
XBT_INFO("Task received");
}
static void maestro(void* /* data */)
{
ensure_other_tid();
- simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver);
- simgrid::s4u::Engine::get_instance()->run();
+ sg4::Actor::create("receiver", sg4::Host::by_name("Jupiter"), receiver);
+ sg4::Engine::get_instance()->run();
}
/** Main function */
* actor by the subsequent sg_actor_attach(). This must be done before the creation of the engine. */
simgrid_set_maestro(maestro, nullptr);
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc == 2, "Usage: %s platform_file\n"
"example: %s ../platforms/small_platform.xml\n",
#include <xbt/dynar.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(bugged1_liveness, "my log messages");
+namespace sg4 = simgrid::s4u;
class Message {
public:
enum class Kind { GRANT, REQUEST, RELEASE };
Kind kind = Kind::GRANT;
- simgrid::s4u::Mailbox* return_mailbox = nullptr;
- explicit Message(Message::Kind kind, simgrid::s4u::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
+ sg4::Mailbox* return_mailbox = nullptr;
+ explicit Message(Message::Kind kind, sg4::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
};
int r = 0;
static void coordinator()
{
bool CS_used = false;
- std::queue<simgrid::s4u::Mailbox*> requests;
+ std::queue<sg4::Mailbox*> requests;
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("coordinator");
while (true) {
auto m = mbox->get_unique<Message>();
} else {
if (not requests.empty()) {
XBT_INFO("CS release. Grant to queued requests (queue size: %zu)", requests.size());
- simgrid::s4u::Mailbox* req = requests.front();
+ sg4::Mailbox* req = requests.front();
requests.pop();
if (req->get_name() != "1") {
req->put(new Message(Message::Kind::GRANT, mbox), 1000);
static void client(int id)
{
- aid_t my_pid = simgrid::s4u::this_actor::get_pid();
+ aid_t my_pid = sg4::this_actor::get_pid();
- simgrid::s4u::Mailbox* my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id));
+ sg4::Mailbox* my_mailbox = sg4::Mailbox::by_name(std::to_string(id));
while (true) {
XBT_INFO("Ask the request");
- simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000);
+ sg4::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000);
if (id == 1) {
r = 1;
XBT_INFO("%d got the answer. Sleep a bit and release it", id);
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
- simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::RELEASE, my_mailbox), 1000);
+ sg4::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::RELEASE, my_mailbox), 1000);
- simgrid::s4u::this_actor::sleep_for(static_cast<double>(my_pid));
+ sg4::this_actor::sleep_for(static_cast<double>(my_pid));
if (id == 1) {
cs = 0;
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
MC_automaton_new_propositional_symbol_pointer("r", &r);
MC_automaton_new_propositional_symbol_pointer("cs", &cs);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator)
+ sg4::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator)
->set_kill_time(argc > 3 ? std::stod(argv[3]) : -1.0);
if (std::stod(argv[2]) == 0) {
- simgrid::s4u::Actor::create("client", e.host_by_name("Boivin"), raw_client, 1);
- simgrid::s4u::Actor::create("client", e.host_by_name("Fafard"), raw_client, 2);
+ sg4::Actor::create("client", e.host_by_name("Boivin"), raw_client, 1);
+ sg4::Actor::create("client", e.host_by_name("Fafard"), raw_client, 2);
} else { // "Visited" case
- simgrid::s4u::Actor::create("client", e.host_by_name("Boivin"), raw_client, 2);
- simgrid::s4u::Actor::create("client", e.host_by_name("Fafard"), raw_client, 1);
+ sg4::Actor::create("client", e.host_by_name("Boivin"), raw_client, 2);
+ sg4::Actor::create("client", e.host_by_name("Fafard"), raw_client, 1);
}
e.run();
constexpr int N = 3;
XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
+namespace sg4 = simgrid::s4u;
static void server()
{
int count = 0;
while (count < N) {
received.reset();
- received = simgrid::s4u::Mailbox::by_name("mymailbox")->get_unique<int>();
+ received = sg4::Mailbox::by_name("mymailbox")->get_unique<int>();
count++;
}
int value_got = *received;
static void client(int id)
{
auto* payload = new int(id);
- simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload, 10000);
+ sg4::Mailbox::by_name("mymailbox")->put(payload, 10000);
XBT_INFO("Sent!");
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("server", e.host_by_name("HostA"), server);
- simgrid::s4u::Actor::create("client", e.host_by_name("HostB"), client, 1);
- simgrid::s4u::Actor::create("client", e.host_by_name("HostC"), client, 2);
- simgrid::s4u::Actor::create("client", e.host_by_name("HostD"), client, 3);
+ sg4::Actor::create("server", e.host_by_name("HostA"), server);
+ sg4::Actor::create("client", e.host_by_name("HostB"), client, 1);
+ sg4::Actor::create("client", e.host_by_name("HostC"), client, 2);
+ sg4::Actor::create("client", e.host_by_name("HostD"), client, 3);
e.run();
return 0;
#include <simgrid/s4u.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(bugged2_liveness, "my log messages");
+namespace sg4 = simgrid::s4u;
class Message {
public:
enum class Kind { GRANT, NOT_GRANT, REQUEST };
Kind kind = Kind::GRANT;
- simgrid::s4u::Mailbox* return_mailbox = nullptr;
- explicit Message(Message::Kind kind, simgrid::s4u::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
+ sg4::Mailbox* return_mailbox = nullptr;
+ explicit Message(Message::Kind kind, sg4::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
};
int cs = 0;
static void coordinator()
{
bool CS_used = false; // initially the CS is idle
- std::queue<simgrid::s4u::Mailbox*> requests;
+ std::queue<sg4::Mailbox*> requests;
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("coordinator");
while (true) {
auto m = mbox->get_unique<Message>();
static void client(int id)
{
- aid_t my_pid = simgrid::s4u::this_actor::get_pid();
+ aid_t my_pid = sg4::this_actor::get_pid();
- simgrid::s4u::Mailbox* my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id));
+ sg4::Mailbox* my_mailbox = sg4::Mailbox::by_name(std::to_string(id));
while (true) {
XBT_INFO("Client (%d) asks the request", id);
- simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000);
+ sg4::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000);
auto grant = my_mailbox->get_unique<Message>();
XBT_INFO("Client (%d) got the answer (not grant). Try again", id);
}
- simgrid::s4u::this_actor::sleep_for(my_pid);
+ sg4::this_actor::sleep_for(my_pid);
}
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
MC_automaton_new_propositional_symbol_pointer("cs", &cs);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator);
- simgrid::s4u::Actor::create("client", e.host_by_name("Fafard"), client, 1);
- simgrid::s4u::Actor::create("client", e.host_by_name("Boivin"), client, 2);
+ sg4::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator);
+ sg4::Actor::create("client", e.host_by_name("Fafard"), client, 1);
+ sg4::Actor::create("client", e.host_by_name("Boivin"), client, 2);
e.run();
constexpr int CS_PER_PROCESS = 2;
XBT_LOG_NEW_DEFAULT_CATEGORY(centralized, "my log messages");
+namespace sg4 = simgrid::s4u;
class Message {
public:
enum class Kind { GRANT, REQUEST, RELEASE };
Kind kind = Kind::GRANT;
- simgrid::s4u::Mailbox* return_mailbox = nullptr;
- explicit Message(Message::Kind kind, simgrid::s4u::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
+ sg4::Mailbox* return_mailbox = nullptr;
+ explicit Message(Message::Kind kind, sg4::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
};
static void coordinator()
{
- std::queue<simgrid::s4u::Mailbox*> requests;
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
+ std::queue<sg4::Mailbox*> requests;
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("coordinator");
bool CS_used = false; // initially the CS is idle
int todo = AMOUNT_OF_CLIENTS * CS_PER_PROCESS; // amount of releases we are expecting
} else { // that's a release. Check if someone was waiting for the lock
if (not requests.empty()) {
XBT_INFO("CS release. Grant to queued requests (queue size: %zu)", requests.size());
- simgrid::s4u::Mailbox* req = requests.front();
+ sg4::Mailbox* req = requests.front();
requests.pop();
req->put(new Message(Message::Kind::GRANT, mbox), 1000);
todo--;
static void client()
{
- aid_t my_pid = simgrid::s4u::this_actor::get_pid();
+ aid_t my_pid = sg4::this_actor::get_pid();
- simgrid::s4u::Mailbox* my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(my_pid));
+ sg4::Mailbox* my_mailbox = sg4::Mailbox::by_name(std::to_string(my_pid));
// request the CS 3 times, sleeping a bit in between
for (int i = 0; i < CS_PER_PROCESS; i++) {
XBT_INFO("Ask the request");
- simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000);
+ sg4::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000);
// wait for the answer
auto grant = my_mailbox->get_unique<Message>();
XBT_INFO("got the answer. Sleep a bit and release it");
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
- simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::RELEASE, my_mailbox), 1000);
- simgrid::s4u::this_actor::sleep_for(static_cast<double>(my_pid));
+ sg4::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::RELEASE, my_mailbox), 1000);
+ sg4::this_actor::sleep_for(static_cast<double>(my_pid));
}
XBT_INFO("Got all the CS I wanted, quit now");
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator);
- simgrid::s4u::Actor::create("client", e.host_by_name("Fafard"), client);
- simgrid::s4u::Actor::create("client", e.host_by_name("Boivin"), client);
- simgrid::s4u::Actor::create("client", e.host_by_name("Jacquelin"), client);
- simgrid::s4u::Actor::create("client", e.host_by_name("Ginette"), client);
+ sg4::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator);
+ sg4::Actor::create("client", e.host_by_name("Fafard"), client);
+ sg4::Actor::create("client", e.host_by_name("Boivin"), client);
+ sg4::Actor::create("client", e.host_by_name("Jacquelin"), client);
+ sg4::Actor::create("client", e.host_by_name("Ginette"), client);
e.run();
#include <simgrid/s4u.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(mc_assert_example, "Logging channel used in this example");
+namespace sg4 = simgrid::s4u;
static int server(int worker_amount)
{
int value_got = -1;
- simgrid::s4u::Mailbox* mb = simgrid::s4u::Mailbox::by_name("server");
+ sg4::Mailbox* mb = sg4::Mailbox::by_name("server");
for (int count = 0; count < worker_amount; count++) {
auto msg = mb->get_unique<int>();
value_got = *msg;
/* I just send my rank onto the mailbox. It must be passed as a stable memory block (thus the new) so that that
* memory survives even after the end of the client */
- simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("server");
+ sg4::Mailbox* mailbox = sg4::Mailbox::by_name("server");
mailbox->put(new int(rank), 1 /* communication cost is not really relevant in MC mode */);
XBT_INFO("Sent!");
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n", argv[0]);
e.load_platform(argv[1]);
auto hosts = e.get_all_hosts();
xbt_assert(hosts.size() >= 3, "This example requires at least 3 hosts");
- simgrid::s4u::Actor::create("server", hosts[0], &server, 2);
- simgrid::s4u::Actor::create("client1", hosts[1], &client, 1);
- simgrid::s4u::Actor::create("client2", hosts[2], &client, 2);
+ sg4::Actor::create("server", hosts[0], &server, 2);
+ sg4::Actor::create("client1", hosts[1], &client, 1);
+ sg4::Actor::create("client2", hosts[2], &client, 2);
e.run();
return 0;
-/* Copyright (c) 2007-2022. The SimGrid Team. LEVEL_ALL rights reserved. */
+/* Copyright (c) 2007-2022. 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 <iomanip>
XBT_LOG_NEW_DEFAULT_CATEGORY(ns3_wifi_example, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
class Message
{
static void sender(const std::string& mailbox, int msg_size, unsigned sleep_time)
{
- simgrid::s4u::this_actor::sleep_for(sleep_time);
- auto* mbox = simgrid::s4u::Mailbox::by_name(mailbox);
- auto* msg = new Message(simgrid::s4u::this_actor::get_host()->get_name(), msg_size);
+ sg4::this_actor::sleep_for(sleep_time);
+ auto* mbox = sg4::Mailbox::by_name(mailbox);
+ auto* msg = new Message(sg4::this_actor::get_host()->get_name(), msg_size);
mbox->put(msg, msg_size);
}
static void receiver(const std::string& mailbox)
{
- auto* mbox = simgrid::s4u::Mailbox::by_name(mailbox);
+ auto* mbox = sg4::Mailbox::by_name(mailbox);
auto msg = mbox->get_unique<Message>();
- XBT_INFO("[%s] %s received %d bytes from %s",
- mailbox.c_str(),
- simgrid::s4u::this_actor::get_host()->get_name().c_str(),
- msg->size,
- msg->sender.c_str());
+ XBT_INFO("[%s] %s received %d bytes from %s", mailbox.c_str(), sg4::this_actor::get_host()->get_name().c_str(),
+ msg->size, msg->sender.c_str());
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
int msg_size = 1e5;
/* Communication between STA in the same wifi zone */
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA0-0"), sender, "1", msg_size, 10);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA0-1"), receiver, "1");
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA0-1"), sender, "2", msg_size, 20);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA0-0"), receiver, "2");
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA1-1"), sender, "3", msg_size, 30);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA1-2"), receiver, "3");
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA1-2"), sender, "4", msg_size, 40);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA1-1"), receiver, "4");
+ sg4::Actor::create("sender", e.host_by_name("STA0-0"), sender, "1", msg_size, 10);
+ sg4::Actor::create("receiver", e.host_by_name("STA0-1"), receiver, "1");
+ sg4::Actor::create("sender", e.host_by_name("STA0-1"), sender, "2", msg_size, 20);
+ sg4::Actor::create("receiver", e.host_by_name("STA0-0"), receiver, "2");
+ sg4::Actor::create("sender", e.host_by_name("STA1-1"), sender, "3", msg_size, 30);
+ sg4::Actor::create("receiver", e.host_by_name("STA1-2"), receiver, "3");
+ sg4::Actor::create("sender", e.host_by_name("STA1-2"), sender, "4", msg_size, 40);
+ sg4::Actor::create("receiver", e.host_by_name("STA1-1"), receiver, "4");
/* Communication between STA of different wifi zones */
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA0-0"), sender, "5", msg_size, 50);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA1-0"), receiver, "5");
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA1-0"), sender, "6", msg_size, 60);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA0-0"), receiver, "6");
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA0-1"), sender, "7", msg_size, 70);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA1-2"), receiver, "7");
- simgrid::s4u::Actor::create("sender", e.host_by_name("STA1-2"), sender, "8", msg_size, 80);
- simgrid::s4u::Actor::create("receiver", e.host_by_name("STA0-1"), receiver, "8");
+ sg4::Actor::create("sender", e.host_by_name("STA0-0"), sender, "5", msg_size, 50);
+ sg4::Actor::create("receiver", e.host_by_name("STA1-0"), receiver, "5");
+ sg4::Actor::create("sender", e.host_by_name("STA1-0"), sender, "6", msg_size, 60);
+ sg4::Actor::create("receiver", e.host_by_name("STA0-0"), receiver, "6");
+ sg4::Actor::create("sender", e.host_by_name("STA0-1"), sender, "7", msg_size, 70);
+ sg4::Actor::create("receiver", e.host_by_name("STA1-2"), receiver, "7");
+ sg4::Actor::create("sender", e.host_by_name("STA1-2"), sender, "8", msg_size, 80);
+ sg4::Actor::create("receiver", e.host_by_name("STA0-1"), receiver, "8");
e.run();
return 0;
#include <unordered_map>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
double start_time;
std::unordered_map<int, std::string> workernames;
/* worker name */
workernames[id] = args[2];
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args[3]);
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(args[3]);
- masternames[id] = simgrid::s4u::Host::current()->get_name();
+ masternames[id] = sg4::Host::current()->get_name();
auto* payload = new double(msg_size);
/* time measurement */
- start_time = simgrid::s4u::Engine::get_clock();
+ start_time = sg4::Engine::get_clock();
mbox->put(payload, static_cast<uint64_t>(msg_size));
XBT_DEBUG("Finished");
xbt_assert(args.size() == 2, "Strange number of arguments expected 1 got %zu", args.size() - 1);
int id = std::stoi(args[1]);
- simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args[1]);
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name(args[1]);
XBT_DEBUG("Worker started");
auto payload = mbox->get_unique<double>();
- double elapsed_time = simgrid::s4u::Engine::get_clock() - start_time;
+ double elapsed_time = sg4::Engine::get_clock() - start_time;
XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s", id, *payload, masternames.at(id).c_str(),
workernames.at(id).c_str());
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 2,
"Usage: %s platform_file deployment_file\n"
"\tExample: %s platform.xml deployment.xml\n",
*/
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_network_wifi, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
-static void sender(simgrid::s4u::Mailbox* mailbox, int data_size)
+static void sender(sg4::Mailbox* mailbox, int data_size)
{
XBT_INFO("Send a message to the other station.");
static std::string message = "message";
mailbox->put(&message, data_size);
XBT_INFO("Done.");
}
-static void receiver(simgrid::s4u::Mailbox* mailbox)
+static void receiver(sg4::Mailbox* mailbox)
{
XBT_INFO("Wait for a message.");
mailbox->get<std::string>();
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
/* Exchange a message between the 2 stations */
- auto mailbox = simgrid::s4u::Mailbox::by_name("mailbox");
+ auto mailbox = sg4::Mailbox::by_name("mailbox");
auto station1 = e.host_by_name("Station 1");
auto station2 = e.host_by_name("Station 2");
- simgrid::s4u::Actor::create("sender", station1, sender, mailbox, 1e7);
- simgrid::s4u::Actor::create("receiver", station2, receiver, mailbox);
+ sg4::Actor::create("sender", station1, sender, mailbox, 1e7);
+ sg4::Actor::create("receiver", station2, receiver, mailbox);
/* Declare that the stations are not at the same distance from their AP */
auto ap = e.link_by_name("AP1");
* speed. The first way to do so is to use a file in the XML, while the second is to use the programmatic interface. */
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_platform_profile, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void watcher()
{
- const auto* jupiter = simgrid::s4u::Host::by_name("Jupiter");
- const auto* fafard = simgrid::s4u::Host::by_name("Fafard");
- const auto* lilibeth = simgrid::s4u::Host::by_name("Lilibeth");
- const auto* link1 = simgrid::s4u::Link::by_name("1");
- const auto* link2 = simgrid::s4u::Link::by_name("2");
+ const auto* jupiter = sg4::Host::by_name("Jupiter");
+ const auto* fafard = sg4::Host::by_name("Fafard");
+ const auto* lilibeth = sg4::Host::by_name("Lilibeth");
+ const auto* link1 = sg4::Link::by_name("1");
+ const auto* link2 = sg4::Link::by_name("2");
- std::vector<simgrid::s4u::Link*> links;
+ std::vector<sg4::Link*> links;
double lat = 0;
jupiter->route_to(fafard, links, &lat);
jupiter->get_speed() * jupiter->get_available_speed() / 1000000,
lilibeth->get_speed() * lilibeth->get_available_speed() / 1000000, link1->get_bandwidth() / 1000,
link1->get_latency() * 1000, link2->get_bandwidth() / 1000, link2->get_latency() * 1000);
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
}
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
->seal();
// Add a watcher of the changes
- simgrid::s4u::Actor::create("watcher", e.host_by_name("Fafard"), watcher);
+ sg4::Actor::create("watcher", e.host_by_name("Fafard"), watcher);
e.run();
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void execute_load_test()
{
- s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
+ s4u_Host* host = sg4::Host::by_name("MyHost1");
XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0) and current average "
"load: %.5f (should be 0)",
host->get_speed(), sg_host_get_computed_flops(host), sg_host_get_avg_load(host));
- double start = simgrid::s4u::Engine::get_clock();
+ double start = sg4::Engine::get_clock();
XBT_INFO("Sleep for 10 seconds");
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
double speed = host->get_speed();
XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
"changed)",
- simgrid::s4u::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
+ sg4::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
// Run an activity
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
XBT_INFO("Run an activity of %.0E flops at current speed of %.0E flop/s", 200E6, host->get_speed());
- simgrid::s4u::this_actor::execute(200E6);
+ sg4::this_actor::execute(200E6);
XBT_INFO(
"Done working on my activity; this took %.2fs; current peak speed: %.0E flop/s (when I started the computation, "
"the speed was set to %.0E flop/s); number of flops computed so "
"far: %.2E, average load as reported by the HostLoad plugin: %.5f (should be %.5f)",
- simgrid::s4u::Engine::get_clock() - start, host->get_speed(), speed, sg_host_get_computed_flops(host),
+ sg4::Engine::get_clock() - start, host->get_speed(), speed, sg_host_get_computed_flops(host),
sg_host_get_avg_load(host),
200E6 / (10.5 * speed * host->get_core_count() +
- (simgrid::s4u::Engine::get_clock() - start - 0.5) * host->get_speed() * host->get_core_count()));
+ (sg4::Engine::get_clock() - start - 0.5) * host->get_speed() * host->get_core_count()));
// ========= Change power peak =========
int pstate = 1;
pstate, host->get_pstate_speed(pstate), host->get_speed(), sg_host_get_avg_load(host));
// Run a second activity
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
XBT_INFO("Run an activity of %.0E flops", 100E6);
- simgrid::s4u::this_actor::execute(100E6);
+ sg4::this_actor::execute(100E6);
XBT_INFO("Done working on my activity; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
"far: %.2E",
- simgrid::s4u::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
+ sg4::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
- start = simgrid::s4u::Engine::get_clock();
+ start = sg4::Engine::get_clock();
XBT_INFO("========= Requesting a reset of the computation and load counters");
sg_host_load_reset(host);
XBT_INFO("After reset: %.0E flops computed; load is %.5f", sg_host_get_computed_flops(host),
sg_host_get_avg_load(host));
XBT_INFO("Sleep for 4 seconds");
- simgrid::s4u::this_actor::sleep_for(4);
+ sg4::this_actor::sleep_for(4);
XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
- simgrid::s4u::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
+ sg4::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
// =========== Turn the other host off ==========
- s4u_Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
+ s4u_Host* host2 = sg4::Host::by_name("MyHost2");
XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far and has an "
"average load of %.5f.",
sg_host_get_computed_flops(host2), sg_host_get_avg_load(host2));
host2->turn_off();
- start = simgrid::s4u::Engine::get_clock();
- simgrid::s4u::this_actor::sleep_for(10);
+ start = sg4::Engine::get_clock();
+ sg4::this_actor::sleep_for(10);
XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
- simgrid::s4u::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
+ sg4::Engine::get_clock() - start, host->get_speed(), sg_host_get_computed_flops(host));
}
static void change_speed()
{
- s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
- simgrid::s4u::this_actor::sleep_for(10.5);
+ s4u_Host* host = sg4::Host::by_name("MyHost1");
+ sg4::this_actor::sleep_for(10.5);
XBT_INFO("I slept until now, but now I'll change the speed of this host "
"while the other actor is still computing! This should slow the computation down.");
host->set_pstate(2);
int main(int argc, char* argv[])
{
sg_host_load_plugin_init();
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("load_test", e.host_by_name("MyHost1"), execute_load_test);
- simgrid::s4u::Actor::create("change_speed", e.host_by_name("MyHost1"), change_speed);
+ sg4::Actor::create("load_test", e.host_by_name("MyHost1"), execute_load_test);
+ sg4::Actor::create("change_speed", e.host_by_name("MyHost1"), change_speed);
e.run();
- XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Total simulation time: %.2f", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void sender(const std::string& mailbox, uint64_t msg_size)
{
- auto mbox = simgrid::s4u::Mailbox::by_name(mailbox);
+ auto mbox = sg4::Mailbox::by_name(mailbox);
static int payload = 42;
mbox->put(&payload, msg_size);
}
static void receiver(const std::string& mailbox)
{
- auto mbox = simgrid::s4u::Mailbox::by_name(mailbox);
+ auto mbox = sg4::Mailbox::by_name(mailbox);
mbox->get<int>();
}
-static void run_transfer(simgrid::s4u::Host* src_host, simgrid::s4u::Host* dst_host, const std::string& mailbox,
- unsigned long msg_size)
+static void run_transfer(sg4::Host* src_host, sg4::Host* dst_host, const std::string& mailbox, unsigned long msg_size)
{
XBT_INFO("Launching the transfer of %lu bytes", msg_size);
- simgrid::s4u::Actor::create("sender", src_host, sender, mailbox, msg_size);
- simgrid::s4u::Actor::create("receiver", dst_host, receiver, mailbox);
+ sg4::Actor::create("sender", src_host, sender, mailbox, msg_size);
+ sg4::Actor::create("receiver", dst_host, receiver, mailbox);
}
static void execute_load_test()
{
- auto host0 = simgrid::s4u::Host::by_name("node-0.simgrid.org");
- auto host1 = simgrid::s4u::Host::by_name("node-1.simgrid.org");
+ auto host0 = sg4::Host::by_name("node-0.simgrid.org");
+ auto host1 = sg4::Host::by_name("node-1.simgrid.org");
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
run_transfer(host0, host1, "1", 1000 * 1000 * 1000);
- simgrid::s4u::this_actor::sleep_for(10);
+ sg4::this_actor::sleep_for(10);
run_transfer(host0, host1, "2", 1000 * 1000 * 1000);
- simgrid::s4u::this_actor::sleep_for(3);
+ sg4::this_actor::sleep_for(3);
run_transfer(host0, host1, "3", 1000 * 1000 * 1000);
}
-static void show_link_load(const std::string& link_name, const simgrid::s4u::Link* link)
+static void show_link_load(const std::string& link_name, const sg4::Link* link)
{
XBT_INFO("%s link load (cum, avg, min, max): (%g, %g, %g, %g)", link_name.c_str(), sg_link_get_cum_load(link),
sg_link_get_avg_load(link), sg_link_get_min_instantaneous_load(link),
static void monitor()
{
- auto link_backbone = simgrid::s4u::Link::by_name("cluster0_backbone");
- auto link_host0 = simgrid::s4u::Link::by_name("cluster0_link_0_UP");
- auto link_host1 = simgrid::s4u::Link::by_name("cluster0_link_1_DOWN");
+ auto link_backbone = sg4::Link::by_name("cluster0_backbone");
+ auto link_host0 = sg4::Link::by_name("cluster0_link_0_UP");
+ auto link_host1 = sg4::Link::by_name("cluster0_link_1_DOWN");
XBT_INFO("Tracking desired links");
sg_link_load_track(link_backbone);
sg_link_load_track(link_host1);
show_link_load("Backbone", link_backbone);
- while (simgrid::s4u::Engine::get_clock() < 5) {
- simgrid::s4u::this_actor::sleep_for(1);
+ while (sg4::Engine::get_clock() < 5) {
+ sg4::this_actor::sleep_for(1);
show_link_load("Backbone", link_backbone);
}
XBT_INFO("Now resetting and probing host links each second.");
- while (simgrid::s4u::Engine::get_clock() < 29) {
+ while (sg4::Engine::get_clock() < 29) {
sg_link_load_reset(link_host0);
sg_link_load_reset(link_host1);
- simgrid::s4u::this_actor::sleep_for(1);
+ sg4::this_actor::sleep_for(1);
show_link_load("Host0_UP", link_host0);
show_link_load("Host1_UP", link_host1);
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_link_load_plugin_init();
xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
- simgrid::s4u::Actor::create("load_test", e.host_by_name("node-42.simgrid.org"), execute_load_test);
- simgrid::s4u::Actor::create("monitor", e.host_by_name("node-51.simgrid.org"), monitor);
+ sg4::Actor::create("load_test", e.host_by_name("node-42.simgrid.org"), execute_load_test);
+ sg4::Actor::create("monitor", e.host_by_name("node-51.simgrid.org"), monitor);
e.run();
- XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Total simulation time: %.2f", sg4::Engine::get_clock());
return 0;
}
#include <string>
XBT_LOG_NEW_DEFAULT_CATEGORY(replay_comm, "Messages specific for this example");
+namespace sg4 = simgrid::s4u;
#define ACT_DEBUG(...) \
if (XBT_LOG_ISENABLED(replay_comm, xbt_log_priority_verbose)) { \
static void compute(simgrid::xbt::ReplayAction& action)
{
double amount = std::stod(action[2]);
- double clock = simgrid::s4u::Engine::get_clock();
+ double clock = sg4::Engine::get_clock();
ACT_DEBUG("Entering %s", NAME.c_str());
- simgrid::s4u::this_actor::execute(amount);
- log_action(action, simgrid::s4u::Engine::get_clock() - clock);
+ sg4::this_actor::execute(amount);
+ log_action(action, sg4::Engine::get_clock() - clock);
}
static void send(simgrid::xbt::ReplayAction& action)
{
auto size = static_cast<uint64_t>(std::stod(action[3]));
auto* payload = new std::string(action[3]);
- double clock = simgrid::s4u::Engine::get_clock();
- simgrid::s4u::Mailbox* to = simgrid::s4u::Mailbox::by_name(simgrid::s4u::this_actor::get_name() + "_" + action[2]);
+ double clock = sg4::Engine::get_clock();
+ sg4::Mailbox* to = sg4::Mailbox::by_name(sg4::this_actor::get_name() + "_" + action[2]);
ACT_DEBUG("Entering Send: %s (size: %" PRIu64 ") -- Actor %s on mailbox %s", NAME.c_str(), size,
- simgrid::s4u::this_actor::get_cname(), to->get_cname());
+ sg4::this_actor::get_cname(), to->get_cname());
to->put(payload, size);
- log_action(action, simgrid::s4u::Engine::get_clock() - clock);
+ log_action(action, sg4::Engine::get_clock() - clock);
}
static void recv(simgrid::xbt::ReplayAction& action)
{
- double clock = simgrid::s4u::Engine::get_clock();
- simgrid::s4u::Mailbox* from =
- simgrid::s4u::Mailbox::by_name(std::string(action[2]) + "_" + simgrid::s4u::this_actor::get_name());
+ double clock = sg4::Engine::get_clock();
+ sg4::Mailbox* from = sg4::Mailbox::by_name(std::string(action[2]) + "_" + sg4::this_actor::get_name());
- ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME.c_str(), simgrid::s4u::this_actor::get_cname(),
- from->get_cname());
+ ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME.c_str(), sg4::this_actor::get_cname(), from->get_cname());
from->get_unique<std::string>();
- log_action(action, simgrid::s4u::Engine::get_clock() - clock);
+ log_action(action, sg4::Engine::get_clock() - clock);
}
};
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 2,
"Usage: %s platform_file deployment_file [action_files]\n"
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include <boost/algorithm/string/join.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(replay_io, "Messages specific for this example");
+namespace sg4 = simgrid::s4u;
#define ACT_DEBUG(...) \
if (XBT_LOG_ISENABLED(replay_io, xbt_log_priority_verbose)) { \
((void)0)
class Replayer {
- static std::unordered_map<std::string, simgrid::s4u::File> opened_files;
+ static std::unordered_map<std::string, sg4::File> opened_files;
static void log_action(const simgrid::xbt::ReplayAction& action, double date)
{
}
}
- static simgrid::s4u::File* get_file_descriptor(const std::string& file_name)
+ static sg4::File* get_file_descriptor(const std::string& file_name)
{
- std::string full_name = simgrid::s4u::this_actor::get_name() + ":" + file_name;
+ std::string full_name = sg4::this_actor::get_name() + ":" + file_name;
return &opened_files.at(full_name);
}
static void open(simgrid::xbt::ReplayAction& action)
{
std::string file_name = action[2];
- double clock = simgrid::s4u::Engine::get_clock();
- std::string full_name = simgrid::s4u::this_actor::get_name() + ":" + file_name;
+ double clock = sg4::Engine::get_clock();
+ std::string full_name = sg4::this_actor::get_name() + ":" + file_name;
ACT_DEBUG("Entering Open: %s (filename: %s)", NAME.c_str(), file_name.c_str());
opened_files.emplace(std::piecewise_construct, std::forward_as_tuple(full_name),
std::forward_as_tuple(file_name, nullptr));
- log_action(action, simgrid::s4u::Engine::get_clock() - clock);
+ log_action(action, sg4::Engine::get_clock() - clock);
}
static void read(simgrid::xbt::ReplayAction& action)
{
std::string file_name = action[2];
sg_size_t size = std::stoul(action[3]);
- double clock = simgrid::s4u::Engine::get_clock();
+ double clock = sg4::Engine::get_clock();
- simgrid::s4u::File* file = get_file_descriptor(file_name);
+ sg4::File* file = get_file_descriptor(file_name);
ACT_DEBUG("Entering Read: %s (size: %llu)", NAME.c_str(), size);
file->read(size);
- log_action(action, simgrid::s4u::Engine::get_clock() - clock);
+ log_action(action, sg4::Engine::get_clock() - clock);
}
static void close(simgrid::xbt::ReplayAction& action)
{
std::string file_name = action[2];
- std::string full_name = simgrid::s4u::this_actor::get_name() + ":" + file_name;
- double clock = simgrid::s4u::Engine::get_clock();
+ std::string full_name = sg4::this_actor::get_name() + ":" + file_name;
+ double clock = sg4::Engine::get_clock();
ACT_DEBUG("Entering Close: %s (filename: %s)", NAME.c_str(), file_name.c_str());
xbt_assert(opened_files.erase(full_name) == 1, "File not found in opened files: %s", full_name.c_str());
- log_action(action, simgrid::s4u::Engine::get_clock() - clock);
+ log_action(action, sg4::Engine::get_clock() - clock);
}
};
-std::unordered_map<std::string, simgrid::s4u::File> Replayer::opened_files;
+std::unordered_map<std::string, sg4::File> Replayer::opened_files;
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
sg_storage_file_system_init();
xbt_assert(argc > 3,
e.run();
- XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+ XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
return 0;
}
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
std::vector<simgrid::kernel::routing::ClusterZone*> clusters =
for (auto c : clusters) {
XBT_INFO("%s", c->get_cname());
- std::vector<simgrid::s4u::Host*> hosts = c->get_all_hosts();
+ std::vector<sg4::Host*> hosts = c->get_all_hosts();
for (auto h : hosts)
XBT_INFO(" %s", h->get_cname());
}
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
+namespace sg4 = simgrid::s4u;
/// Wait on the barrier then leave
-static void worker(simgrid::s4u::BarrierPtr barrier)
+static void worker(sg4::BarrierPtr barrier)
{
XBT_INFO("Waiting on the barrier");
barrier->wait();
/// Spawn actor_count-1 workers and do a barrier with them
static void master(int actor_count)
{
- simgrid::s4u::BarrierPtr barrier = simgrid::s4u::Barrier::create(actor_count);
+ sg4::BarrierPtr barrier = sg4::Barrier::create(actor_count);
XBT_INFO("Spawning %d workers", actor_count - 1);
for (int i = 0; i < actor_count - 1; i++) {
- simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Jupiter"), worker, barrier);
+ sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), worker, barrier);
}
XBT_INFO("Waiting on the barrier");
int main(int argc, char **argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
// Parameter: Number of actores in the barrier
xbt_assert(argc >= 2, "Usage: %s <actor-count>\n", argv[0]);
xbt_assert(actor_count > 0, "<actor-count> must be greater than 0");
e.load_platform(argc > 2 ? argv[2] : "../../platforms/two_hosts.xml");
- simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), master, actor_count);
+ sg4::Actor::create("master", e.host_by_name("Tremblay"), master, actor_count);
e.run();
return 0;
#include <simgrid/s4u.hpp> /* All of S4U */
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
+namespace sg4 = simgrid::s4u;
-simgrid::s4u::MutexPtr mtx = nullptr;
-simgrid::s4u::ConditionVariablePtr cv = nullptr;
+sg4::MutexPtr mtx = nullptr;
+sg4::ConditionVariablePtr cv = nullptr;
bool ready = false;
static void competitor(int id)
{
XBT_INFO("Entering the race...");
- std::unique_lock<simgrid::s4u::Mutex> lck(*mtx);
+ std::unique_lock<sg4::Mutex> lck(*mtx);
while (not ready) {
- auto now = simgrid::s4u::Engine::get_clock();
+ auto now = sg4::Engine::get_clock();
if (cv->wait_until(lck, now + (id+1)*0.25) == std::cv_status::timeout) {
XBT_INFO("Out of wait_until (timeout)");
}
static void go()
{
XBT_INFO("Are you ready? ...");
- simgrid::s4u::this_actor::sleep_for(3);
- std::unique_lock<simgrid::s4u::Mutex> lck(*mtx);
+ sg4::this_actor::sleep_for(3);
+ std::unique_lock<sg4::Mutex> lck(*mtx);
XBT_INFO("Go go go!");
ready = true;
cv->notify_all();
static void main_actor()
{
- mtx = simgrid::s4u::Mutex::create();
- cv = simgrid::s4u::ConditionVariable::create();
+ mtx = sg4::Mutex::create();
+ cv = sg4::ConditionVariable::create();
- auto host = simgrid::s4u::this_actor::get_host();
+ auto host = sg4::this_actor::get_host();
for (int i = 0; i < 10; ++i)
- simgrid::s4u::Actor::create("competitor", host, competitor, i);
- simgrid::s4u::Actor::create("go", host, go);
+ sg4::Actor::create("competitor", host, competitor, i);
+ sg4::Actor::create("go", host, go);
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform("../../platforms/small_platform.xml");
- simgrid::s4u::Actor::create("main", e.host_by_name("Tremblay"), main_actor);
+ sg4::Actor::create("main", e.host_by_name("Tremblay"), main_actor);
e.run();
return 0;
#include <simgrid/s4u.hpp> /* All of S4U */
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
+namespace sg4 = simgrid::s4u;
std::string data;
bool done = false;
-static void worker_fun(simgrid::s4u::ConditionVariablePtr cv, simgrid::s4u::MutexPtr mutex)
+static void worker_fun(sg4::ConditionVariablePtr cv, sg4::MutexPtr mutex)
{
- std::unique_lock<simgrid::s4u::Mutex> lock(*mutex);
+ std::unique_lock<sg4::Mutex> lock(*mutex);
XBT_INFO("Start processing data which is '%s'.", data.c_str());
data += std::string(" after processing");
static void master_fun()
{
- auto mutex = simgrid::s4u::Mutex::create();
- auto cv = simgrid::s4u::ConditionVariable::create();
+ auto mutex = sg4::Mutex::create();
+ auto cv = sg4::ConditionVariable::create();
data = std::string("Example data");
- auto worker = simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Jupiter"), worker_fun, cv, mutex);
+ auto worker = sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), worker_fun, cv, mutex);
// wait for the worker
- cv->wait(std::unique_lock<simgrid::s4u::Mutex>(*mutex), []() { return done; });
+ cv->wait(std::unique_lock<sg4::Mutex>(*mutex), []() { return done; });
XBT_INFO("data is now '%s'.", data.c_str());
worker->join();
int main(int argc, char** argv)
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
e.load_platform("../../platforms/two_hosts.xml");
- simgrid::s4u::Actor::create("main", e.host_by_name("Tremblay"), master_fun);
+ sg4::Actor::create("main", e.host_by_name("Tremblay"), master_fun);
e.run();
return 0;
#include "simgrid/instr.h"
#include "simgrid/s4u.hpp"
+namespace sg4 = simgrid::s4u;
+
struct Task {
std::string name;
std::string category;
static void master()
{
- auto mbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
+ auto mbox = sg4::Mailbox::by_name("master_mailbox");
for (int i = 0; i < 10; i++) {
Task task;
if (i % 2)
static void worker()
{
- auto mbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
+ auto mbox = sg4::Mailbox::by_name("master_mailbox");
while (true) {
auto task = mbox->get_unique<Task>();
if (task->name == "finalize") {
break;
}
// creating task and setting its category
- simgrid::s4u::this_actor::exec_init(task->flops)
- ->set_name(task->name)
- ->set_tracing_category(task->category)
- ->wait();
+ sg4::this_actor::exec_init(task->flops)->set_name(task->name)->set_tracing_category(task->category)->wait();
}
}
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
simgrid::instr::declare_tracing_category("data", "0 0 1"); // blue
simgrid::instr::declare_tracing_category("finalize", "0 0 0"); // black
- simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), master);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Fafard"), worker);
+ sg4::Actor::create("master", e.host_by_name("Tremblay"), master);
+ sg4::Actor::create("worker", e.host_by_name("Fafard"), worker);
e.run();
return 0;
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void trace_fun()
{
- const auto host = simgrid::s4u::this_actor::get_host()->get_name();
+ const auto host = sg4::this_actor::get_host()->get_name();
// the hostname has an empty HDD with a capacity of 100000 (bytes)
simgrid::instr::set_host_variable(host, "HDD_capacity", 100000);
for (int i = 0; i < 10; i++) {
// create and execute a task just to make the simulated time advance
- simgrid::s4u::this_actor::execute(1e4);
+ sg4::this_actor::execute(1e4);
// ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
simgrid::instr::add_host_variable(host, "HDD_utilization", 100);
for (int i = 0; i < 10; i++) {
// create and execute a task just to make the simulated time advance
- simgrid::s4u::this_actor::execute(1e4);
+ sg4::this_actor::execute(1e4);
// SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
simgrid::instr::sub_host_variable(host, "HDD_utilization", 100);
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
simgrid::instr::declare_host_variable("HDD_capacity");
simgrid::instr::declare_host_variable("HDD_utilization", "1 0 0"); // red color
- simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), trace_fun);
+ sg4::Actor::create("master", e.host_by_name("Tremblay"), trace_fun);
e.run();
#include "simgrid/instr.h"
#include "simgrid/s4u.hpp"
+namespace sg4 = simgrid::s4u;
+
static void trace_fun()
{
// set initial values for the link user variables this example only shows for links identified by "6" and "3" in the
// run the simulation, update my variables accordingly
for (int i = 0; i < 10; i++) {
- simgrid::s4u::this_actor::execute(1e6);
+ sg4::this_actor::execute(1e6);
// Add to link user variables
simgrid::instr::add_link_variable("3", "Link_Utilization", 5.6);
}
for (int i = 0; i < 10; i++) {
- simgrid::s4u::this_actor::execute(1e6);
+ sg4::this_actor::execute(1e6);
// Subtract from link user variables
simgrid::instr::sub_link_variable("3", "Link_Utilization", 3.4);
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
simgrid::instr::declare_link_variable("Link_Capacity");
simgrid::instr::declare_link_variable("Link_Utilization", "0.9 0.1 0.1");
- simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Tremblay"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Jupiter"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Fafard"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Ginette"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Bourassa"), trace_fun);
+ sg4::Actor::create("master", e.host_by_name("Tremblay"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Tremblay"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Jupiter"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Fafard"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Ginette"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Bourassa"), trace_fun);
e.run();
return 0;
#include <simgrid/s4u.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_trace_masterworker, "Messages specific for this example");
+namespace sg4 = simgrid::s4u;
struct Task {
std::string name;
double compute_cost = std::stod(args[2]);
long communication_cost = std::stol(args[3]);
size_t workers_count = args.size() - 4;
- const auto& my_host = simgrid::s4u::this_actor::get_host()->get_name();
- auto mailbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
+ const auto& my_host = sg4::this_actor::get_host()->get_name();
+ auto mailbox = sg4::Mailbox::by_name("master_mailbox");
XBT_DEBUG("Got %zu workers and %ld tasks to process", workers_count, tasks_count);
{
xbt_assert(args.size() == 1, "The worker expects no argument");
- const auto& my_host = simgrid::s4u::this_actor::get_host()->get_name();
- auto mailbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
+ const auto& my_host = sg4::this_actor::get_host()->get_name();
+ auto mailbox = sg4::Mailbox::by_name("master_mailbox");
simgrid::instr::set_host_variable(my_host, "is_worker", 1);
simgrid::instr::set_host_variable(my_host, "task_computation", 0);
}
// adding the task's cost to the variable "task_computation"
simgrid::instr::add_host_variable(my_host, "task_computation", task->flops);
- simgrid::s4u::this_actor::exec_init(task->flops)
- ->set_name(task->name)
- ->set_tracing_category(task->category)
- ->wait();
+ sg4::this_actor::exec_init(task->flops)->set_name(task->name)->set_tracing_category(task->category)->wait();
}
XBT_DEBUG("Exiting now.");
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
e.load_platform(argv[1]);
#include "simgrid/s4u.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
static void trace_fun()
{
// run the simulation, update my variables accordingly
for (int i = 0; i < 10; i++) {
- simgrid::s4u::this_actor::execute(1e6);
+ sg4::this_actor::execute(1e6);
// Add to link user variables
simgrid::instr::add_link_variable("Tremblay", "Bourassa", "Link_Utilization", 5.6);
}
for (int i = 0; i < 10; i++) {
- simgrid::s4u::this_actor::execute(1e6);
+ sg4::this_actor::execute(1e6);
// Subtract from link user variables
simgrid::instr::sub_link_variable("Tremblay", "Bourassa", "Link_Utilization", 3.4);
int main(int argc, char* argv[])
{
- simgrid::s4u::Engine e(&argc, argv);
+ sg4::Engine e(&argc, argv);
xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
e.load_platform(argv[1]);
simgrid::instr::declare_link_variable("Link_Capacity");
simgrid::instr::declare_link_variable("Link_Utilization", "0.9 0.1 0.1");
- simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Tremblay"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Jupiter"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Fafard"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Ginette"), trace_fun);
- simgrid::s4u::Actor::create("worker", e.host_by_name("Bourassa"), trace_fun);
+ sg4::Actor::create("master", e.host_by_name("Tremblay"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Tremblay"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Jupiter"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Fafard"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Ginette"), trace_fun);
+ sg4::Actor::create("worker", e.host_by_name("Bourassa"), trace_fun);
e.run();
return 0;