Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill models getName() call sites.
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 20 Jul 2015 16:14:21 +0000 (18:14 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 20 Jul 2015 16:22:09 +0000 (18:22 +0200)
- Debug messages now depend on typeid(...).name(). Beware, the output
  may be compiler dependent.
- It was mainly used to have a specific handling of NS3, which method
  shareRessources() is not idempotent (ie, it actually moves the model
  in the future with no possibility of rolling it back afterward).

  So NS3->shareRessource() needs to be run after all other
  shareRessources, and before the updateState()s.

  Add a shareResourcesIsIdempotent() method to all models to detect
  whether we need to activate that strange behavior without having to
  rely on the model name.

- Removing models namesmakes Model pure virtual, possibly allowing
  diamon-shaped inheritance in L07, where we need only one model for
  CpuModel and NetworkModel.

src/include/surf/surf.h
src/surf/cpu_interface.hpp
src/surf/host_clm03.cpp
src/surf/host_interface.hpp
src/surf/host_ptask_L07.hpp
src/surf/network_cm02.hpp
src/surf/network_ns3.hpp
src/surf/storage_interface.hpp
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.hpp
src/surf/vm_hl13.cpp

index 1dee691..15b1b8e 100644 (file)
@@ -198,11 +198,9 @@ XBT_PUBLIC(void) surf_as_cluster_set_backbone(AS_t as, void* backbone);
 
 /** @{ @ingroup SURF_c_bindings */
 
 
 /** @{ @ingroup SURF_c_bindings */
 
-/**
- * @brief Get the name of a surf model
+/** @brief Get the name of a surf model (dont rely on exact value)
  *
  *
- * @param model A model
- * @return The name of the model
+ * This is implemented using typeid(), so it may change with the compiler
  */
 XBT_PUBLIC(const char *) surf_model_name(surf_model_t model);
 
  */
 XBT_PUBLIC(const char *) surf_model_name(surf_model_t model);
 
index 6375ce0..ecbf8b0 100644 (file)
@@ -90,6 +90,7 @@ public:
 
   void updateActionsStateLazy(double now, double delta);
   void updateActionsStateFull(double now, double delta);
 
   void updateActionsStateLazy(double now, double delta);
   void updateActionsStateFull(double now, double delta);
+  bool shareResourcesIsIdempotent() {return true;}
 };
 
 /************
 };
 
 /************
index bfe88b0..2932677 100644 (file)
@@ -69,13 +69,13 @@ double HostCLM03Model::shareResources(double now){
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = surf_cpu_model_pm->shareResources(now);
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = surf_cpu_model_pm->shareResources(now);
-  double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
+  double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1;
   double min_by_sto = surf_storage_model->shareResources(now);
 
   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
   double min_by_sto = surf_storage_model->shareResources(now);
 
   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
-      this, surf_cpu_model_pm->getName(), min_by_cpu,
-            surf_network_model->getName(), min_by_net,
-            surf_storage_model->getName(), min_by_sto);
+      this, typeid(surf_cpu_model_pm).name(), min_by_cpu,
+               typeid(surf_network_model).name(), min_by_net,
+                       typeid(surf_storage_model).name(), min_by_sto);
 
   double res = max(max(min_by_cpu, min_by_net), min_by_sto);
   if (min_by_cpu >= 0.0 && min_by_cpu < res)
 
   double res = max(max(min_by_cpu, min_by_net), min_by_sto);
   if (min_by_cpu >= 0.0 && min_by_cpu < res)
index 48fa525..78e7f5a 100644 (file)
@@ -80,6 +80,8 @@ public:
                                         double rate)=0;
 
   virtual Action *communicate(Host *src, Host *dst, double size, double rate)=0;
                                         double rate)=0;
 
   virtual Action *communicate(Host *src, Host *dst, double size, double rate)=0;
+
+  bool shareResourcesIsIdempotent() {return true;}
 };
 
 /************
 };
 
 /************
index 66c5b03..33a957d 100644 (file)
@@ -81,6 +81,8 @@ public:
 
   Action *communicate(RoutingEdge */*src*/, RoutingEdge */*dst*/, double /*size*/, double /*rate*/) {DIE_IMPOSSIBLE;};
   void addTraces() {DIE_IMPOSSIBLE;};
 
   Action *communicate(RoutingEdge */*src*/, RoutingEdge */*dst*/, double /*size*/, double /*rate*/) {DIE_IMPOSSIBLE;};
   void addTraces() {DIE_IMPOSSIBLE;};
+  bool shareResourcesIsIdempotent() {return true;}
+
   HostL07Model *p_hostModel;
 };
 
   HostL07Model *p_hostModel;
 };
 
index 3dd58ea..3007837 100644 (file)
@@ -56,6 +56,7 @@ public:
   void updateActionsStateFull(double now, double delta);
   Action *communicate(RoutingEdge *src, RoutingEdge *dst,
                                           double size, double rate);
   void updateActionsStateFull(double now, double delta);
   Action *communicate(RoutingEdge *src, RoutingEdge *dst,
                                           double size, double rate);
