aboutsummaryrefslogtreecommitdiff
path: root/src/simulator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulator.cc')
-rw-r--r--src/simulator.cc51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/simulator.cc b/src/simulator.cc
index d122a5b..7b288e4 100644
--- a/src/simulator.cc
+++ b/src/simulator.cc
@@ -63,13 +63,14 @@ typedef unsigned int u32;
*/
class Payload{
public:
- Payload():hint(0),duration(0),HasHint(false),HisForward(false),HasData(false),DataSize(0){}
- Payload(Payload &p):hint(p.hint),duration(p.duration),HasHint(p.HasHint),DedicatedMailbox(p.DedicatedMailbox),HisForward(p.HisForward),HasData(p.HasData),DataSize(p.DataSize){}
+ Payload():hint(0),duration(0),HasHint(false),HisForward(false),HasData(false),DataSize(0),Abort(false){}
+ Payload(Payload &p):hint(p.hint),duration(p.duration),HasHint(p.HasHint),DedicatedMailbox(p.DedicatedMailbox),HisForward(p.HisForward),HasData(p.HasData),DataSize(p.DataSize),Abort(p.Abort){}
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;
+ bool Abort;
u32 DataSize;
std::string DedicatedMailbox; // Dedicated mailbox used by the sender/receiver
};
@@ -166,7 +167,9 @@ static void obs_node(std::vector<std::string> args) {
SEND(m_ded->put(p,p->DataSize,uptime)); // Send the actual hint
XBT_INFO("%s sent a hint successfully",CNAME);
}
- catch(...){}
+ catch(...){
+
+ }
}
// Send data if send hint mode is disable
@@ -187,17 +190,23 @@ static void obs_node(std::vector<std::string> args) {
try {
TRACK_UPTIME(m->put(p,0,FOR(1)));
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
- MODE_TX();
- if(i.extended){
- SEND(m_ded->put(p,p->DataSize));
+ Payload *ack=m_ded->get<Payload>();
+ if(!ack->Abort){
+ MODE_TX();
+ if(i.extended){
+ SEND(m_ded->put(p,p->DataSize));
+ }
+ else{
+ SEND(m_ded->put(p,p->DataSize,uptime));
+ }
+ XBT_INFO("%s sent data successfully",CNAME);
+ nSend++;
+ is_sender=(nSend<(i.n_nodes-1)); // Stop sending if all nodes received
+ isObserver=!is_sender; // Switch to observer mode if all nodes received the data
}
- else{
- SEND(m_ded->put(p,p->DataSize,uptime));
+ else {
+ simgrid::s4u::this_actor::sleep_for(FOR(1));
}
- XBT_INFO("%s sent data successfully",CNAME);
- nSend++;
- is_sender=(nSend<(i.n_nodes-1)); // Stop sending if all nodes received
- isObserver=!is_sender; // Switch to observer mode if all nodes received the data
}
catch(...){}
}
@@ -207,8 +216,11 @@ static void obs_node(std::vector<std::string> args) {
else if(!isObserver){
// Forward hint mode
if(forward_mode){
- if(hint_forward!=NULL && CLOCK < hint_forward->hint){
+ if(i.use_hint && hint_forward!=NULL && CLOCK < hint_forward->hint){
+ try {
FORWARD_HINT(FOR(0.3)); // Try forward for 5 seconds then switch to received mode
+ }
+ catch(...){}
}
}
else { // Receiving mode
@@ -233,6 +245,9 @@ static void obs_node(std::vector<std::string> args) {
}
} while(p->HisForward);
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
+ Payload *ack=new Payload();
+ ack->Abort=false;
+ m_ded->put(ack,0);
// Start receiving data
MODE_RX();
if(p->HasHint && !p->HasData){
@@ -285,12 +300,18 @@ static void obs_node(std::vector<std::string> args) {
} while(p->HisForward); // Ignore forwarded hint
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
// Start receiving hint from sender
- forward_only=true;
MODE_RX();
- if(p->HasHint){
+ if(p->HasData){
+ Payload *ack=new Payload();
+ ack->Abort=true;
+ m_ded->put(ack,0);
+ simgrid::s4u::this_actor::sleep_for(FOR(1));
+ }
+ else if(p->HasHint){
TRACK_UPTIME(p=m_ded->get<Payload>(uptime));
XBT_INFO("%s received a hint successfully",CNAME);
hint_forward=new Payload(*p); // Enable hint forwarding
+ forward_only=true;
}
else {
simgrid::s4u::this_actor::sleep_for(FOR(1));