Correct simulations

This commit is contained in:
Loic Guegan 2021-05-11 17:17:49 +02:00
parent 1477290330
commit fd4197731a
9 changed files with 16603 additions and 35769 deletions

View file

@ -156,14 +156,14 @@ void Inputs::GeneratePlatform(std::string p){
pf << "<?xml version='1.0'?>\n";
pf << "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n";
pf << "<platform version=\"4.1\">\n <AS id=\"AS0\" routing=\"Cluster\">\n";
pf << " <link id=\"link\" bandwidth=\""<<d["bitrate"].GetString()<<"\" latency=\"0ms\" sharing_policy=\"SHARED\"></link>\n";
pf << " <link id=\"link\" bandwidth=\""<<d["bitrate"].GetString()<<"\" latency=\""<<d["latency"].GetString()<<"\" sharing_policy=\"SHARED\"></link>\n";
for (Value::ConstMemberIterator itr = d["nodes"].MemberBegin(); itr != d["nodes"].MemberEnd(); ++itr)
{
std::string name=itr->name.GetString();
double power_off=d["nodes"][itr->name.GetString()]["power_off"].GetDouble();
double power_on=d["nodes"][itr->name.GetString()]["power_on"].GetDouble();
double power_rx=d["nodes"][itr->name.GetString()]["power_rx"].GetDouble();
double power_tx=d["nodes"][itr->name.GetString()]["power_tx"].GetDouble();
double power_rx=power_on+d["nodes"][itr->name.GetString()]["power_rx"].GetDouble();
double power_tx=power_on+d["nodes"][itr->name.GetString()]["power_tx"].GetDouble();
// Create node
pf << " <host id=\""<<name<<"\" speed=\"100.0f,100.0f,100.0f,100.0f\" pstate=\"0\">\n";

View file

@ -17,10 +17,10 @@ using namespace rapidjson;
int main(int argc, char **argv){
// Setup seed
if(argc!=15){
if(argc!=16){
cerr << "Usage: " << argv[0] <<
" <seed> <simtime> <wakeupevery> <wakeupfor> <n_nodes>" <<
" <extended> <hint> <poff> <pon> <prx> <ptx> <datasize> <bitrate> <hintsize>" <<
" <extended> <hint> <poff> <pon> <prx> <ptx> <datasize> <bitrate> <hintsize> <latency>" <<
endl;
exit(1);
}
@ -40,6 +40,7 @@ int main(int argc, char **argv){
unsigned int datasize=atoi(argv[12]);
string bitrate(argv[13]);
unsigned int hintsize=atoi(argv[14]);
string latency(argv[15]);
// Setup seed
@ -49,9 +50,12 @@ int main(int argc, char **argv){
Document d;
d.SetObject();
d.AddMember("seed",Value().SetInt(seed),d.GetAllocator());
Value simkeyValue;
simkeyValue.SetString(bitrate.c_str(),bitrate.size(),d.GetAllocator());
d.AddMember("bitrate",simkeyValue,d.GetAllocator());
Value bitrateValue;
bitrateValue.SetString(bitrate.c_str(),bitrate.size(),d.GetAllocator());
d.AddMember("bitrate",bitrateValue,d.GetAllocator());
Value latencyValue;
latencyValue.SetString(latency.c_str(),latency.size(),d.GetAllocator());
d.AddMember("latency",latencyValue,d.GetAllocator());
d.AddMember("extended",extended,d.GetAllocator());
d.AddMember("hint_size",hintsize,d.GetAllocator());

View file

@ -89,6 +89,8 @@ static void obs_node(std::vector<std::string> args) {
u32 data_size=i.data_size;
// Starting node
bool hintReceived=false;
Payload *hint;
u32 nWakeUp=0;
u32 nDataRcv=0;
u32 nSendFail=0;
@ -108,15 +110,23 @@ static void obs_node(std::vector<std::string> args) {
while(uptime>0.00001){ // Ensure not infinite loop even if it should not happend (we loose accuracy here but just in case)
try {
if(isSender){ // If I am a sender
if(useHint&&i.HasNext()){
Payload *phint=new Payload();
phint->containsHint=true;
phint->hint=i.GetNextTS();
phint->duration=i.GetNextDuration();
phint->size=i.hint_size;
// Send data and update uptime
double hint_duration=simgrid::s4u::Engine::get_clock();
m->put(phint,phint->size,uptime);
hint_duration=simgrid::s4u::Engine::get_clock()-hint_duration;
hint_duration=hint_duration>0 ? hint_duration : 0; // Ensure valid hint_duration
uptime-=hint_duration;
uptime=uptime>0 ? uptime:0; // Ensure valid uptime
}
Payload *p=new Payload();
p->node=selfName;
p->size=data_size;
if(useHint&&i.HasNext()){
p->containsHint=true;
p->hint=i.GetNextTS();
p->duration=i.GetNextDuration();
p->size=data_size+i.hint_size;
}
if(i.extended){
// We use a trick here
// First we send an instantaneous message (size=0) with the usual timeout
@ -137,6 +147,7 @@ static void obs_node(std::vector<std::string> args) {
isSender=(nSend<(i.n_nodes-1));
isObserver=!isSender;
XBT_INFO("%s sent data successfully",selfName.c_str());
}
else if (!isObserver){
Payload* p;
@ -145,23 +156,31 @@ static void obs_node(std::vector<std::string> args) {
// we first receive the instantaneous message
// and then we use a mailbox specific to the sender (to have an exclusive channel)
p=m->get<Payload>(uptime);
simgrid::s4u::Mailbox *m_ext_sender = simgrid::s4u::Mailbox::by_name("medium"+p->node);
MODE_RX();
p=m_ext_sender->get<Payload>();
if(p->containsHint){
hintReceived=true;
hint=p;
XBT_INFO("%s received and hint of %f",selfName.c_str(),p->hint);
}
else {
simgrid::s4u::Mailbox *m_ext_sender = simgrid::s4u::Mailbox::by_name("medium"+p->node);
MODE_RX();
p=m_ext_sender->get<Payload>();
}
}
else{
MODE_RX();
p=m->get<Payload>(uptime);
nDataRcv++; // New data received
if(p->containsHint){
hintReceived=true;
hint=p;
XBT_INFO("%s received and hint of %f",selfName.c_str(),p->hint);
}
else{
isObserver=true; // Now we received the data we switch to observer
XBT_INFO("%s received data successfully",selfName.c_str());
}
}
nDataRcv++; // New data received
if(p->containsHint){
XBT_INFO("%s received and hint of %f",selfName.c_str(),p->hint);
i.AddEvent(p->hint, p->duration); // Schedule a new wake up time
}
else{
XBT_INFO("%s received data successfully",selfName.c_str());
}
isObserver=true; // Now we received the data we switch to observer
}
else {
XBT_INFO("%s is observing his environment...",selfName.c_str());
@ -177,6 +196,10 @@ static void obs_node(std::vector<std::string> args) {
}
else{
XBT_INFO("%s could not receive any data",selfName.c_str());
if(hintReceived){
hintReceived=false;
i.AddEvent(hint->hint, hint->duration); // Schedule a new wake up time
}
nRcvFail++;
}
}
@ -186,6 +209,10 @@ static void obs_node(std::vector<std::string> args) {
i.GotoNextEvent();
nWakeUp++; // Increase the number of wake up
totalUptime+=simgrid::s4u::Engine::get_clock()-startUptime;
if(hintReceived){
hintReceived=false;
i.AddEvent(hint->hint, hint->duration); // Schedule a new wake up time
}
}
// Done
MODE_OFF()