Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adding an example of simdag with tracing functions
authorschnorr <schnorr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 19 Oct 2010 12:01:13 +0000 (12:01 +0000)
committerschnorr <schnorr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 19 Oct 2010 12:01:13 +0000 (12:01 +0000)
details:
- three categories created, one for each task

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8433 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/simdag/CMakeLists.txt
examples/simdag/simdag_trace.c [new file with mode: 0644]

index b0b9f03..56f28b0 100644 (file)
@@ -6,6 +6,7 @@ add_executable(ex_sd_test sd_test.c)
 add_executable(sd_test2 sd_test2.c)
 add_executable(sd_seq_access sd_seq_access.c)
 add_executable(sd_test_console sd_test_console.c)
+add_executable(simdag_tracing simdag_trace.c)
 
 ### Add definitions for compile
 if(NOT WIN32)
@@ -13,6 +14,7 @@ if(NOT WIN32)
        target_link_libraries(sd_test2 simgrid pthread m )
        target_link_libraries(sd_seq_access simgrid pthread m )
        target_link_libraries(sd_test_console simgrid pthread m )
+       target_link_libraries(simdag_tracing simgrid pthread m )
        
        add_custom_command(TARGET ex_sd_test
                POST_BUILD
@@ -29,6 +31,7 @@ else(NOT WIN32)
        target_link_libraries(sd_test2 simgrid)
        target_link_libraries(sd_seq_access simgrid)
        target_link_libraries(sd_test_console simgrid)
+       target_link_libraries(simdag_tracing simgrid)
        
        add_custom_command(TARGET ex_sd_test
                POST_BUILD
diff --git a/examples/simdag/simdag_trace.c b/examples/simdag/simdag_trace.c
new file mode 100644 (file)
index 0000000..3ec3954
--- /dev/null
@@ -0,0 +1,141 @@
+/* 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. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "simdag/simdag.h"
+#include "xbt/ex.h"
+#include "xbt/log.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(sd_seq_access,
+                             "Logging specific to this SimDag example");
+
+int main(int argc, char **argv)
+{
+  int i;
+  const char *platform_file;
+  const SD_workstation_t *workstations;
+  int kind;
+  SD_task_t task, taskA, taskB, taskC;
+  xbt_dynar_t changed_tasks;
+  SD_workstation_t workstation_list[2];
+  double computation_amount[2];
+  double communication_amount[4] = { 0 };
+  double rate = -1.0;
+  SD_workstation_t w1, w2;
+
+  /* initialisation of SD */
+  SD_init(&argc, argv);
+
+  TRACE_start ();
+
+  /*  xbt_log_control_set("sd.thres=debug"); */
+
+  if (argc < 2) {
+    INFO1("Usage: %s platform_file", argv[0]);
+    INFO1("example: %s sd_platform.xml", argv[0]);
+    exit(1);
+  }
+
+  /* creation of the environment */
+  platform_file = argv[1];
+  SD_create_environment(platform_file);
+
+  /* Change the access mode of the workstations */
+  workstations = SD_workstation_get_list();
+  w1 = workstations[0];
+  w2 = workstations[1];
+  for (i = 0; i < 2; i++) {
+    SD_workstation_set_access_mode(workstations[i],
+                                   SD_WORKSTATION_SEQUENTIAL_ACCESS);
+    INFO2("Access mode of %s is %s",
+          SD_workstation_get_name(workstations[i]),
+          (SD_workstation_get_access_mode(workstations[i]) ==
+           SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
+  }
+
+  /* creation of the tasks and their dependencies */
+  taskA = SD_task_create_comp_seq("Task A", NULL, 2e9);
+  taskB = SD_task_create_comm_e2e("Task B", NULL, 2e9);
+  taskC = SD_task_create_comp_seq("Task C", NULL, 1e9);
+  TRACE_category ("taskA");
+  TRACE_category ("taskB");
+  TRACE_category ("taskC");
+  TRACE_sd_set_task_category (taskA, "taskA");
+  TRACE_sd_set_task_category (taskB, "taskB");
+  TRACE_sd_set_task_category (taskC, "taskC");
+
+  /* if everything is ok, no exception is forwarded or rethrown by main() */
+
+  /* watch points */
+  SD_task_watch(taskA, SD_RUNNING);
+  SD_task_watch(taskB, SD_RUNNING);
+  SD_task_watch(taskC, SD_RUNNING);
+  SD_task_watch(taskC, SD_DONE);
+
+
+  /* scheduling parameters */
+  workstation_list[0] = w1;
+  workstation_list[1] = w2;
+  computation_amount[0] = SD_task_get_amount(taskA);
+  computation_amount[1] = SD_task_get_amount(taskB);
+
+  communication_amount[1] = SD_task_get_amount(taskC);
+  communication_amount[2] = 0.0;
+
+  SD_task_schedule(taskA, 1, &w1,
+                   &(computation_amount[0]), SD_SCHED_NO_COST, rate);
+  SD_task_schedule(taskB, 2, workstation_list,
+                   SD_SCHED_NO_COST, communication_amount, rate);
+  SD_task_schedule(taskC, 1, &w1,
+                   &(computation_amount[1]), SD_SCHED_NO_COST, rate);
+
+  /* let's launch the simulation! */
+  while (xbt_dynar_length(changed_tasks = SD_simulate(-1.0)) > 0) {
+    for (i = 0; i < 2; i++) {
+      task = SD_workstation_get_current_task(workstations[i]);
+      if (task)
+        kind = SD_task_get_kind(task);
+      else {
+        INFO1("There is no task running on %s",
+              SD_workstation_get_name(workstations[i]));
+        continue;
+      }
+
+      switch (kind) {
+      case SD_TASK_COMP_SEQ:
+        INFO2("%s is currently running on %s (SD_TASK_COMP_SEQ)",
+              SD_task_get_name(task),
+              SD_workstation_get_name(workstations[i]));
+        break;
+      case SD_TASK_COMM_E2E:
+        INFO2("%s is currently running on %s (SD_TASK_COMM_E2E)",
+              SD_task_get_name(task),
+              SD_workstation_get_name(workstations[i]));
+        break;
+      case SD_TASK_NOT_TYPED:
+        INFO1("Task running on %s has no type",
+              SD_workstation_get_name(workstations[i]));
+        break;
+      default:
+        ERROR0("Shouldn't be here");
+      }
+    }
+    xbt_dynar_free_container(&changed_tasks);
+  }
+
+  DEBUG0("Destroying tasks...");
+
+  SD_task_destroy(taskA);
+  SD_task_destroy(taskB);
+  SD_task_destroy(taskC);
+
+  DEBUG0("Tasks destroyed. Exiting SimDag...");
+
+  SD_exit();
+  TRACE_end();
+  return 0;
+}