Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allows the bytes_amount argument of MSG_parallel_task_create to be null.
[simgrid.git] / src / surf / host_ptask_L07.cpp
index c202f98..69b9b75 100644 (file)
@@ -73,7 +73,8 @@ CpuL07Model::CpuL07Model(HostL07Model *hmodel,lmm_system_t sys)
        }
 CpuL07Model::~CpuL07Model() {
        surf_cpu_model_pm = NULL;
-       p_maxminSystem = NULL; // Avoid multi-free
+       lmm_system_free(p_maxminSystem);
+       p_maxminSystem = NULL;
 }
 NetworkL07Model::NetworkL07Model(HostL07Model *hmodel, lmm_system_t sys)
        : NetworkModel()
@@ -208,23 +209,25 @@ L07Action::L07Action(Model *model, int host_nb,
          this->p_netcardList->push_back(host_list[i]->pimpl_netcard);
 
   /* Compute the number of affected resources... */
-  for (int i = 0; i < host_nb; i++) {
-    for (int j = 0; j < host_nb; j++) {
-      xbt_dynar_t route=NULL;
-
-      if (bytes_amount[i * host_nb + j] > 0) {
-        double lat=0.0;
-        unsigned int cpt;
-        void *_link;
-        LinkL07 *link;
-
-        routing_platf->getRouteAndLatency((*this->p_netcardList)[i], (*this->p_netcardList)[j],
-                                                 &route, &lat);
-        latency = MAX(latency, lat);
-
-        xbt_dynar_foreach(route, cpt, _link) {
-           link = static_cast<LinkL07*>(_link);
-           xbt_dict_set(ptask_parallel_task_link_set, link->getName(), link, NULL);
+  if(bytes_amount != NULL) {
+    for (int i = 0; i < host_nb; i++) {
+      for (int j = 0; j < host_nb; j++) {
+        xbt_dynar_t route=NULL;
+
+        if (bytes_amount[i * host_nb + j] > 0) {
+          double lat=0.0;
+          unsigned int cpt;
+          void *_link;
+          LinkL07 *link;
+
+          routing_platf->getRouteAndLatency((*this->p_netcardList)[i], (*this->p_netcardList)[j],
+                                                        &route, &lat);
+          latency = MAX(latency, lat);
+
+          xbt_dynar_foreach(route, cpt, _link) {
+            link = static_cast<LinkL07*>(_link);
+            xbt_dict_set(ptask_parallel_task_link_set, link->getName(), link, NULL);
+          }
         }
       }
     }
@@ -256,22 +259,23 @@ L07Action::L07Action(Model *model, int host_nb,
               host_list[i]->pimpl_cpu->getConstraint(),
                this->getVariable(), flops_amount[i]);
 
-  for (int i = 0; i < host_nb; i++) {
-    for (int j = 0; j < host_nb; j++) {
-      void *_link;
+  if(bytes_amount != NULL) {
+    for (int i = 0; i < host_nb; i++) {
+      for (int j = 0; j < host_nb; j++) {
+        void *_link;
 
-      xbt_dynar_t route=NULL;
-      if (bytes_amount[i * host_nb + j] == 0.0)
-        continue;
+        xbt_dynar_t route=NULL;
+        if (bytes_amount[i * host_nb + j] == 0.0)
+          continue;
 
-      routing_platf->getRouteAndLatency((*this->p_netcardList)[i], (*this->p_netcardList)[j],
-                                           &route, NULL);
+        routing_platf->getRouteAndLatency((*this->p_netcardList)[i], (*this->p_netcardList)[j],
+                                                    &route, NULL);
 
-      xbt_dynar_foreach(route, cpt, _link) {
-        LinkL07 *link = static_cast<LinkL07*>(_link);
-        lmm_expand_add(model->getMaxminSystem(), link->getConstraint(),
-                       this->getVariable(),
-                       bytes_amount[i * host_nb + j]);
+        xbt_dynar_foreach(route, cpt, _link) {
+          LinkL07 *link = static_cast<LinkL07*>(_link);
+          lmm_expand_add(model->getMaxminSystem(), link->getConstraint(),
+                        this->getVariable(), bytes_amount[i * host_nb + j]);
+        }
       }
     }
   }
@@ -350,7 +354,7 @@ void HostL07Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
+    host->p_stateEvent = future_evt_set->add_trace(trace, 0.0, host);
   }
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
@@ -360,7 +364,7 @@ void HostL07Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->p_speedEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
+    host->p_speedEvent = future_evt_set->add_trace(trace, 0.0, host);
   }
 
   /* Connect traces relative to network */
@@ -371,7 +375,7 @@ void HostL07Model::addTraces()
     xbt_assert(link, "Link %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_stateEvent = future_evt_set->add_trace(trace, 0.0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
@@ -381,7 +385,7 @@ void HostL07Model::addTraces()
     xbt_assert(link, "Link %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    link->p_bwEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_bwEvent = future_evt_set->add_trace(trace, 0.0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
@@ -391,7 +395,7 @@ void HostL07Model::addTraces()
     xbt_assert(link, "Link %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_latEvent = future_evt_set->add_trace(trace, 0.0, link);
   }
 }
 
@@ -409,12 +413,10 @@ CpuL07::CpuL07(CpuL07Model *model, simgrid::s4u::Host *host,
   p_constraint = lmm_constraint_new(model->getMaxminSystem(), this, xbt_dynar_get_as(speedPeakList,pstate,double) * speedScale);
 
   if (speedTrace)
-    p_speedEvent = tmgr_history_add_trace(history, speedTrace, 0.0, 0, this);
-  else
-    p_speedEvent = NULL;
+    p_speedEvent = future_evt_set->add_trace(speedTrace, 0.0, this);
 
   if (state_trace)
-       p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
+    p_stateEvent = future_evt_set->add_trace(state_trace, 0.0, this);
 }
 
 CpuL07::~CpuL07()
@@ -429,11 +431,11 @@ LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
                         int initiallyOn,
                         tmgr_trace_t state_trace,
                         e_surf_link_sharing_policy_t policy)
- : Link(model, name, props, lmm_constraint_new(model->getMaxminSystem(), this, bw_initial), history, state_trace)
+ : Link(model, name, props, lmm_constraint_new(model->getMaxminSystem(), this, bw_initial), future_evt_set, state_trace)
 {
   m_bwCurrent = bw_initial;
   if (bw_trace)
-    p_bwEvent = tmgr_history_add_trace(history, bw_trace, 0.0, 0, this);
+    p_bwEvent = future_evt_set->add_trace(bw_trace, 0.0, this);
 
   if (initiallyOn)
     turnOn();
@@ -442,7 +444,7 @@ LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
   m_latCurrent = lat_initial;
 
   if (lat_trace)
-       p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, this);
+    p_latEvent = future_evt_set->add_trace(lat_trace, 0.0, this);
 
   if (policy == SURF_LINK_FATPIPE)
        lmm_constraint_shared(getConstraint());
@@ -504,49 +506,40 @@ bool LinkL07::isUsed(){
   return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint());
 }
 
-void CpuL07::updateState(tmgr_trace_iterator_t event_type, double value, double /*date*/){
+void CpuL07::updateState(tmgr_trace_iterator_t triggered, double value, double /*date*/){
   XBT_DEBUG("Updating cpu %s (%p) with value %g", getName(), this, value);
-  if (event_type == p_speedEvent) {
-       m_speedScale = value;
-       onSpeedChange();
-    if (tmgr_trace_event_free(event_type))
-      p_speedEvent = NULL;
-  } else if (event_type == p_stateEvent) {
+  if (triggered == p_speedEvent) {
+    m_speedScale = value;
+    onSpeedChange();
+    tmgr_trace_event_unref(&p_speedEvent);
+  } else if (triggered == p_stateEvent) {
     if (value > 0)
       turnOn();
     else
       turnOff();
-    if (tmgr_trace_event_free(event_type))
-      p_stateEvent = NULL;
+    tmgr_trace_event_unref(&p_stateEvent);
   } else {
-    XBT_CRITICAL("Unknown event ! \n");
-    xbt_abort();
+    xbt_die("Unknown event!\n");
   }
-  return;
 }
 
-void LinkL07::updateState(tmgr_trace_iterator_t event_type, double value, double date) {
+void LinkL07::updateState(tmgr_trace_iterator_t triggered, double value, double date) {
   XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", getName(), this, value, date);
-  if (event_type == p_bwEvent) {
+  if (triggered == p_bwEvent) {
     updateBandwidth(value, date);
-    if (tmgr_trace_event_free(event_type))
-      p_bwEvent = NULL;
-  } else if (event_type == p_latEvent) {
+    tmgr_trace_event_unref(&p_bwEvent);
+  } else if (triggered == p_latEvent) {
     updateLatency(value, date);
-    if (tmgr_trace_event_free(event_type))
-      p_latEvent = NULL;
-  } else if (event_type == p_stateEvent) {
+    tmgr_trace_event_unref(&p_latEvent);
+  } else if (triggered == p_stateEvent) {
     if (value > 0)
       turnOn();
     else
       turnOff();
-    if (tmgr_trace_event_free(event_type))
-      p_stateEvent = NULL;
+    tmgr_trace_event_unref(&p_stateEvent);
   } else {
-    XBT_CRITICAL("Unknown event ! \n");
-    xbt_abort();
+    xbt_die("Unknown event ! \n");
   }
-  return;
 }
 
 double LinkL07::getBandwidth()
@@ -578,7 +571,8 @@ void LinkL07::updateLatency(double value, double date)
  **********/
 
 L07Action::~L07Action(){
-  free(p_communicationAmount);
+  if (p_communicationAmount != NULL)
+    free(p_communicationAmount);
   free(p_computationAmount);
 }
 
@@ -590,16 +584,18 @@ void L07Action::updateBound()
 
   int hostNb = p_netcardList->size();
 
-  for (i = 0; i < hostNb; i++) {
-    for (j = 0; j < hostNb; j++) {
-      xbt_dynar_t route=NULL;
+  if (p_communicationAmount != NULL) {
+    for (i = 0; i < hostNb; i++) {
+      for (j = 0; j < hostNb; j++) {
+        xbt_dynar_t route=NULL;
 
-      if (p_communicationAmount[i * hostNb + j] > 0) {
-        double lat = 0.0;
-        routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j],
-                                                         &route, &lat);
+        if (p_communicationAmount[i * hostNb + j] > 0) {
+          double lat = 0.0;
+          routing_platf->getRouteAndLatency((*p_netcardList)[i], (*p_netcardList)[j],
+                                                                &route, &lat);
 
-        lat_current = MAX(lat_current, lat * p_communicationAmount[i * hostNb + j]);
+          lat_current = MAX(lat_current, lat * p_communicationAmount[i * hostNb + j]);
+        }
       }
     }
   }