+  bool shareResourcesIsIdempotent() {return true;}
 };
 
 /************
 };
 
 /************
index b296eb2..82bcc7e 100644 (file)
@@ -46,6 +46,7 @@ public:
   double shareResources(double now);
   void updateActionsState(double now, double delta);
   void addTraces(){DIE_IMPOSSIBLE;}
   double shareResources(double now);
   void updateActionsState(double now, double delta);
   void addTraces(){DIE_IMPOSSIBLE;}
+  bool shareResourcesIsIdempotent() {return false;}
 };
 
 /************
 };
 
 /************
index 241cb67..9e0e442 100644 (file)
@@ -84,6 +84,8 @@ public:
                                     xbt_dict_t properties,
                                     const char *attach) = 0;
 
                                     xbt_dict_t properties,
                                     const char *attach) = 0;
 
+  bool shareResourcesIsIdempotent() {return true;}
+
   xbt_dynar_t p_storageList;
 };
 
   xbt_dynar_t p_storageList;
 };
 
index 6ea7968..c346440 100644 (file)
@@ -76,11 +76,11 @@ double surf_solve(double max_date)
   XBT_DEBUG("Looking for next action end for all models except NS3");
   xbt_dynar_foreach(model_list_invoke, iter, model) {
          double next_action_end = -1.0;
   XBT_DEBUG("Looking for next action end for all models except NS3");
   xbt_dynar_foreach(model_list_invoke, iter, model) {
          double next_action_end = -1.0;
-         if (strcmp(model->getName(), "network NS3")) {
-           XBT_DEBUG("Running for Resource [%s]", model->getName());
+         if (model->shareResourcesIsIdempotent()) {
+           XBT_DEBUG("Running for Resource [%s]", typeid(model).name());
            next_action_end = model->shareResources(NOW);
            XBT_DEBUG("Resource [%s] : next action end = %f",
            next_action_end = model->shareResources(NOW);
            XBT_DEBUG("Resource [%s] : next action end = %f",
-               model->getName(), next_action_end);
+               typeid(model).name(), next_action_end);
          }
          if ((surf_min < 0.0 || next_action_end < surf_min)
                          && next_action_end >= 0.0) {
          }
          if ((surf_min < 0.0 || next_action_end < surf_min)
                          && next_action_end >= 0.0) {
@@ -97,7 +97,7 @@ double surf_solve(double max_date)
 
     next_event_date = tmgr_history_next_date(history);
 
 
     next_event_date = tmgr_history_next_date(history);
 
-    if(!strcmp(surf_network_model->getName(), "network NS3")){
+    if(! surf_network_model->shareResourcesIsIdempotent()){ // NS3, I see you
       if(next_event_date!=-1.0 && surf_min!=-1.0) {
         surf_min = MIN(next_event_date - NOW, surf_min);
       } else{
       if(next_event_date!=-1.0 && surf_min!=-1.0) {
         surf_min = MIN(next_event_date - NOW, surf_min);
       } else{
@@ -186,7 +186,7 @@ void surf_as_cluster_set_backbone(AS_t as, void* backbone){
 }
 
 const char *surf_model_name(surf_model_t model){
 }
 
 const char *surf_model_name(surf_model_t model){
-  return model->getName();
+  return typeid(model).name();
 }
 
 surf_action_t surf_model_extract_done_action_set(surf_model_t model){
 }
 
 surf_action_t surf_model_extract_done_action_set(surf_model_t model){
index 2197bb0..f9ca6db 100644 (file)
@@ -211,6 +211,13 @@ public:
   virtual void updateActionsStateLazy(double now, double delta);
   virtual void updateActionsStateFull(double now, double delta);
 
   virtual void updateActionsStateLazy(double now, double delta);
   virtual void updateActionsStateFull(double now, double delta);
 
+  /** @brief Returns whether this model have an idempotent shareResource()
+   *
+   * The only model that is not is NS3: computing the next timestamp moves the model up to that point,
+   * so we need to call it only when the next timestamp of other sources is computed.
+   */
+  virtual bool shareResourcesIsIdempotent()=0;
+
 protected:
   ActionLmmListPtr p_modifiedSet;
   lmm_system_t p_maxminSystem;
 protected:
   ActionLmmListPtr p_modifiedSet;
   lmm_system_t p_maxminSystem;
index 4afa59e..68cfc56 100644 (file)
@@ -127,7 +127,7 @@ double VMHL13Model::shareResources(double now)
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = surf_cpu_model_vm->shareResources(now);
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = surf_cpu_model_vm->shareResources(now);
-  double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
+  double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1;
   // Fixme: take storage into account once it's implemented
   double min_by_sto = -1;
 
   // Fixme: take storage into account once it's implemented
   double min_by_sto = -1;