loosely-coupled-dss/simulator.cc
2021-05-05 16:42:11 +02:00

67 lines
No EOL
1.8 KiB
C++

#include "simgrid/s4u.hpp"
#include <simgrid/s4u/Mailbox.hpp>
#include <string>
#include <sstream>
#include "inputs.hpp"
#include "xbt/log.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]");
typedef unsigned int u32;
u32 max_attempts=0;
/// @brief Observation unit code
static void obs_unit(std::vector<std::string> args);
int main(int argc, char **argv) {
// Build engine
simgrid::s4u::Engine engine(&argc, argv);
engine.load_platform("platform.xml");
// Parse arguments
max_attempts=std::stoi(argv[1]);
XBT_INFO("-------------------------------------------------");
XBT_INFO("Sarting loosely coupled data dissemination experiments");
XBT_INFO("Number of wake attempts per OU is %d",max_attempts);
XBT_INFO("-------------------------------------------------");
u32 nObsUnit=simgrid::s4u::Engine::get_instance()->get_host_count();
for(u32 i=0;i<nObsUnit;i++){
std::vector<std::string> args;
std::ostringstream ss;
ss<< "ou" <<i;
simgrid::s4u::Actor::create("Sender", simgrid::s4u::Host::by_name(ss.str()), obs_unit, args);
}
// Setup/Run simulation
engine.run();
XBT_INFO("Simulation took %fs", simgrid::s4u::Engine::get_clock());
return (0);
}
static void obs_unit(std::vector<std::string> args) {
std::string selfName = simgrid::s4u::this_actor::get_host()->get_name();
Inputs i(selfName);
simgrid::s4u::Mailbox *m = simgrid::s4u::Mailbox::by_name("medium");
XBT_INFO("Deploying %s",selfName.c_str());
std::string msg("aloha");
double wake_interval=i.wake_interval;
for(u32 i=0;i<max_attempts;i++){
try
{
simgrid::s4u::this_actor::sleep_for(wake_interval);
}
catch (...)
{
XBT_INFO("Not send");
}
}
}