#include <cstdlib>
#include <iostream>
#include <string>
class Sender {
long messages_count;
long receivers_count;
double msg_size;
public:
explicit Sender(std::vector<std::string> args)
{
xbt_assert(args.size() == 4,
"Expecting 3 parameters from the XML deployment file but got %zu", args.size());
messages_count = std::stol(args[1]);
msg_size = std::stod(args[2]);
receivers_count = std::stol(args[3]);
}
void operator()()
{
std::vector<simgrid::s4u::CommPtr> pending_comms;
for (int i = 0; i < messages_count; i++) {
XBT_INFO(
"Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
pending_comms.push_back(comm);
}
for (int i = 0; i < receivers_count; i++) {
pending_comms.push_back(comm);
XBT_INFO(
"Send 'finalize' to 'receiver-%ld'", i % receivers_count);
}
XBT_INFO(
"Done dispatching all messages");
}
};
class Receiver {
public:
explicit Receiver(std::vector<std::string> args)
{
xbt_assert(args.size() == 2,
"Expecting one parameter from the XML deployment file but got %zu", args.size());
}
void operator()()
{
for (bool cont = true; cont;) {
XBT_INFO(
"I got a '%s'.", received->c_str());
cont = (*received != "finalize");
delete received;
}
}
};
{
xbt_assert(argc > 2,
"Usage: %s platform_file deployment_file\n", argv[0]);
e.registerFunction<Sender>("sender");
e.registerFunction<Receiver>("receiver");
e.loadPlatform(argv[1]);
e.loadDeployment(argv[2]);
e.run();
return 0;
}