Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
xbt_dynar_to_array now destroys the dynar. The caller is now only responsible of...
[simgrid.git] / examples / simdag / dot / dot_test2.c
1 /* simple test trying to load a DOT file.                                   */
2
3 /* Copyright (c) 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include "simdag/simdag.h"
12 #include "xbt/log.h"
13 #include "xbt/ex.h"
14 #include <string.h>
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
17                              "Logging specific to this SimDag example");
18
19 int main(int argc, char **argv)
20 {
21   xbt_dynar_t dot;
22   unsigned int cursor;
23   SD_task_t task, *dot_as_array=NULL;
24
25   /* initialisation of SD */
26   SD_init(&argc, argv);
27
28   /* Check our arguments */
29   if (argc < 2) {
30     INFO1("Usage: %s dot_file", argv[0]);
31     exit(1);
32   }
33
34   /* load the DOT file */
35   dot = SD_dotload(argv[1]);
36
37   /* Display all the tasks */
38   INFO0
39       ("------------------- Display all tasks of the loaded DAG ---------------------------");
40   xbt_dynar_foreach(dot, cursor, task) {
41       SD_task_dump(task);
42     }
43
44   INFO0
45       ("--------------------- Transform the dynar into an array ---------------------------");
46   cursor=0;
47   dot_as_array = (SD_task_t*) xbt_dynar_to_array(dot);
48   INFO0
49       ("----------------------------- dump tasks again ------------------------------------");
50   while ((task=dot_as_array[cursor++])){
51     SD_task_dump(task);
52   }
53
54   xbt_dynar_foreach(dot, cursor, task) {
55     SD_task_destroy(task);
56   }
57
58   free(&dot_as_array);
59
60   /* exit */
61   SD_exit();
62   return 0;
63 }