Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify some indirections.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 4 Dec 2017 21:30:14 +0000 (22:30 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 4 Dec 2017 22:41:13 +0000 (23:41 +0100)
src/surf/cpu_cas01.cpp
src/surf/cpu_cas01.hpp
src/surf/cpu_ti.cpp
src/surf/cpu_ti.hpp

index 27ccc86..1dfe275 100644 (file)
@@ -53,8 +53,7 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel()
     xbt_die("Unsupported optimization (%s) for this model", optim.c_str());
   }
 
-  p_cpuRunningActionSetThatDoesNotNeedBeingChecked = new ActionList();
-  maxminSystem_                                    = new simgrid::kernel::lmm::s_lmm_system_t(selectiveUpdate_);
+  maxminSystem_ = new simgrid::kernel::lmm::s_lmm_system_t(selectiveUpdate_);
 
   if (getUpdateMechanism() == UM_LAZY) {
     modifiedSet_ = new ActionLmmList();
@@ -69,8 +68,6 @@ CpuCas01Model::~CpuCas01Model()
   delete modifiedSet_;
 
   surf_cpu_model_pm = nullptr;
-
-  delete p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
 }
 
 Cpu *CpuCas01Model::createCpu(simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)
@@ -186,7 +183,7 @@ CpuAction *CpuCas01::sleep(double duration)
   if (duration < 0) { // NO_MAX_DURATION
     /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */
     simgrid::xbt::intrusive_erase(*action->getStateSet(), *action);
-    action->stateSet_ = static_cast<CpuCas01Model*>(model())->p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
+    action->stateSet_ = &static_cast<CpuCas01Model*>(model())->p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
     action->getStateSet()->push_back(*action);
   }
 
index 6309e17..a7c2202 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2016. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2013-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -28,7 +28,7 @@ public:
   ~CpuCas01Model() override;
 
   Cpu *createCpu(simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core) override;
-  ActionList *p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
+  ActionList p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
 };
 
 /************
index d36dff6..3fc88fe 100644 (file)
@@ -327,18 +327,9 @@ void surf_cpu_model_init_ti()
 namespace simgrid {
 namespace surf {
 
-CpuTiModel::CpuTiModel() : CpuModel()
-{
-  runningActionSetThatDoesNotNeedBeingChecked_ = new ActionList();
-
-  modifiedCpu_ = new CpuTiList();
-}
-
 CpuTiModel::~CpuTiModel()
 {
   surf_cpu_model_pm = nullptr;
-  delete runningActionSetThatDoesNotNeedBeingChecked_;
-  delete modifiedCpu_;
 }
 
 Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host, std::vector<double>* speedPerPstate, int core)
@@ -351,7 +342,7 @@ double CpuTiModel::nextOccuringEvent(double now)
   double min_action_duration = -1;
 
   /* iterates over modified cpus to update share resources */
