Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a bug making that the simulation ran longer than expected
[simgrid.git] / src / simdag / sd_workstation.c
index 232b83c..7a163ef 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2006-2011. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -9,6 +9,9 @@
 #include "xbt/dict.h"
 #include "xbt/sysdep.h"
 #include "surf/surf.h"
+#include "surf/surf_resource.h"
+
+
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_workstation, sd,
                                 "Logging specific to SimDag (workstation)");
@@ -67,12 +70,12 @@ const SD_workstation_t *SD_workstation_get_list(void)
 
   if (sd_global->workstation_list == NULL) {    /* this is the first time the function is called */
     sd_global->workstation_list =
-        xbt_new(SD_workstation_t, host_lib->count);
+      xbt_new(SD_workstation_t, xbt_lib_length(host_lib));
 
     i = 0;
     xbt_lib_foreach(host_lib, cursor, key, data) {
       if(data[SD_HOST_LEVEL])
-         sd_global->workstation_list[i++] = (SD_workstation_t) data[SD_HOST_LEVEL];
+        sd_global->workstation_list[i++] = (SD_workstation_t) data[SD_HOST_LEVEL];
     }
   }
   return sd_global->workstation_list;
@@ -86,7 +89,7 @@ const SD_workstation_t *SD_workstation_get_list(void)
  */
 int SD_workstation_get_number(void)
 {
-  return host_lib->count;
+  return xbt_lib_length(host_lib);
 }
 
 /**
@@ -154,6 +157,42 @@ xbt_dict_t SD_workstation_get_properties(SD_workstation_t workstation)
 
 }
 
+/** @brief Displays debugging informations about a workstation */
+void SD_workstation_dump(SD_workstation_t ws)
+{
+  xbt_dict_t props;
+  xbt_dict_cursor_t cursor=NULL;
+  char *key,*data;
+  SD_task_t task = NULL;
+  
+  XBT_INFO("Displaying workstation %s", SD_workstation_get_name(ws));
+  XBT_INFO("  - power: %.0f", SD_workstation_get_power(ws));
+  XBT_INFO("  - available power: %.2f", SD_workstation_get_available_power(ws));
+  switch (ws->access_mode){
+  case SD_WORKSTATION_SHARED_ACCESS:
+      XBT_INFO("  - access mode: Space shared");
+      break;
+  case SD_WORKSTATION_SEQUENTIAL_ACCESS:
+      XBT_INFO("  - access mode: Exclusive");
+    task = SD_workstation_get_current_task(ws);
+    if(task)
+      XBT_INFO("    current running task: %s",
+               SD_task_get_name(task));
+    else
+      XBT_INFO("    no task running");
+      break;
+  default: break;
+  }
+  props = SD_workstation_get_properties(ws);
+  
+  if (!xbt_dict_is_empty(props)){
+    XBT_INFO("  - properties:");
+
+    xbt_dict_foreach(props,cursor,key,data) {
+      XBT_INFO("    %s->%s",key,data);
+    }
+  }
+}
 
 /**
  * \brief Returns the route between two workstations
@@ -251,7 +290,7 @@ double SD_workstation_get_computation_time(SD_workstation_t workstation,
 }
 
 /**
- * \brief Returns the latency of the route between two workstations, i.e. the sum of all link latencies
+ * \brief Returns the latency of the route between two workstations, i.e. the sum of all link latencies
  * between the workstations.
  *
  * \param src the first workstation
@@ -280,7 +319,7 @@ double SD_route_get_current_latency(SD_workstation_t src,
 }
 
 /**
- * \brief Returns the bandwidth of the route between two workstations, i.e. the minimum link bandwidth of all
+ * \brief Returns the bandwidth of the route between two workstations, i.e. the minimum link bandwidth of all
  * between the workstations.
  *
  * \param src the first workstation
@@ -394,6 +433,10 @@ void SD_workstation_set_access_mode(SD_workstation_t workstation,
                                     e_SD_workstation_access_mode_t
                                     access_mode)
 {
+  xbt_assert(access_mode != SD_WORKSTATION_SEQUENTIAL_ACCESS ||
+             access_mode != SD_WORKSTATION_SHARED_ACCESS,
+             "Trying to set an invalid access mode");
+
   if (access_mode == workstation->access_mode) {
     return;                     // nothing is changed
   }
@@ -408,16 +451,16 @@ void SD_workstation_set_access_mode(SD_workstation_t workstation,
   }
 }
 
-/* Returns whether a task can start now on a workstation.
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              *//*
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   int __SD_workstation_can_start(SD_workstation_t workstation, SD_task_t task) {
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   SD_CHECK_INIT_DONE();
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   xbt_assert(workstation != NULL && task != NULL, "Invalid parameter");
+/* Returns whether a task can start now on a workstation*/
+/*
+  int __SD_workstation_can_start(SD_workstation_t workstation, SD_task_t task) {
+  SD_CHECK_INIT_DONE();
+  xbt_assert(workstation != NULL && task != NULL, "Invalid parameter");
 
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   return !__SD_workstation_is_busy(workstation) &&
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   (xbt_fifo_size(workstation->task_fifo) == 0) || xbt_fifo_get_first_item(workstation->task_fifo) == task);
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   }
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
+  return !__SD_workstation_is_busy(workstation) &&
+  (xbt_fifo_size(workstation->task_fifo) == 0) || xbt_fifo_get_first_item(workstation->task_fifo) == task);
+  }
+*/
 
 /* Returns whether a workstation is busy. A workstation is busy is it is
  * in sequential mode and a task is running on it or the fifo is not empty.