This commit is contained in:
Loic Guegan 2021-05-20 14:36:34 +02:00
parent a342ca0c89
commit e3c7d5219d
8 changed files with 1400 additions and 8897 deletions

View file

@ -70,11 +70,12 @@ bool is_data_rcv_ready(){
*/
class Payload{
public:
Payload():hint(0),duration(0),HasHint(false),HisForward(false){}
Payload():hint(0),duration(0),HasHint(false),HisForward(false),HasData(false){}
Payload(Payload &p):hint(p.hint),duration(p.duration),HasHint(p.HasHint),DedicatedMailbox(p.DedicatedMailbox),HisForward(p.HisForward){}
double hint; // The timestamp that should be used by the receiver
double duration; // The duration that should be used by the receiver
bool HasHint;
bool HasData;
bool HisForward;
std::string DedicatedMailbox; // Dedicated mailbox used by the sender/receiver
};
@ -140,6 +141,7 @@ static void obs_node(std::vector<std::string> args) {
u32 hint_added=0;
double totalUptime=0;
Payload *hint_forward=NULL;
bool init_issender=i.is_sender;
while(i.ShouldContinue()){
// Start by sleeping
XBT_INFO("%s is spleeping",CNAME);
@ -154,57 +156,62 @@ static void obs_node(std::vector<std::string> args) {
double upuntil=i.GetTS()+i.GetDuration();
bool forward_mode=false;
bool onlyf=false;
bool sendhint_mode=false;
while(uptime>0)
{
if(i.is_sender){
Payload *p=new Payload();
p->DedicatedMailbox="dedicated"+selfName;
// Add hint informations to the payload
if(i.use_hint && i.HasNext()){
double try_for=sendhint_mode ? 0.3 : 1;
try_for=try_for>uptime ? uptime : try_for; // Ensure we do not exceed uptime
try_for=(i.use_hint && i.HasNext()) ? try_for: uptime; // Ensure we shoud use hint otherwise only send data
// Send hint
if(i.use_hint && sendhint_mode && i.HasNext()){
Payload *p=new Payload();
p->DedicatedMailbox="hintmailbox"+selfName;
p->HasHint=true;
p->duration=i.GetNextDuration();
p->hint=i.GetNextTS();
}
try {
// First we send and instantaneous message
// This allow first to detect if their is a receiver
// (to not cause deadlock for the extended mode) and second
// to inform the receiver if he should get a hint first
TRACK_UPTIME(m->put(p,0,uptime));
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
// First send hint if it is required
if(p->HasHint){
TRACK_UPTIME(SEND(m_ded->put(p,i.hint_size,uptime)));
try {
TRACK_UPTIME(m->put(p,0,try_for));
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
MODE_TX();
SEND(m_ded->put(p,i.hint_size,uptime));
XBT_INFO("%s sent a hint successfully",CNAME);
}
MODE_TX();
// Then try sending the data
if(is_data_rcv_ready()){
catch(...){}
}
else{ // Send data
Payload *p=new Payload();
p->DedicatedMailbox="datamailbox"+selfName;
p->HasData=true;
p->HasHint=false;
if(i.use_hint && i.HasNext()){
p->HasHint=true;
p->duration=i.GetNextDuration();
p->hint=i.GetNextTS();
}
try {
TRACK_UPTIME(m->put(p,0,try_for));
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
MODE_TX();
if(i.extended){
SEND(m_ded->put(p,i.data_size));
SEND(m_ded->put(p,i.data_size));
}
else{
SEND(m_ded->put(p,i.data_size,uptime));
}
XBT_INFO("%s sent data successfully",CNAME);
nSend++;
i.is_sender=(nSend<(i.n_nodes-1));
isObserver=!i.is_sender;
}
else
throw "Attemps to send when no receiver available in extended mode";
// If we reach here, data has been sent successfully
XBT_INFO("%s sent data successfully",CNAME);
nSend++;
i.is_sender=(nSend<(i.n_nodes-1));
isObserver=!i.is_sender;
}
catch(...){
XBT_INFO("%s could not send any data",CNAME);
nSendFail++;
catch(...){}
}
sendhint_mode=!sendhint_mode; // Switch to send hint mode
}
else if(!isObserver){
// Here we try to forward hint for 1 sec and try to receive data for 5 secs
double try_for=forward_mode ? 1 : 1;
double try_for=forward_mode ? 0.3 : 1;
try_for=try_for>uptime ? uptime : try_for; // Ensure we do not exceed uptime
// Forward hint mode
if(forward_mode){
@ -238,24 +245,36 @@ static void obs_node(std::vector<std::string> args) {
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
// Start receiving data
MODE_RX();
if(p->HasHint){
if(p->HasHint && !p->HasData){
TRACK_UPTIME(p=m_ded->get<Payload>(uptime));
XBT_INFO("%s received a hint successfully",CNAME);
hint=new Payload(*p); // Save hint
hint_forward=new Payload(*p); // Enable hint forwarding
hintReceived=true;
if(CLOCK < p->hint){
i.AddEvent(p->hint, p->duration);
hint_forward=new Payload(*p);
hint_added++;
}
}
data_ready[id]=true; // Say to the receiver that he can send (to avoid deadlock in extended mode)
if(i.extended){
p=m_ded->get<Payload>(); // Fetch data until sended
else {
if(i.extended){
p=m_ded->get<Payload>(); // Fetch data until sended
}
else
p=m_ded->get<Payload>(uptime); // Fetch data until sended or uptime expire
// If we reach here, data has been received successfully
XBT_INFO("%s received data successfully",CNAME);
if(p->HasHint){
XBT_INFO("%s received a hint along with data successfully",CNAME);
hint=new Payload(*p); // Save hint
hint_forward=new Payload(*p); // Enable hint forwarding
hintReceived=true;
}
nDataRcv++;
isObserver=true;
i.is_sender=false;
}
else
p=m_ded->get<Payload>(uptime); // Fetch data until sended or uptime expire
// If we reach here, data has been received successfully
XBT_INFO("%s received data successfully",CNAME);
nDataRcv++;
isObserver=true;
i.is_sender=false;
}catch(...){
XBT_INFO("%s could not receive any data",CNAME);
@ -265,7 +284,6 @@ static void obs_node(std::vector<std::string> args) {
hint_added++;
}
}
data_ready[id]=false;
}
forward_mode=!forward_mode; // Toggle mode (go back and forth between receiving and forwarding)
}
@ -319,5 +337,5 @@ static void obs_node(std::vector<std::string> args) {
}
// Done
MODE_OFF()
XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|isSender:%d|nSend:%d|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d|totalUptime:%f|seed:%d|hint_added:%d)",CNAME,CNAME,i.is_sender,nSend,nWakeUp,nDataRcv,nSendFail,nRcvFail,totalUptime,i.seed,hint_added);
XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|isSender:%d|nSend:%d|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d|totalUptime:%f|seed:%d|hint_added:%d)",CNAME,CNAME,init_issender,nSend,nWakeUp,nDataRcv,nSendFail,nRcvFail,totalUptime,i.seed,hint_added);
}