Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
81c0b421c2b783b490222a476862a84b3d4a1000
[simgrid.git] / examples / simdag / dot / dot_test2.c
1 /* simple test trying to load a DOT file.                                   */
2
3 /* Copyright (c) 2010-2015. 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 "simgrid/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     XBT_INFO("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   XBT_INFO
39       ("------------------- Display all tasks of the loaded DAG ---------------------------");
40   xbt_dynar_foreach(dot, cursor, task) {
41       SD_task_dump(task);
42     }
43
44   XBT_INFO
45       ("--------------------- Transform the dynar into an array ---------------------------");
46   cursor=0;
47   dot_as_array = (SD_task_t*) xbt_dynar_to_array(dot);
48   XBT_INFO
49       ("----------------------------- dump tasks again ------------------------------------");
50   while ((task=dot_as_array[cursor++])){
51     SD_task_dump(task);
52   }
53
54   cursor=0;
55   while ((task=dot_as_array[cursor++])){
56     SD_task_destroy(task);
57   }
58
59   free(dot_as_array);
60
61   /* exit */
62   SD_exit();
63   return 0;
64 }