Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add/update copyright notices.
[simgrid.git] / examples / simdag / dot / ptg_test.c
1 /* Copyright (c) 2013-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include "simdag/simdag.h"
10 #include "xbt/log.h"
11 #include "xbt/ex.h"
12 #include <string.h>
13 #include <libgen.h>
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
16                              "Logging specific to this SimDag example");
17
18 /* simple test trying to load a Parallel Task Graph (PTG) as a DOT file.    */
19 int main(int argc, char **argv){
20   xbt_dynar_t dot;
21   unsigned int cursor;
22   SD_task_t task;
23
24   /* initialization of SD */
25   SD_init(&argc, argv);
26
27   /* Check our arguments */
28   if (argc < 2) {
29     XBT_INFO("Usage: %s platform_file dot_file ", argv[0]);
30     XBT_INFO("example: %s ../2clusters.xml ptg.dot", argv[0]);
31     exit(1);
32   }
33
34   /* creation of the environment */
35   SD_create_environment(argv[1]);
36
37   /* load the DOT file */
38   dot = SD_PTG_dotload(argv[2]);
39   if(dot == NULL){
40     SD_exit();
41     xbt_die("No dot load may be you have a cycle in your graph");
42   }
43
44   /* Display all the tasks */
45   XBT_INFO
46       ("------------------- Display all tasks of the loaded DAG ---------------------------");
47   xbt_dynar_foreach(dot, cursor, task) {
48     SD_task_dump(task);
49   }
50
51   FILE *dotout = fopen("dot.dot", "w");
52   fprintf(dotout, "digraph A {\n");
53   xbt_dynar_foreach(dot, cursor, task) {
54     SD_task_dotty(task, dotout);
55   }
56   fprintf(dotout, "}\n");
57   fclose(dotout);
58
59   /* Schedule them all on all the first workstation */
60   XBT_INFO("------------------- Schedule tasks ---------------------------");
61   const SD_workstation_t *ws_list = SD_workstation_get_list();
62   int count = SD_workstation_get_number();
63   xbt_dynar_foreach(dot, cursor, task) {
64     if (SD_task_get_kind(task) == SD_TASK_COMP_PAR_AMDAHL) {
65         SD_task_schedulev(task, count, ws_list);
66     }
67   }
68
69   XBT_INFO
70       ("------------------- Run the schedule ---------------------------");
71   SD_simulate(-1);
72   XBT_INFO("Makespan: %f", SD_get_clock());
73   xbt_dynar_foreach(dot, cursor, task) {
74     SD_task_destroy(task);
75   }
76   xbt_dynar_free_container(&dot);
77
78   /* exit */
79   SD_exit();
80   return 0;
81 }