Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a new example that use SD_task_set_rate to throttle a communication
authorsuter <frederic.suter@cc.in2p3.fr>
Fri, 15 Jun 2012 07:36:13 +0000 (09:36 +0200)
committersuter <frederic.suter@cc.in2p3.fr>
Fri, 15 Jun 2012 07:36:13 +0000 (09:36 +0200)
examples/simdag/CMakeLists.txt
examples/simdag/sd_comm_throttling.c [new file with mode: 0644]

index 8d99b16..6a619bb 100644 (file)
@@ -5,6 +5,7 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
 add_executable(ex_sd_test sd_test.c)
 add_executable(sd_test2 sd_test2.c)
 add_executable(sd_typed_tasks_test sd_typed_tasks_test.c)
+add_executable(sd_comm_throttling sd_comm_throttling.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)
@@ -14,6 +15,7 @@ if(NOT WIN32)
   target_link_libraries(ex_sd_test simgrid pthread m )
   target_link_libraries(sd_test2 simgrid pthread m )
   target_link_libraries(sd_typed_tasks_test simgrid pthread m )
+  target_link_libraries(sd_comm_throttling 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 )
@@ -32,6 +34,7 @@ else(NOT WIN32)
   target_link_libraries(ex_sd_test simgrid)
   target_link_libraries(sd_test2 simgrid)
   target_link_libraries(sd_typed_tasks_test simgrid)
+  target_link_libraries(sd_comm_throttling simgrid)
   target_link_libraries(sd_seq_access simgrid)
   target_link_libraries(sd_test_console simgrid)
   target_link_libraries(simdag_tracing simgrid)
@@ -66,6 +69,7 @@ set(examples_src
   ${CMAKE_CURRENT_SOURCE_DIR}/sd_test.c
   ${CMAKE_CURRENT_SOURCE_DIR}/sd_test_console.c
   ${CMAKE_CURRENT_SOURCE_DIR}/sd_typed_tasks_test.c
+  ${CMAKE_CURRENT_SOURCE_DIR}/sd_comm_throttling.c
   ${CMAKE_CURRENT_SOURCE_DIR}/simdag_trace.c
   PARENT_SCOPE
 )
diff --git a/examples/simdag/sd_comm_throttling.c b/examples/simdag/sd_comm_throttling.c
new file mode 100644 (file)
index 0000000..a9fb24f
--- /dev/null
@@ -0,0 +1,93 @@
+/* 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_comm_throttling,
+                             "Logging specific to this SimDag example");
+
+int main(int argc, char **argv)
+{
+  unsigned int ctr;
+  const char *platform_file;
+  const SD_workstation_t *workstations;
+  SD_task_t task, taskA, taskB, taskC, taskD, taskE;
+  xbt_dynar_t changed_tasks;
+
+  SD_workstation_t workstation_list[4];
+  
+  /* initialization of SD */
+  SD_init(&argc, argv);
+
+  /*  xbt_log_control_set("sd.thres=debug"); */
+
+  if (argc < 2) {
+    XBT_INFO("Usage: %s platform_file", argv[0]);
+    XBT_INFO("example: %s sd_platform.xml", argv[0]);
+    exit(1);
+  }
+
+  /* creation of the environment */
+  platform_file = argv[1];
+  SD_create_environment(platform_file);
+  workstations = SD_workstation_get_list();
+
+  /* creation of some typed tasks and their dependencies */
+  /* chain of five tasks, three compute tasks with two data transfers */
+  /* in between */
+  taskA = SD_task_create_comp_seq("Task A", NULL, 5e9);
+  taskB = SD_task_create_comm_e2e("Task B", NULL, 1e7);
+  taskC = SD_task_create_comp_seq("Task C", NULL, 5e9);
+  taskD = SD_task_create_comm_e2e("Task D", NULL, 1e7);
+  taskE = SD_task_create_comp_seq("Task E", NULL, 5e9);
+
+  SD_task_dependency_add(NULL, NULL, taskA, taskB);
+  SD_task_dependency_add(NULL, NULL, taskB, taskC);
+  SD_task_dependency_add(NULL, NULL, taskC, taskD);
+  SD_task_dependency_add(NULL, NULL, taskD, taskE);
+
+  /* Add watchpoints on completion of compute tasks */
+  SD_task_watch(taskA, SD_DONE);
+  SD_task_watch(taskC, SD_DONE);
+  SD_task_watch(taskE, SD_DONE);
+
+  /* Auto-schedule the compute tasks on three different workstations */
+  /* Data transfer tasks taskB and taskD are automagically scheduled */
+  SD_task_schedulel(taskA, 1, workstations[0]);
+  SD_task_schedulel(taskC, 1, workstations[1]);
+  SD_task_schedulel(taskE, 1, workstations[0]);
+  while (!xbt_dynar_is_empty((changed_tasks = SD_simulate(-1.0)))) {
+    XBT_INFO("Simulation stopped after %.4f seconds", SD_get_clock());
+    xbt_dynar_foreach(changed_tasks, ctr, task) {
+      XBT_INFO("Task '%s' start time: %f, finish time: %f",
+              SD_task_get_name(task),
+              SD_task_get_start_time(task), 
+              SD_task_get_finish_time(task));
+    }
+    /* let throttle the communication for taskD if its parent is SD_DONE */
+    if (SD_task_get_state(taskC) == SD_DONE)
+      SD_task_set_rate(taskD, 0.5);
+  }
+
+  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...");
+
+  SD_exit();
+  return 0;
+}