diff options
Diffstat (limited to 'src/simulator.cc')
| -rw-r--r-- | src/simulator.cc | 63 |
1 files changed, 45 insertions, 18 deletions
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<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() |
