Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge commit '045db1657e870c721be490b411868f4181a12ced' into surf++
[simgrid.git] / src / surf / surf.cpp
index fdfc793..010de57 100644 (file)
@@ -51,7 +51,7 @@ static void remove_watched_host(void *key)
   xbt_dict_remove(watched_hosts_lib, *(char**)key);
 }
 
-void surf_watched_hosts(void)
+/*void surf_watched_hosts(void)
 {
   char *key;
   void *host;
@@ -71,13 +71,15 @@ void surf_watched_hosts(void)
   }
   xbt_dynar_map(hosts, remove_watched_host);
   xbt_dynar_free(&hosts);
-}
+}*/
 
 
 xbt_dynar_t model_list = NULL;
 tmgr_history_t history = NULL;
 lmm_system_t maxmin_system = NULL;
 xbt_dynar_t surf_path = NULL;
+xbt_dynar_t host_that_restart = NULL;
+xbt_dict_t watched_hosts_lib;
 
 /* Don't forget to update the option description in smx_config when you change this */
 s_surf_model_description_t surf_network_model_description[] = {
@@ -154,16 +156,6 @@ s_surf_model_description_t surf_storage_model_description[] = {
   {NULL, NULL,  NULL}      /* this array must be NULL terminated */
 };
 
-/* ********************************************************************* */
-/* TUTORIAL: New model                                                   */
-s_surf_model_description_t surf_new_model_description[] = {
-  {"default",
-   "Tutorial model.",
-   surf_new_model_init_default},
-  {NULL, NULL,  NULL}      /* this array must be NULL terminated */
-};
-/* ********************************************************************* */
-
 #ifdef CONTEXT_THREADS
 static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
 #endif
@@ -174,35 +166,11 @@ static double min;               /* duration determined by surf_solve */
 
 double NOW = 0;
 
-XBT_INLINE double surf_get_clock(void)
+double surf_get_clock(void)
 {
   return NOW;
 }
 
-/*TODO: keepit void surf_watched_hosts(void)
-{
-  char *key;
-  void *_host;
-  smx_host_t host;
-  xbt_dict_cursor_t cursor;
-  xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL);
-
-  XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib");
-  xbt_dict_foreach(watched_hosts_lib,cursor,key,_host)
-  {
-    host = (smx_host_t) host;
-    if(SIMIX_host_get_state(host) == SURF_RESOURCE_ON){
-      XBT_INFO("Restart processes on host: %s",SIMIX_host_get_name(host));
-      SIMIX_host_autorestart(host);
-      xbt_dynar_push_as(hosts, char*, key);
-    }
-    else
-      XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key);
-  }
-  xbt_dynar_map(hosts, remove_watched_host);
-  xbt_dynar_free(&hosts);
-}*/
-
 #ifdef _XBT_WIN32
 # define FILE_DELIM "\\"
 #else
@@ -333,7 +301,7 @@ static XBT_INLINE void surf_cpu_free(void *r)
 
 static XBT_INLINE void surf_link_free(void *r)
 {
-  delete static_cast<NetworkCm02LinkPtr>(r);
+  delete dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(r));
 }
 
 static XBT_INLINE void surf_workstation_free(void *r)
@@ -356,7 +324,7 @@ void surf_init(int *argc, char **argv)
   as_router_lib = xbt_lib_new();
   storage_lib = xbt_lib_new();
   storage_type_lib = xbt_lib_new();
-  watched_hosts_lib = xbt_dict_new();
+  watched_hosts_lib = xbt_dict_new_homogeneous(NULL);
 
   XBT_DEBUG("Add routing levels");
   ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
@@ -391,6 +359,11 @@ void surf_exit(void)
   unsigned int iter;
   ModelPtr model = NULL;
 
+#ifdef HAVE_TRACING
+  TRACE_end();                  /* Just in case it was not called by the upper
+                                 * layer (or there is no upper layer) */
+#endif
+
   sg_config_finalize();
 
   xbt_dynar_foreach(model_list, iter, model)
@@ -413,7 +386,7 @@ void surf_exit(void)
   xbt_free(surf_mins);
   surf_mins = NULL;
 #endif
