From fd4197731a5f8bb5af76361edac5a6038f06c9ad Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 11 May 2021 17:17:49 +0200 Subject: Correct simulations --- src/Inputs.cc | 6 +++--- src/scenarios.cc | 14 ++++++++----- src/simulator.cc | 63 ++++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 57 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/Inputs.cc b/src/Inputs.cc index bef8b6f..9220e36 100644 --- a/src/Inputs.cc +++ b/src/Inputs.cc @@ -156,14 +156,14 @@ void Inputs::GeneratePlatform(std::string p){ pf << "\n"; pf << "\n"; pf << "\n \n"; - pf << " \n"; + pf << " \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 << " \n"; diff --git a/src/scenarios.cc b/src/scenarios.cc index 3102e3d..2c839d1 100644 --- a/src/scenarios.cc +++ b/src/scenarios.cc @@ -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] << " " << - " " << + " " << 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()); diff --git a/src/simulator.cc b/src/simulator.cc index 6b3e5b0..2d78cf6 100644 --- a/src/simulator.cc +++ b/src/simulator.cc @@ -89,6 +89,8 @@ static void obs_node(std::vector 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 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 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 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(uptime); - simgrid::s4u::Mailbox *m_ext_sender = simgrid::s4u::Mailbox::by_name("medium"+p->node); - MODE_RX(); - p=m_ext_sender->get(); + 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(); + } } else{ MODE_RX(); p=m->get(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 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 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() -- cgit v1.2.3