Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : MUTEX_UNLOCK is invisible for MC
[simgrid.git] / src / surf / network_cm02.cpp
index d7c41bb..fe4d32d 100644 (file)
@@ -192,7 +192,8 @@ void NetworkCm02Model::initialize()
                                                   SURF_LINK_FATPIPE, NULL));
 
   if (p_updateMechanism == UM_LAZY) {
-       p_actionHeap = new ActionHeap();
+       p_actionHeap = xbt_heap_new(8, NULL);
+       xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap);
        p_modifiedSet = new ActionLmmList();
        p_maxminSystem->keep_track = p_modifiedSet;
   }
@@ -228,10 +229,9 @@ NetworkLinkPtr NetworkCm02Model::createNetworkLink(const char *name,
 void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
 {
   NetworkCm02ActionPtr action;
-  while ((!p_actionHeap->empty())
-         && (double_equals(p_actionHeap->topKey(), now, sg_surf_precision))) {
-    action = (NetworkCm02ActionPtr) p_actionHeap->topValue();
-    p_actionHeap->pop();
+  while ((xbt_heap_size(p_actionHeap) > 0)
+         && (double_equals(xbt_heap_maxkey(p_actionHeap), now, sg_surf_precision))) {
+    action = (NetworkCm02ActionPtr) xbt_heap_pop(p_actionHeap);
     XBT_DEBUG("Something happened to action %p", action);
 #ifdef HAVE_TRACING
     if (TRACE_is_enabled()) {
@@ -255,22 +255,22 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
 #endif
 
     // if I am wearing a latency hat
-    if (action->getHeapActionType() == LATENCY) {
+    if (action->getHat() == LATENCY) {
       XBT_DEBUG("Latency paid for action %p. Activating", action);
       lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight);
-      action->heapRemove();
+      action->heapRemove(p_actionHeap);
       action->refreshLastUpdate();
 
         // if I am wearing a max_duration or normal hat
-    } else if (action->getHeapActionType() == MAX_DURATION ||
-        action->getHeapActionType() == NORMAL) {
+    } else if (action->getHat() == MAX_DURATION ||
+        action->getHat() == NORMAL) {
         // no need to communicate anymore
         // assume that flows that reached max_duration have remaining of 0
       XBT_DEBUG("Action %p finished", action);
       action->setRemains(0);
       action->finish();
       action->setState(SURF_ACTION_DONE);
-      action->heapRemove();
+      action->heapRemove(p_actionHeap);
 
       action->gapRemove();
     }
@@ -278,6 +278,79 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
   return;
 }
 
+
+void NetworkCm02Model::updateActionsStateFull(double now, double delta)
+{
+  NetworkCm02ActionPtr action;
+  ActionListPtr running_actions = getRunningActionSet();
+
+  for(ActionList::iterator it(running_actions->begin()), itNext=it, itend(running_actions->end())
+     ; it != itend ; it=itNext) {
+       ++itNext;
+
+    action = (NetworkCm02ActionPtr) &*it;
+    XBT_DEBUG("Something happened to action %p", action);
+      double deltap = delta;
+      if (action->m_latency > 0) {
+        if (action->m_latency > deltap) {
+          double_update(&(action->m_latency), deltap, sg_surf_precision);
+          deltap = 0.0;
+        } else {
+          double_update(&(deltap), action->m_latency, sg_surf_precision);
+          action->m_latency = 0.0;
+        }
+        if (action->m_latency == 0.0 && !(action->isSuspended()))
+          lmm_update_variable_weight(p_maxminSystem, action->getVariable(),
+              action->m_weight);
+      }
+  #ifdef HAVE_TRACING
+      if (TRACE_is_enabled()) {
+        int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
+        int i;
+        for (i = 0; i < n; i++){
+          lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
+                                                            action->getVariable(),
+                                                            i);
+          NetworkCm02LinkPtr link = static_cast<NetworkCm02LinkPtr>(lmm_constraint_id(constraint));
+          TRACE_surf_link_set_utilization(link->getName(),
+                                        action->getCategory(),
+                                        (lmm_variable_getvalue(action->getVariable())*
+                                            lmm_get_cnst_weight_from_var(p_maxminSystem,
+                                                action->getVariable(),
+                                                i)),
+                                        action->getLastUpdate(),
+                                        now - action->getLastUpdate());
+        }
+      }
+  #endif
+      if (!lmm_get_number_of_cnst_from_var
+          (p_maxminSystem, action->getVariable())) {
+        /* There is actually no link used, hence an infinite bandwidth.
+         * This happens often when using models like vivaldi.
+         * In such case, just make sure that the action completes immediately.
+         */
+        action->updateRemains(action->getRemains());
+      }
+    action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
+                  
+    if (action->getMaxDuration() != NO_MAX_DURATION)
+      action->updateMaxDuration(delta);
+      
+    if ((action->getRemains() <= 0) &&
+        (lmm_get_variable_weight(action->getVariable()) > 0)) {
+      action->finish();
+      action->setState(SURF_ACTION_DONE);
+      action->gapRemove();
+    } else if (((action->getMaxDuration() != NO_MAX_DURATION)
+        && (action->getMaxDuration() <= 0))) {
+      action->finish();
+      action->setState(SURF_ACTION_DONE);
+      action->gapRemove();
+    }
+  }
+  return;
+}
+
 ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
                                                 double size, double rate)
 {
@@ -327,6 +400,7 @@ ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
 
   action->m_rate = rate;
   if (p_updateMechanism == UM_LAZY) {
+    action->m_indexHeap = -1;
     action->m_lastUpdate = surf_get_clock();
   }
 
@@ -369,8 +443,7 @@ ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
       // add to the heap the event when the latency is payed
       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
                 action->m_latency + action->m_lastUpdate);
-
-      action->heapInsert(action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
+      action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
     }
   } else
     action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
@@ -541,6 +614,9 @@ void NetworkCm02Link::updateBandwidth(double value, double date){
                  (p_power.peak * p_power.scale);
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
+  lmm_element_t nextelem = NULL;
+  int numelem = 0;
+
   NetworkCm02ActionPtr action = NULL;
 
   p_power.peak = value;
@@ -552,7 +628,7 @@ void NetworkCm02Link::updateBandwidth(double value, double date){
   TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * p_power.peak * p_power.scale);
 #endif
   if (sg_weight_S_parameter > 0) {
-    while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
+    while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
       action = (NetworkCm02ActionPtr) lmm_variable_id(var);
       action->m_weight += delta;
       if (!action->isSuspended())
@@ -565,10 +641,12 @@ void NetworkCm02Link::updateLatency(double value, double date){
   double delta = value - m_latCurrent;
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
+  lmm_element_t nextelem = NULL;
+  int numelem = 0;
   NetworkCm02ActionPtr action = NULL;
 
   m_latCurrent = value;
-  while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
+  while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
     action = (NetworkCm02ActionPtr) lmm_variable_id(var);
     action->m_latCurrent += delta;
     action->m_weight += delta;
@@ -617,12 +695,12 @@ void NetworkCm02Action::updateRemainingLazy(double now)
     finish();
     setState(SURF_ACTION_DONE);
 
-    heapRemove();
+    heapRemove(getModel()->getActionHeap());
   } else if (((m_maxDuration != NO_MAX_DURATION)
       && (m_maxDuration <= 0))) {
     finish();
     setState(SURF_ACTION_DONE);
-    heapRemove();
+    heapRemove(getModel()->getActionHeap());
   }
 
   m_lastUpdate = now;