Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix missing proto for PID functions
[simgrid.git] / src / simdag / sd_task.c
index 3673944..058e3bf 100644 (file)
@@ -451,6 +451,20 @@ double SD_task_get_amount(SD_task_t task)
   return task->amount;
 }
 
+/**
+ * \brief Returns the alpha parameter of a SD_TASK_COMP_PAR_AMDAH task
+ *
+ * \param task a parallel task assuming Amdahl's law as speedup model
+ * \return the alpha parameter (serial part of a task in percent) for this task
+ */
+double SD_task_get_alpha(SD_task_t task)
+{
+  xbt_assert(SD_task_get_kind(task) == SD_TASK_COMP_PAR_AMDAHL,
+     "Alpha parameter is not defined for this kink of task");
+  return task->alpha;
+}
+
+
 /**
  * \brief Returns the remaining amount work to do till the completion of a task
  *
@@ -480,16 +494,16 @@ void SD_task_dump(SD_task_t task)
 
   XBT_INFO("Displaying task %s", SD_task_get_name(task));
   statename = bprintf("%s %s %s %s %s %s %s %s",
-                      (task->state & SD_NOT_SCHEDULED ? "not scheduled" :
+                      (task->state == SD_NOT_SCHEDULED ? "not scheduled" :
                        ""),
-                      (task->state & SD_SCHEDULABLE ? "schedulable" : ""),
-                      (task->state & SD_SCHEDULED ? "scheduled" : ""),
-                      (task->state & SD_RUNNABLE ? "runnable" :
+                      (task->state == SD_SCHEDULABLE ? "schedulable" : ""),
+                      (task->state == SD_SCHEDULED ? "scheduled" : ""),
+                      (task->state == SD_RUNNABLE ? "runnable" :
                        "not runnable"),
-                      (task->state & SD_IN_FIFO ? "in fifo" : ""),
-                      (task->state & SD_RUNNING ? "running" : ""),
-                      (task->state & SD_DONE ? "done" : ""),
-                      (task->state & SD_FAILED ? "failed" : ""));
+                      (task->state == SD_IN_FIFO ? "in fifo" : ""),
+                      (task->state == SD_RUNNING ? "running" : ""),
+                      (task->state == SD_DONE ? "done" : ""),
+                      (task->state == SD_FAILED ? "failed" : ""));
   XBT_INFO("  - state: %s", statename);
   free(statename);
 
@@ -504,11 +518,16 @@ void SD_task_dump(SD_task_t task)
     case SD_TASK_COMP_PAR_AMDAHL:
       XBT_INFO("  - kind: parallel computation following Amdahl's law");
       break;
+    case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
+      XBT_INFO("  - kind: MxN data redistribution assuming 1D block distribution");
+      break;
     default:
       XBT_INFO("  - (unknown kind %d)", task->kind);
     }
   }
   XBT_INFO("  - amount: %.0f", SD_task_get_amount(task));
+  if (task->kind == SD_TASK_COMP_PAR_AMDAHL)
+    XBT_INFO("  - alpha: %.2f", task->alpha);
   XBT_INFO("  - Dependencies to satisfy: %d", task->unsatisfied_dependencies);
   if (!xbt_dynar_is_empty(task->tasks_before)) {
     XBT_INFO("  - pre-dependencies:");
@@ -532,9 +551,11 @@ void SD_task_dotty(SD_task_t task, void *out)
   fprintf(out, "  T%p [label=\"%.20s\"", task, task->name);
   switch (task->kind) {
   case SD_TASK_COMM_E2E:
+  case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
     fprintf(out, ", shape=box");
     break;
   case SD_TASK_COMP_SEQ:
+  case SD_TASK_COMP_PAR_AMDAHL:
     fprintf(out, ", shape=circle");
     break;
   default:
@@ -633,6 +654,23 @@ void SD_task_dependency_add(const char *name, void *data, SD_task_t src,
     __SD_task_set_state(dst, SD_SCHEDULED);
   }
 }
+/**
+ * \brief Returns the name given as input when dependency has been created..
+ *
+ * \param src a task
+ * \param dst a task depending on \a src
+ *
+ */
+const char *SD_task_dependency_get_name(SD_task_t src, SD_task_t dst){
+  unsigned int i;
+  SD_dependency_t dependency;
+
+  xbt_dynar_foreach(src->tasks_after, i, dependency){
+    if (dependency->dst == dst)
+      return dependency->name;
+  }
+  return NULL;
+}
 
 /**
  * \brief Indicates whether there is a dependency between two tasks.
@@ -1029,7 +1067,7 @@ void __SD_task_really_run(SD_task_t task)
   for (i = 0; i < workstation_nb; i++) {
     if (SD_workstation_get_access_mode(task->workstation_list[i]) ==
         SD_WORKSTATION_SEQUENTIAL_ACCESS) {
-      task->workstation_list[i]->current_task = task;
+      SD_workstation_priv(task->workstation_list[i])->current_task = task;
       xbt_assert(__SD_workstation_is_busy(task->workstation_list[i]),
                   "The workstation should be busy now");
     }
@@ -1045,7 +1083,7 @@ void __SD_task_really_run(SD_task_t task)
   surf_workstations = xbt_new(void *, workstation_nb);
 
   for (i = 0; i < workstation_nb; i++)
-    surf_workstations[i] = task->workstation_list[i]->surf_workstation;
+    surf_workstations[i] = task->workstation_list[i];
 
   double *computation_amount = xbt_new0(double, workstation_nb);
   double *communication_amount = xbt_new0(double, workstation_nb * workstation_nb);
@@ -1111,11 +1149,11 @@ int __SD_task_try_to_run(SD_task_t task)
   if (!can_start) {             /* if the task cannot start and is not in the FIFOs yet */
     for (i = 0; i < task->workstation_nb; i++) {
       workstation = task->workstation_list[i];
-      if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
+      if (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
         XBT_DEBUG("Pushing task '%s' in the FIFO of workstation '%s'",
                SD_task_get_name(task),
                SD_workstation_get_name(workstation));
-        xbt_fifo_push(workstation->task_fifo, task);
+        xbt_fifo_push(SD_workstation_priv(workstation)->task_fifo, task);
       }
     }
     __SD_task_set_state(task, SD_IN_FIFO);
