diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-05-09 11:07:16 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-05-09 11:07:16 +0200 |
| commit | 51d0c256a349f147b41221ac82932371f2037341 (patch) | |
| tree | 154469e93ac08670e933238d2e66e7909a626f20 /src/simulator.cc | |
| parent | 69e881864268a4d7ec892159f6185f475cc188aa (diff) | |
Debug and add scenarios in paper
Diffstat (limited to 'src/simulator.cc')
| -rw-r--r-- | src/simulator.cc | 135 |
1 files changed, 72 insertions, 63 deletions
diff --git a/src/simulator.cc b/src/simulator.cc index b34a95b..87cbe84 100644 --- a/src/simulator.cc +++ b/src/simulator.cc @@ -92,6 +92,7 @@ static void obs_node(std::vector<std::string> args) { u32 nDataRcv=0; u32 nSendFail=0; u32 nRcvFail=0; + u32 nSend=0; while(i.ShouldContinue()){ XBT_INFO("%s is spleeping",selfName.c_str()); MODE_OFF(); @@ -100,73 +101,81 @@ static void obs_node(std::vector<std::string> args) { XBT_INFO("%s wakes up",selfName.c_str()); // Doing wake up stuff - try { - if(isSender){ // If I am a sender - Payload *p=new Payload(); - p->node=selfName; - if(useHint&&i.HasNext()){ - p->containsHint=true; - p->hint=i.GetNextTS(); - p->duration=i.GetNextDuration(); + double uptime=i.GetDuration(); + 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 + Payload *p=new Payload(); + p->node=selfName; + if(useHint&&i.HasNext()){ + p->containsHint=true; + p->hint=i.GetNextTS(); + p->duration=i.GetNextDuration(); + } + if(i.extended){ + // We use a trick here + // First we send an instantaneous message (size=0) with the usual timeout + // to check whether there is a receiver! + // If there is one, we are sure that a put in the "medium"+selfName + // will not lead to a deadlock (cf anchor:5623) and we are using a exclusive + // channel (to avoid other receivers to get the message) + m->put(p,0,uptime); + simgrid::s4u::Mailbox *m_ext= simgrid::s4u::Mailbox::by_name("medium"+selfName); + MODE_TX(); + m_ext->put(p,data_size); + } + else{ + MODE_TX(); + m->put(p,data_size,uptime); + } + nSend++; + isSender=(nSend<(i.n_nodes-1)); + isObserver=!isSender; + XBT_INFO("%s sent data successfully",selfName.c_str()); } - if(i.extended){ - // We use a trick here - // First we send an instantaneous message (size=0) with the usual timeout - // to check whether there is a receiver! - // If there is one, we are sure that a put in the "medium"+selfName - // will not lead to a deadlock (cf anchor:5623) and we are using a exclusive - // channel (to avoid other receivers to get the message) - m->put(p,0,i.GetDuration()); - simgrid::s4u::Mailbox *m_ext= simgrid::s4u::Mailbox::by_name("medium"+selfName); - MODE_TX(); - m_ext->put(p,data_size); + else if (!isObserver){ + Payload* p; + if(i.extended){ + // anchor:5623 We can see here that + // 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>(); + } + else{ + MODE_RX(); + p=m->get<Payload>(uptime); + } + 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{ - MODE_TX(); - m->put(p,data_size,i.GetDuration()); + else { + XBT_INFO("%s is observing his environment...",selfName.c_str()); + MODE_ON(); + simgrid::s4u::this_actor::sleep_for(uptime); } - XBT_INFO("%s sent data successfully",selfName.c_str()); } - else if (!isObserver){ - Payload* p; - if(i.extended){ - // anchor:5623 We can see here that - // 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>(i.GetDuration()); - 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>(i.GetDuration()); - } - 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 and switch to forwarding mode",selfName.c_str()); - } - isObserver=true; // Now we received the data we switch to observer + catch (...) + { + if(isSender){ + XBT_INFO("%s could not send any data",selfName.c_str()); + nSendFail++; + } + else{ + XBT_INFO("%s could not receive any data",selfName.c_str()); + nRcvFail++; + } } - else { - XBT_INFO("%s is observing his environment...",selfName.c_str()); - simgrid::s4u::this_actor::sleep_until(i.GetDuration()); - } - } - catch (...) - { - if(isSender){ - XBT_INFO("%s could not send any data",selfName.c_str()); - nSendFail++; - } - else{ - XBT_INFO("%s could not receive any data",selfName.c_str()); - nRcvFail++; - } + uptime=(i.GetTS()+i.GetDuration())-simgrid::s4u::Engine::get_clock(); } // Load next event i.GotoNextEvent(); @@ -174,5 +183,5 @@ static void obs_node(std::vector<std::string> args) { } // Done MODE_OFF() - XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d|simkey:%s|seed:%d)",selfName.c_str(),selfName.c_str(),nWakeUp,nDataRcv,nSendFail,nRcvFail,i.simkey.c_str(),i.seed); + XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|nSend:%d|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d|simkey:%s|seed:%d)",selfName.c_str(),selfName.c_str(),nSend,nWakeUp,nDataRcv,nSendFail,nRcvFail,i.simkey.c_str(),i.seed); }
\ No newline at end of file |
