Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a portable inline and declare variables at the beginning
[simgrid.git] / src / simdag / sd_task.c
index b5728f1..0de83bb 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 2007-2009 Da SimGrid Team.  All rights reserved.           */
+/* Copyright (c) 2006, 2007, 2008, 2009, 2010. 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. */
@@ -168,6 +169,12 @@ const char *SD_task_get_name(SD_task_t task)
   return task->name;
 }
 
+/** @brief Allows to change the name of a task */
+void SD_task_set_name(SD_task_t task, const char *name) {
+  xbt_free(task->name);
+  task->name = xbt_strdup(name);
+}
+
 /** @brief Returns the dynar of the parents of a task
  *
  * \param task a task
@@ -644,25 +651,27 @@ double SD_task_get_execution_time(SD_task_t task,
   double time, max_time = 0.0;
   int i, j;
   SD_CHECK_INIT_DONE();
-  xbt_assert0(task != NULL && workstation_nb > 0 && workstation_list != NULL
-              && computation_amount != NULL
-              && communication_amount != NULL, "Invalid parameter");
+  xbt_assert0(task != NULL && workstation_nb > 0 && workstation_list != NULL,
+              "Invalid parameter");
 
   /* the task execution time is the maximum execution time of the parallel tasks */
 
   for (i = 0; i < workstation_nb; i++) {
-    time =
-      SD_workstation_get_computation_time(workstation_list[i],
-                                          computation_amount[i]);
-
-    for (j = 0; j < workstation_nb; j++) {
-      time +=
-        SD_route_get_communication_time(workstation_list[i],
-                                        workstation_list[j],
-                                        communication_amount[i *
-                                                             workstation_nb +
-                                                             j]);
-    }
+    time = 0.0;
+    if (computation_amount != NULL)
+      time =
+          SD_workstation_get_computation_time(workstation_list[i],
+              computation_amount[i]);
+
+    if (communication_amount != NULL)
+      for (j = 0; j < workstation_nb; j++) {
+        time +=
+            SD_route_get_communication_time(workstation_list[i],
+                workstation_list[j],
+                communication_amount[i *
+                                     workstation_nb +
+                                     j]);
+      }
 
     if (time > max_time) {
       max_time = time;
@@ -670,7 +679,7 @@ double SD_task_get_execution_time(SD_task_t task,
   }
   return max_time;
 }
-static inline void SD_task_do_schedule(SD_task_t task) {
+static XBT_INLINE void SD_task_do_schedule(SD_task_t task) {
   SD_CHECK_INIT_DONE();
 
    if (!__SD_task_is_not_scheduled(task))
@@ -704,9 +713,10 @@ void SD_task_schedule(SD_task_t task, int workstation_count,
                       const double *computation_amount,
                       const double *communication_amount, double rate)
 {
-  xbt_assert0(workstation_count > 0, "workstation_nb must be positive");
-
   int communication_nb;
+  task->workstation_nb = 0;
+  task->rate = 0;
+  xbt_assert0(workstation_count > 0, "workstation_nb must be positive");
 
   task->workstation_nb = workstation_count;
   task->rate = rate;
@@ -915,7 +925,8 @@ int __SD_task_try_to_run(SD_task_t task)
 
 
   for (i = 0; i < task->workstation_nb; i++) {
-    can_start = !__SD_workstation_is_busy(task->workstation_list[i]);
+    can_start = can_start && 
+      !__SD_workstation_is_busy(task->workstation_list[i]);
   }
 
   DEBUG2("Task '%s' can start: %d", SD_task_get_name(task), can_start);
@@ -1194,7 +1205,7 @@ void SD_task_destroy(SD_task_t task)
 }
 
 
-static inline SD_task_t SD_task_create_sized(const char*name,void*data,double amount,int ws_count) {
+static XBT_INLINE SD_task_t SD_task_create_sized(const char*name,void*data,double amount,int ws_count) {
   SD_task_t task = SD_task_create(name,data,amount);
   task->communication_amount = xbt_new0(double,ws_count*ws_count);
   task->computation_amount = xbt_new0(double,ws_count);
@@ -1256,6 +1267,8 @@ SD_task_t SD_task_create_comp_seq(const char*name, void *data, double amount) {
  */
 void SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list) {
   int i;
+  SD_dependency_t dep;
+  unsigned int cpt;
   xbt_assert1(task->kind != 0,"Task %s is not typed. Cannot automatically schedule it.",SD_task_get_name(task));
   switch(task->kind) {
   case SD_TASK_COMM_E2E:
@@ -1281,8 +1294,7 @@ void SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list) {
     VERB3("Schedule computation task %s on %s. It costs %.f flops",
         SD_task_get_name(task),SD_workstation_get_name(task->workstation_list[0]),
         task->computation_amount[0]);
-    SD_dependency_t dep;
-    unsigned int cpt;
+
     xbt_dynar_foreach(task->tasks_before,cpt,dep) {
       SD_task_t before = dep->src;
       if (before->kind == SD_TASK_COMM_E2E) {