Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make Model::actionHeap_ private.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 12 Nov 2017 15:13:00 +0000 (16:13 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 12 Nov 2017 22:03:59 +0000 (23:03 +0100)
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/network_cm02.cpp
src/surf/network_interface.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp

index 40d145e..aa47bff 100644 (file)
@@ -55,8 +55,6 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel()
   maxminSystem_ = lmm_system_new(selectiveUpdate_);
 
   if (getUpdateMechanism() == UM_LAZY) {
-    actionHeap_ = xbt_heap_new(8, nullptr);
-    xbt_heap_set_update_callback(actionHeap_,  surf_action_lmm_update_index_heap);
     modifiedSet_ = new ActionLmmList();
     maxminSystem_->keep_track = modifiedSet_;
   }
@@ -66,7 +64,6 @@ CpuCas01Model::~CpuCas01Model()
 {
   lmm_system_free(maxminSystem_);
   maxminSystem_ = nullptr;
-  xbt_heap_free(actionHeap_);
   delete modifiedSet_;
 
   surf_cpu_model_pm = nullptr;
index e36d98c..8818c21 100644 (file)
@@ -331,9 +331,6 @@ CpuTiModel::CpuTiModel() : CpuModel()
   runningActionSetThatDoesNotNeedBeingChecked_ = new ActionList();
 
   modifiedCpu_ = new CpuTiList();
-
-  actionHeap_ = xbt_heap_new(8, nullptr);
-  xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap);
 }
 
 CpuTiModel::~CpuTiModel()
@@ -341,7 +338,6 @@ CpuTiModel::~CpuTiModel()
   surf_cpu_model_pm = nullptr;
   delete runningActionSetThatDoesNotNeedBeingChecked_;
   delete modifiedCpu_;
-  xbt_heap_free(actionHeap_);
 }
 
 Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host, std::vector<double>* speedPerPstate, int core)
@@ -363,8 +359,8 @@ double CpuTiModel::nextOccuringEvent(double now)
   }
 
 /* get the min next event if heap not empty */
-  if (xbt_heap_size(actionHeap_) > 0)
-    min_action_duration = xbt_heap_maxkey(actionHeap_) - now;
+  if (xbt_heap_size(getActionHeap()) > 0)
+    min_action_duration = xbt_heap_maxkey(getActionHeap()) - now;
 
   XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
 
@@ -373,8 +369,8 @@ double CpuTiModel::nextOccuringEvent(double now)
 
 void CpuTiModel::updateActionsState(double now, double /*delta*/)
 {
-  while ((xbt_heap_size(actionHeap_) > 0) && (xbt_heap_maxkey(actionHeap_) <= now)) {
-    CpuTiAction* action = static_cast<CpuTiAction*>(xbt_heap_pop(actionHeap_));
+  while ((xbt_heap_size(getActionHeap()) > 0) && (xbt_heap_maxkey(getActionHeap()) <= now)) {
+    CpuTiAction* action = static_cast<CpuTiAction*>(xbt_heap_pop(getActionHeap()));
     XBT_DEBUG("Action %p: finish", action);
     action->finish(Action::State::done);
     /* set the remains to 0 due to precision problems when updating the remaining amount */
index 3761084..35db28a 100644 (file)
@@ -153,8 +153,6 @@ NetworkCm02Model::NetworkCm02Model()
   loopback_     = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
 
   if (getUpdateMechanism() == UM_LAZY) {
-    actionHeap_ = xbt_heap_new(8, nullptr);
-    xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap);
     modifiedSet_ = new ActionLmmList();
     maxminSystem_->keep_track = modifiedSet_;
   }
@@ -173,10 +171,10 @@ LinkImpl* NetworkCm02Model::createLink(const std::string& name, double bandwidth
 
 void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
 {
-  while ((xbt_heap_size(actionHeap_) > 0)
-         && (double_equals(xbt_heap_maxkey(actionHeap_), now, sg_surf_precision))) {
+  while ((xbt_heap_size(getActionHeap()) > 0) &&
+         (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) {
 
-    NetworkCm02Action *action = static_cast<NetworkCm02Action*> (xbt_heap_pop(actionHeap_));
+    NetworkCm02Action* action = static_cast<NetworkCm02Action*>(xbt_heap_pop(getActionHeap()));
     XBT_DEBUG("Something happened to action %p", action);
     if (TRACE_is_enabled()) {
       int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable());
@@ -195,7 +193,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
     if (action->getHat() == LATENCY) {
       XBT_DEBUG("Latency paid for action %p. Activating", action);
       lmm_update_variable_weight(maxminSystem_, action->getVariable(), action->weight_);
-      action->heapRemove(actionHeap_);
+      action->heapRemove(getActionHeap());
       action->refreshLastUpdate();
 
         // if I am wearing a max_duration or normal hat
@@ -205,7 +203,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
       XBT_DEBUG("Action %p finished", action);
       action->setRemains(0);
       action->finish(Action::State::done);
-      action->heapRemove(actionHeap_);
+      action->heapRemove(getActionHeap());
     }
   }
 }
@@ -318,7 +316,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
     if (getUpdateMechanism() == UM_LAZY) {
       // add to the heap the event when the latency is payed
       XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency_ + action->getLastUpdate());
-      action->heapInsert(actionHeap_, action->latency_ + action->getLastUpdate(), route.empty() ? NORMAL : LATENCY);
+      action->heapInsert(getActionHeap(), action->latency_ + action->getLastUpdate(), route.empty() ? NORMAL : LATENCY);
     }
   } else
     action->setVariable(lmm_variable_new(maxminSystem_, action, 1.0, -1.0, constraints_per_variable));
index a7803a9..2bbbd86 100644 (file)
@@ -63,7 +63,6 @@ namespace simgrid {
     NetworkModel::~NetworkModel()
     {
       lmm_system_free(maxminSystem_);
-      xbt_heap_free(actionHeap_);
       delete modifiedSet_;
     }
 
index f9c9679..13ee74b 100644 (file)
@@ -365,12 +365,14 @@ Model::Model()
   doneActionSet_ = new ActionList();
 
   modifiedSet_ = nullptr;
-  actionHeap_ = nullptr;
+  actionHeap_      = xbt_heap_new(8, nullptr);
+  xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap);
   updateMechanism_ = UM_UNDEFINED;
   selectiveUpdate_ = 0;
 }
 
 Model::~Model(){
+  xbt_heap_free(actionHeap_);
   delete readyActionSet_;
   delete runningActionSet_;
   delete failedActionSet_;
index f569ce7..1ace36d 100644 (file)
@@ -333,7 +333,6 @@ protected:
   ActionLmmListPtr modifiedSet_;
   lmm_system_t maxminSystem_ = nullptr;
   bool selectiveUpdate_;
-  xbt_heap_t actionHeap_;
 
 private:
   e_UM_t updateMechanism_ = UM_UNDEFINED;
@@ -341,6 +340,7 @@ private:
   ActionList* runningActionSet_; /**< Actions in state SURF_ACTION_RUNNING */
   ActionList* failedActionSet_; /**< Actions in state SURF_ACTION_FAILED */
   ActionList* doneActionSet_; /**< Actions in state SURF_ACTION_DONE */
+  xbt_heap_t actionHeap_;
 };
 
 }