Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a new example to test xbt_dynar_to_array
authorsuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 2 Dec 2010 13:58:57 +0000 (13:58 +0000)
committersuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 2 Dec 2010 13:58:57 +0000 (13:58 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8887 48e7efb5-ca39-0410-a469-dd3cf9ba447f

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

index 9771852..6cfac8f 100644 (file)
@@ -1,14 +1,16 @@
 cmake_minimum_required(VERSION 2.6)
 
-set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")                      
+set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")              
+       
+#add_executable(<name_of_target> <src list>)
+add_executable(dot_test dot_test.c)
+add_executable(simulate_dot simulate_dot.c)
+add_executable(dot_test2 dot_test2.c)
 
-add_executable(dot_test dot_test.c)                                    #add_executable(<name_of_target> <src list>)
-add_executable(simulate_dot simulate_dot.c)                                    #add_executable(<name_of_target> <src list>)
-
-### Add definitions for compile
 if(NOT WIN32)
   target_link_libraries(dot_test simgrid pthread m)    #target_link_libraries(<name_of_targe> <dependencies>)
   target_link_libraries(simulate_dot simgrid pthread m)        #target_link_libraries(<name_of_targe> <dependencies>)
+  target_link_libraries(dot_test2 simgrid pthread m)   #target_link_libraries(<name_of_targe> <dependencies>)
 
        get_directory_property(extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
        set_directory_properties(
@@ -18,6 +20,7 @@ if(NOT WIN32)
 else(NOT WIN32)
   target_link_libraries(dot_test simgrid)      #target_link_libraries(<name_of_targe> <dependencies>)
   target_link_libraries(simulate_dot simgrid)  #target_link_libraries(<name_of_targe> <dependencies>)
+  target_link_libraries(dot_test2 simgrid)     #target_link_libraries(<name_of_targe> <dependencies>)
        set_directory_properties(
         PROPERTIES
         ADDITIONAL_MAKE_CLEAN_FILES "${extra_clean_files};${CMAKE_CURRENT_BINARY_DIR}/dot_test; ${CMAKE_CURRENT_BINARY_DIR}/simulate_dot;")
diff --git a/examples/simdag/dot/dot_test2.c b/examples/simdag/dot/dot_test2.c
new file mode 100644 (file)
index 0000000..8ea2f54
--- /dev/null
@@ -0,0 +1,63 @@
+/* simple test trying to load a DOT file.                                   */
+
+/* Copyright (c) 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 <stdlib.h>
+#include <stdio.h>
+#include "simdag/simdag.h"
+#include "xbt/log.h"
+#include "xbt/ex.h"
+#include <string.h>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(test,
+                             "Logging specific to this SimDag example");
+
+int main(int argc, char **argv)
+{
+  xbt_dynar_t dot;
+  unsigned int cursor;
+  SD_task_t task, *dot_as_array=NULL;
+
+  /* initialisation of SD */
+  SD_init(&argc, argv);
+
+  /* Check our arguments */
+  if (argc < 1) {
+    INFO1("Usage: %s dot_file", argv[0]);
+    exit(1);
+  }
+
+  /* load the DOT file */
+  dot = SD_dotload(argv[1]);
+
+  /* Display all the tasks */
+  INFO0
+      ("------------------- Display all tasks of the loaded DAG ---------------------------");
+  xbt_dynar_foreach(dot, cursor, task) {
+      SD_task_dump(task);
+    }
+
+  INFO0
+      ("--------------------- Transform the dynar into an array ---------------------------");
+  cursor=0;
+  dot_as_array = (SD_task_t*) xbt_dynar_to_array(dot);
+  INFO0
+      ("----------------------------- dump tasks again ------------------------------------");
+  while ((task=dot_as_array[cursor++])){
+    SD_task_dump(task);
+  }
+
+  xbt_dynar_foreach(dot, cursor, task) {
+    SD_task_destroy(task);
+  }
+
+  xbt_dynar_free_container(&dot);
+
+  /* exit */
+  SD_exit();
+  return 0;
+}