Refresh all scenarios

This commit is contained in:
Loic Guegan 2021-05-12 10:05:19 +02:00
parent fd4197731a
commit 454d01dc84
8 changed files with 16597 additions and 16617 deletions

View file

@ -15,6 +15,15 @@
#define MODE_ON() simgrid::s4u::this_actor::get_host()->set_pstate(1);
#define MODE_RX() simgrid::s4u::this_actor::get_host()->set_pstate(2);
#define MODE_TX() simgrid::s4u::this_actor::get_host()->set_pstate(3);
#define CLOCK (simgrid::s4u::Engine::get_clock())
#define TRACK_UPTIME(instruction) \
{ \
double uptimeTrack=CLOCK; \
instruction; \
uptimeTrack=CLOCK-uptimeTrack; \
uptime-=uptimeTrack; \
uptime=uptime > 0 ? uptime : 0; \
}
/// @brief Required by SimGrid
XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]");
@ -27,12 +36,11 @@ typedef unsigned int u32;
*/
class Payload{
public:
Payload():hint(0),duration(0),containsHint(false),size(0){}
Payload():hint(0),duration(0),HasHint(false){}
double hint;
double duration;
int size;
bool containsHint;
std::string node;
bool HasHint;
std::string DedicatedMailbox;
};
/// @brief Observation node code
@ -82,15 +90,8 @@ static void obs_node(std::vector<std::string> args) {
simgrid::s4u::Mailbox *m = simgrid::s4u::Mailbox::by_name("medium");
XBT_INFO("Deploying observation node %s",selfName.c_str());
// Init convenient variables
bool isSender=i.is_sender;
bool useHint=i.use_hint;
bool isObserver=false;
u32 data_size=i.data_size;
// Starting node
bool hintReceived=false;
Payload *hint;
bool isObserver=false;
u32 nWakeUp=0;
u32 nDataRcv=0;
u32 nSendFail=0;
@ -98,6 +99,7 @@ static void obs_node(std::vector<std::string> args) {
u32 nSend=0;
double totalUptime=0;
while(i.ShouldContinue()){
// Start by sleeping
XBT_INFO("%s is spleeping",selfName.c_str());
MODE_OFF();
simgrid::s4u::this_actor::sleep_until(i.GetTS());
@ -106,113 +108,84 @@ static void obs_node(std::vector<std::string> args) {
// Doing wake up stuff
double uptime=i.GetDuration();
double startUptime=simgrid::s4u::Engine::get_clock();
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
double upsince=simgrid::s4u::Engine::get_clock();
double upuntil=i.GetTS()+i.GetDuration();
while(uptime>0.0000001)
{
if(i.is_sender){
Payload *p=new Payload();
p->DedicatedMailbox="dedicated"+selfName;
if(i.use_hint && i.HasNext()){
p->HasHint=i.use_hint;
p->duration=i.GetNextDuration();
p->hint=i.GetNextTS();
}
MODE_ON();
try {
TRACK_UPTIME(m->put(p,0,uptime)); // Send instantaneous message
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
// First send hint if it is required
if(p->HasHint){
TRACK_UPTIME(m_ded->put(p,i.hint_size,uptime));
XBT_INFO("%s sent a hint successfully",selfName.c_str());
}
Payload *p=new Payload();
p->node=selfName;
p->size=data_size;
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,p->size);
}
else{
MODE_TX();
m->put(p,p->size,uptime);
}
nSend++;
isSender=(nSend<(i.n_nodes-1));
isObserver=!isSender;
// Then try sending the data
MODE_TX();
if(i.extended)
m_ded->put(p,i.data_size);
else
m_ded->put(p,i.data_size,uptime);
XBT_INFO("%s sent data successfully",selfName.c_str());
nSend++;
i.is_sender=(nSend<(i.n_nodes-1));
isObserver=!i.is_sender;
}
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);
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());
}
}
}
else {
XBT_INFO("%s is observing his environment...",selfName.c_str());
MODE_ON();
simgrid::s4u::this_actor::sleep_for(uptime);
}
}
catch (...)
{
if(isSender){
catch(...){
XBT_INFO("%s could not send any data",selfName.c_str());
nSendFail++;
}
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++;
}
}
}
uptime=(i.GetTS()+i.GetDuration())-simgrid::s4u::Engine::get_clock();
else if(!isObserver){
Payload *p;
Payload *hint; // To Save the received hint
bool hintReceived=false;
MODE_ON();
try {
TRACK_UPTIME(p=m->get<Payload>(uptime)); // Get the instantaneous message
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
if(p->HasHint){
TRACK_UPTIME(p=m_ded->get<Payload>(uptime));
XBT_INFO("%s received a hint successfully",selfName.c_str());
hintReceived=true;
}
MODE_RX();
if(i.extended)
p=m_ded->get<Payload>(); // Fetch data
else
p=m_ded->get<Payload>(uptime); // Fetch data
XBT_INFO("%s received data successfully",selfName.c_str());
nDataRcv++;
isObserver=true;
i.is_sender=false;
}catch(...){
XBT_INFO("%s could not receive any data",selfName.c_str());
nRcvFail++;
if(hintReceived)
i.AddEvent(p->hint, p->duration); // Add the hint to the event list
}
}
else {
XBT_INFO("%s is observing his environment...",selfName.c_str());
MODE_ON();
simgrid::s4u::this_actor::sleep_for(uptime);
}
uptime=upuntil-CLOCK; // Note that uptime can be < 0 in extended mode
}
// Load next event
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
}
totalUptime+=CLOCK-upsince;
}
// Done
MODE_OFF()