-
+  xbt_dynar_free(&host_that_restart);
   xbt_dynar_free(&surf_path);
 
   xbt_lib_free(&host_lib);
@@ -435,7 +408,9 @@ void surf_exit(void)
  *********/
 
 Model::Model(string name)
- : m_name(name), m_resOnCB(0), m_resOffCB(0), m_actSuspendCB(0), m_actCancelCB(0), m_actResumeCB(0)
+ : m_name(name), m_resOnCB(0), m_resOffCB(0),
+   m_actSuspendCB(0), m_actCancelCB(0), m_actResumeCB(0),
+   p_maxminSystem(0)
 {
   ActionPtr action;
   p_readyActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
@@ -545,26 +520,24 @@ double Model::shareResourcesFull(double now) {
 
 
 double Model::shareResourcesMaxMin(xbt_swag_t running_actions,
-                          size_t offset,
                           lmm_system_t sys,
                           void (*solve) (lmm_system_t))
 {
   void *_action = NULL;
-  ActionPtr action = NULL;
+  ActionLmmPtr action = NULL;
   double min = -1;
   double value = -1;
-#define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + (offset))))
 
   solve(sys);
 
   xbt_swag_foreach(_action, running_actions) {
-    action = (ActionPtr)_action;
-    value = lmm_variable_getvalue(VARIABLE(action));
+    action = dynamic_cast<ActionLmmPtr>(static_cast<ActionPtr>(_action));
+    value = lmm_variable_getvalue(action->p_variable);
     if ((value > 0) || (action->m_maxDuration >= 0))
       break;
   }
 
-  if (!action)
+  if (!_action)
     return -1.0;
 
   if (value > 0) {
@@ -578,10 +551,11 @@ double Model::shareResourcesMaxMin(xbt_swag_t running_actions,
     min = action->m_maxDuration;
 
 
-  for (action = (ActionPtr) xbt_swag_getNext(action, running_actions->offset);
-       action;
-       action = (ActionPtr) xbt_swag_getNext(action, running_actions->offset)) {
-    value = lmm_variable_getvalue(VARIABLE(action));
+  for (_action = xbt_swag_getNext(static_cast<ActionPtr>(action), running_actions->offset);
+       _action;
+       _action = xbt_swag_getNext(static_cast<ActionPtr>(action), running_actions->offset)) {
+       action = dynamic_cast<ActionLmmPtr>(static_cast<ActionPtr>(_action));
+    value = lmm_variable_getvalue(action->p_variable);
     if (value > 0) {
       if (action->m_remains > 0)
         value = action->m_remains / value;
@@ -599,7 +573,6 @@ double Model::shareResourcesMaxMin(xbt_swag_t running_actions,
   }
   XBT_DEBUG("min value : %f", min);
 
-#undef VARIABLE
   return min;
 }
 
@@ -737,11 +710,11 @@ ResourceLmm::ResourceLmm(surf_model_t model, const char *name, xbt_dict_t props,
   p_constraint = lmm_constraint_new(system, this, constraint_value);
   p_stateCurrent = state_init;
   if (state_trace)
-    p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
+    p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, static_cast<ResourcePtr>(this));
   p_power.scale = 1.0;
   p_power.peak = metric_peak;
   if (metric_trace)
-    p_power.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, this);
+    p_power.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 }
 
 /**********
@@ -1023,7 +996,7 @@ void ActionLmm::updateRemainingLazy(double now)
   delta = now - m_lastUpdate;
 
   if (m_remains > 0) {
-    XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
+    XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, m_remains, m_lastUpdate);
     double_update(&m_remains, m_lastValue * delta);
 
 #ifdef HAVE_TRACING
@@ -1032,7 +1005,7 @@ void ActionLmm::updateRemainingLazy(double now)
       TRACE_surf_host_set_utilization(cpu->m_name, p_category, m_lastValue, m_lastUpdate, now - m_lastUpdate);
     }
 #endif
-    XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
+    XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains);
   }
 
   if(p_model == static_cast<ModelPtr>(surf_network_model))