Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
get rid of the last swag in SimDag (\o/), hence the encapsulation of
[simgrid.git] / examples / simdag / sd_typed_tasks_test.c
index 9326823..32f3e59 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2006-2010, 2012-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -6,7 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "simdag/simdag.h"
+#include "simgrid/simdag.h"
 #include "xbt/ex.h"
 #include "xbt/log.h"
 
 #include "xbt/ex.h"
 #include "xbt/log.h"
 
@@ -19,7 +19,8 @@ int main(int argc, char **argv)
   unsigned int ctr;
   const char *platform_file;
   const SD_workstation_t *workstations;
   unsigned int ctr;
   const char *platform_file;
   const SD_workstation_t *workstations;
-  SD_task_t task, taskA, taskB, taskC, taskD, taskE;
+  SD_task_t task, seq_comp1, e2e_comm, seq_comp2;
+  SD_task_t par_comp1, redist, par_comp2, par_comp3;
   xbt_dynar_t changed_tasks;
 
   double computation_amount[4];
   xbt_dynar_t changed_tasks;
 
   double computation_amount[4];
@@ -43,33 +44,45 @@ int main(int argc, char **argv)
  
   workstations = SD_workstation_get_list();
 
  
   workstations = SD_workstation_get_list();
 
-  for (i=0;i<SD_workstation_get_number();i++)
-    XBT_INFO("%s runs at %f flops", SD_workstation_get_name(workstations[i]),
-       SD_workstation_get_power(workstations[i]));
-
   /* creation of some typed tasks and their dependencies */
   /* creation of some typed tasks and their dependencies */
-  taskA = SD_task_create_comp_seq("Task A", NULL, 1e9);
-  taskB = SD_task_create_comm_e2e("Task B", NULL, 1e7);
-  taskC = SD_task_create_comp_seq("Task C", NULL, 1e9);
-  taskD = SD_task_create_comp_par_amdahl("Task D", NULL, 1e9, 0.2);
-  taskE = SD_task_create("Task E", NULL, 1e9);
+  seq_comp1 = SD_task_create_comp_seq("Seq. comp. 1", NULL, 1e9);
+  e2e_comm = SD_task_create_comm_e2e("E2E comm.", NULL, 1e7);
+  seq_comp2 = SD_task_create_comp_seq("Seq. comp 2.", NULL, 1e9);
+  par_comp1 = SD_task_create_comp_par_amdahl("Par. Comp. 1", NULL, 1e9, 0.2);
+  redist = SD_task_create_comm_par_mxn_1d_block("MxN redist", NULL, 1.2e8);
+  par_comp2 = SD_task_create_comp_par_amdahl("Par. Comp. 2", NULL, 3e8, 0.5);
+
+  par_comp3 = SD_task_create("Par. Comp. 3", NULL, 1e9);
+
+  SD_task_dependency_add(NULL, NULL, seq_comp1, e2e_comm);
+  SD_task_dependency_add(NULL, NULL, e2e_comm, seq_comp2);
+
+  SD_task_dependency_add(NULL, NULL, par_comp1, redist);
+  SD_task_dependency_add(NULL, NULL, redist, par_comp2);
+
+  SD_task_schedulel(seq_comp1, 1, workstations[8]);
+  SD_task_schedulel(seq_comp2, 1, workstations[9]);
 
 
-  SD_task_dependency_add(NULL, NULL, taskA, taskB);
-  SD_task_dependency_add(NULL, NULL, taskB, taskC);
+  SD_task_schedulev(par_comp1, 4, workstations);
+  SD_task_schedulev(par_comp2, 3, workstations);
 
 
-  SD_task_schedulel(taskA, 1, workstations[8]);
-  SD_task_schedulel(taskC, 1, workstations[9]);
+  /* Let's unschedule these tasks and test the auto-scheduling in the
+   * opposite way.
+   */
+  SD_task_unschedule(par_comp1);
+  SD_task_unschedule(par_comp2);
+  SD_task_unschedule(redist); /* yes, it was scheduled too */
 
 
-  SD_task_distribute_comp_amdhal(taskD, 4);
-  SD_task_schedulev(taskD, 4, workstations);
+  SD_task_schedulev(par_comp2, 3, workstations);
+  SD_task_schedulev(par_comp1, 4, workstations);
 
   for (i=0;i<4;i++){
     workstation_list[i]=workstations[i+4];
     /* Apply Amdahl's law manually assuming a 20% serial part */
 
   for (i=0;i<4;i++){
     workstation_list[i]=workstations[i+4];
     /* Apply Amdahl's law manually assuming a 20% serial part */
-    computation_amount[i]=(0.2 + (1 - 0.2)/4) * SD_task_get_amount(taskE);
+    computation_amount[i]=(0.2 + (1 - 0.2)/4) * SD_task_get_amount(par_comp3);
   }
 
   }
 
-  SD_task_schedule(taskE, 4, workstation_list,
+  SD_task_schedule(par_comp3, 4, workstation_list,
                    computation_amount, communication_amount, -1);
 
   changed_tasks = SD_simulate(-1.0);
                    computation_amount, communication_amount, -1);
 
   changed_tasks = SD_simulate(-1.0);
@@ -79,16 +92,9 @@ int main(int argc, char **argv)
           SD_task_get_start_time(task), SD_task_get_finish_time(task));
   }
 
           SD_task_get_start_time(task), SD_task_get_finish_time(task));
   }
 
-  XBT_DEBUG("Destroying tasks...");
-
-  SD_task_destroy(taskA);
-  SD_task_destroy(taskB);
-  SD_task_destroy(taskC);
-  SD_task_destroy(taskD);
-  SD_task_destroy(taskE);
-
-  XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
-
+  xbt_dynar_foreach(changed_tasks, ctr, task) {
+    SD_task_destroy(task);
+  }
   SD_exit();
   return 0;
 }
   SD_exit();
   return 0;
 }