-  for (auto it = std::begin(*modifiedCpu_); it != std::end(*modifiedCpu_);) {
+  for (auto it = std::begin(modifiedCpu_); it != std::end(modifiedCpu_);) {
     CpuTi& ti = *it;
     ++it; // increment iterator here since the following call to ti.updateActionsFinishTime() may invalidate it
     ti.updateActionsFinishTime(now);
@@ -388,8 +379,6 @@ CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, std::vector<double> *s
   xbt_assert(core==1,"Multi-core not handled by this model yet");
   coresAmount_ = core;
 
-  actionSet_ = new ActionTiList();
-
   speed_.peak = speedPerPstate->front();
   XBT_DEBUG("CPU create: peak=%f", speed_.peak);
 
@@ -400,7 +389,6 @@ CpuTi::~CpuTi()
 {
   modified(false);
   delete speedIntegratedTrace_;
-  delete actionSet_;
 }
 void CpuTi::setSpeedTrace(tmgr_trace_t trace)
 {
@@ -451,7 +439,7 @@ void CpuTi::apply_event(tmgr_trace_event_t event, double value)
       double date = surf_get_clock();
 
       /* put all action running on cpu to failed */
-      for (CpuTiAction& action : *actionSet_) {
+      for (CpuTiAction& action : actionSet_) {
         if (action.getState() == Action::State::running || action.getState() == Action::State::ready ||
             action.getState() == Action::State::not_in_the_system) {
           action.setFinishTime(date);
@@ -475,7 +463,7 @@ void CpuTi::updateActionsFinishTime(double now)
   /* update remaining amount of actions */
   updateRemainingAmount(now);
 
-  for (CpuTiAction const& action : *actionSet_) {
+  for (CpuTiAction const& action : actionSet_) {
     /* action not running, skip it */
     if (action.getStateSet() != surf_cpu_model_pm->getRunningActionSet())
       continue;
@@ -492,7 +480,7 @@ void CpuTi::updateActionsFinishTime(double now)
   }
   sumPriority_ = sum_priority;
 
-  for (CpuTiAction& action : *actionSet_) {
+  for (CpuTiAction& action : actionSet_) {
     double min_finish = -1;
     /* action not running, skip it */
     if (action.getStateSet() != surf_cpu_model_pm->getRunningActionSet())
@@ -532,7 +520,7 @@ void CpuTi::updateActionsFinishTime(double now)
 
 bool CpuTi::isUsed()
 {
-  return not actionSet_->empty();
+  return not actionSet_.empty();
 }
 
 double CpuTi::getAvailableSpeed()
@@ -552,7 +540,7 @@ void CpuTi::updateRemainingAmount(double now)
   /* compute the integration area */
   double area_total = speedIntegratedTrace_->integrate(lastUpdate_, now) * speed_.peak;
   XBT_DEBUG("Flops total: %f, Last update %f", area_total, lastUpdate_);
-  for (CpuTiAction& action : *actionSet_) {
+  for (CpuTiAction& action : actionSet_) {
     /* action not running, skip it */
     if (action.getStateSet() != model()->getRunningActionSet())
       continue;
@@ -585,7 +573,7 @@ CpuAction *CpuTi::execution_start(double size)
   XBT_IN("(%s,%g)", getCname(), size);
   CpuTiAction* action = new CpuTiAction(static_cast<CpuTiModel*>(model()), size, isOff(), this);
 
-  actionSet_->push_back(*action);
+  actionSet_.push_back(*action);
 
   XBT_OUT();
   return action;
@@ -605,25 +593,25 @@ CpuAction *CpuTi::sleep(double duration)
   if (duration == NO_MAX_DURATION) {
     /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */
     simgrid::xbt::intrusive_erase(*action->getStateSet(), *action);
-    action->stateSet_ = static_cast<CpuTiModel*>(model())->runningActionSetThatDoesNotNeedBeingChecked_;
+    action->stateSet_ = &static_cast<CpuTiModel*>(model())->runningActionSetThatDoesNotNeedBeingChecked_;
     action->getStateSet()->push_back(*action);
   }
 
-  actionSet_->push_back(*action);
+  actionSet_.push_back(*action);
 
   XBT_OUT();
   return action;
 }
 
 void CpuTi::modified(bool modified){
-  CpuTiList* modifiedCpu = static_cast<CpuTiModel*>(model())->modifiedCpu_;
+  CpuTiList& modifiedCpu = static_cast<CpuTiModel*>(model())->modifiedCpu_;
   if (modified) {
     if (not cpu_ti_hook.is_linked()) {
-      modifiedCpu->push_back(*this);
+      modifiedCpu.push_back(*this);
     }
   } else {
     if (cpu_ti_hook.is_linked())
-      simgrid::xbt::intrusive_erase(*modifiedCpu, *this);
+      simgrid::xbt::intrusive_erase(modifiedCpu, *this);
   }
 }
 
@@ -652,7 +640,7 @@ int CpuTiAction::unref()
       simgrid::xbt::intrusive_erase(*getStateSet(), *this);
     /* remove from action_set */
     if (action_ti_hook.is_linked())
-      simgrid::xbt::intrusive_erase(*cpu_->actionSet_, *this);
+      simgrid::xbt::intrusive_erase(cpu_->actionSet_, *this);
     /* remove from heap */
     heapRemove(getModel()->getActionHeap());
     cpu_->modified(true);
index 1789127..609cff9 100644 (file)
@@ -124,7 +124,7 @@ public:
   void modified(bool modified);
 
   CpuTiTgmr *speedIntegratedTrace_ = nullptr;/*< Structure with data needed to integrate trace file */
-  ActionTiList *actionSet_ = nullptr;        /*< set with all actions running on cpu */
+  ActionTiList actionSet_;                   /*< set with all actions running on cpu */
   double sumPriority_ = 0; /*< the sum of actions' priority that are running on cpu */
   double lastUpdate_ = 0;  /*< last update of actions' remaining amount done */
 
@@ -141,14 +141,14 @@ typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
  *********/
 class CpuTiModel : public CpuModel {
 public:
-  CpuTiModel();
+  CpuTiModel() = default;
   ~CpuTiModel() override;
   Cpu *createCpu(simgrid::s4u::Host *host,  std::vector<double>* speedPerPstate, int core) override;
   double nextOccuringEvent(double now) override;
   void updateActionsState(double now, double delta) override;
 
-  ActionList *runningActionSetThatDoesNotNeedBeingChecked_;
-  CpuTiList *modifiedCpu_;
+  ActionList runningActionSetThatDoesNotNeedBeingChecked_;
+  CpuTiList modifiedCpu_;
 };
 
 }