@@ -1165,23 +1203,23 @@ void __SD_task_just_done(SD_task_t task)
   for (i = 0; i < task->workstation_nb; i++) {
     workstation = task->workstation_list[i];
     XBT_DEBUG("Workstation '%s': access_mode = %d",
-              SD_workstation_get_name(workstation), (int)workstation->access_mode);
-    if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
-      xbt_assert(workstation->task_fifo != NULL,
+              SD_workstation_get_name(workstation), (int)SD_workstation_priv(workstation)->access_mode);
+    if (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
+      xbt_assert(SD_workstation_priv(workstation)->task_fifo != NULL,
                   "Workstation '%s' has sequential access but no FIFO!",
                   SD_workstation_get_name(workstation));
-      xbt_assert(workstation->current_task =
+      xbt_assert(SD_workstation_priv(workstation)->current_task =
                   task, "Workstation '%s': current task should be '%s'",
                   SD_workstation_get_name(workstation),
                   SD_task_get_name(task));
 
       /* the task is over so we can release the workstation */
-      workstation->current_task = NULL;
+      SD_workstation_priv(workstation)->current_task = NULL;
 
       XBT_DEBUG("Getting candidate in FIFO");
       candidate =
           xbt_fifo_get_item_content(xbt_fifo_get_first_item
-                                    (workstation->task_fifo));
+                                    (SD_workstation_priv(workstation)->task_fifo));
 
       if (candidate != NULL) {
         XBT_DEBUG("Candidate: '%s'", SD_task_get_name(candidate));
@@ -1235,10 +1273,10 @@ void __SD_task_just_done(SD_task_t task)
 
       /* I can start on this workstation if the workstation is shared
          or if I am the first task in the FIFO */
-      can_start = workstation->access_mode == SD_WORKSTATION_SHARED_ACCESS
+      can_start = SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SHARED_ACCESS
           || candidate ==
           xbt_fifo_get_item_content(xbt_fifo_get_first_item
-                                    (workstation->task_fifo));
+                                    (SD_workstation_priv(workstation)->task_fifo));
     }
 
     XBT_DEBUG("Candidate '%s' can start: %d", SD_task_get_name(candidate),
@@ -1250,8 +1288,8 @@ void __SD_task_just_done(SD_task_t task)
         workstation = candidate->workstation_list[j];
 
         /* update the FIFO */
-        if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
-          candidate = xbt_fifo_shift(workstation->task_fifo);   /* the return value is stored just for debugging */
+        if (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
+          candidate = xbt_fifo_shift(SD_workstation_priv(workstation)->task_fifo);   /* the return value is stored just for debugging */
           XBT_DEBUG("Head of the FIFO: '%s'",
                  (candidate !=
                   NULL) ? SD_task_get_name(candidate) : "NULL");
@@ -1348,9 +1386,10 @@ void SD_task_distribute_comp_amdhal(SD_task_t task, int ws_count)
               "Task %s is not a SD_TASK_COMP_PAR_AMDAHL typed task."
               "Cannot use this function.",
               SD_task_get_name(task));  
-              
   task->computation_amount = xbt_new0(double, ws_count);
   task->communication_amount = xbt_new0(double, ws_count * ws_count);
+  if (task->workstation_list)
+    xbt_free(task->workstation_list);
   task->workstation_nb = ws_count;
   task->workstation_list = xbt_new0(SD_workstation_t, ws_count);
   
@@ -1477,13 +1516,17 @@ void SD_task_schedulev(SD_task_t task, int count,
       SD_task_t before = dep->src;
       if (before->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
         if (!before->workstation_list){
-          XBT_VERB("Sender side of Task %s is not scheduled yet. Fill the workstation list with receiver side",
+          XBT_VERB("Sender side of Task %s is not scheduled yet",
              SD_task_get_name(before));
           before->workstation_list = xbt_new0(SD_workstation_t, count);
           before->workstation_nb = count;
+          XBT_VERB("Fill the workstation list with list of Task '%s'",
+            SD_task_get_name(task));
           for (i=0;i<count;i++)
             before->workstation_list[i] = task->workstation_list[i];
         } else {
+          XBT_VERB("Build communication matrix for task '%s'",
+             SD_task_get_name(before));
           int src_nb, dst_nb;
           double src_start, src_end, dst_start, dst_end;
           src_nb = before->workstation_nb;
@@ -1496,6 +1539,10 @@ void SD_task_schedulev(SD_task_t task, int count,
                task->workstation_list[i];
 
           before->workstation_nb += count;
+          if (before->computation_amount)
+            xbt_free(before->computation_amount);
+          if (before->communication_amount)
+            xbt_free(before->communication_amount);
 
           before->computation_amount = xbt_new0(double,
                                                 before->workstation_nb);
@@ -1538,10 +1585,12 @@ void SD_task_schedulev(SD_task_t task, int count,
       SD_task_t after = dep->dst;
       if (after->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
         if (!after->workstation_list){
-          XBT_VERB("Receiver side of Task %s is not scheduled yet. Fill the workstation list with sender side",
+          XBT_VERB("Receiver side of Task '%s' is not scheduled yet",
               SD_task_get_name(after));
           after->workstation_list = xbt_new0(SD_workstation_t, count);
           after->workstation_nb = count;
+          XBT_VERB("Fill the workstation list with list of Task '%s'",
+            SD_task_get_name(task));
           for (i=0;i<count;i++)
             after->workstation_list[i] = task->workstation_list[i];
         } else {
@@ -1559,6 +1608,11 @@ void SD_task_schedulev(SD_task_t task, int count,
 
           after->workstation_nb += count;
 
+          if (after->computation_amount)
+            xbt_free(after->computation_amount);
+          if (after->communication_amount)
+            xbt_free(after->communication_amount);
+
           after->computation_amount = xbt_new0(double, after->workstation_nb);
           after->communication_amount = xbt_new0(double,
                                                  after->workstation_nb*