Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
aa0c2c4e95a19e973e61746d262f491b72fd0009
[simgrid.git] / examples / simdag / dot / ptg_test.c
1 /* Copyright (c) 2013-2016. 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 <stdio.h>
8 #include "simgrid/simdag.h"
9 #include "xbt/log.h"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
12
13 /* simple test trying to load a Parallel Task Graph (PTG) as a DOT file.    */
14 int main(int argc, char **argv){
15   xbt_dynar_t dot;
16   unsigned int cursor;
17   SD_task_t task;
18
19   /* initialization of SD */
20   SD_init(&argc, argv);
21
22   /* Check our arguments */
23   xbt_assert (argc > 1,"Usage: %s platform_file dot_file example: %s ../2clusters.xml ptg.dot", argv[0], argv[0]);
24
25   /* creation of the environment */
26   SD_create_environment(argv[1]);
27
28   /* load the DOT file */
29   dot = SD_PTG_dotload(argv[2]);
30   if(dot == NULL){
31     SD_exit();
32     xbt_die("No dot load may be you have a cycle in your graph");
33   }
34
35   /* Display all the tasks */
36   XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
37   xbt_dynar_foreach(dot, cursor, task) {
38     SD_task_dump(task);
39   }
40
41   FILE *dotout = fopen("dot.dot", "w");
42   fprintf(dotout, "digraph A {\n");
43   xbt_dynar_foreach(dot, cursor, task) {
44     SD_task_dotty(task, dotout);
45   }
46   fprintf(dotout, "}\n");
47   fclose(dotout);
48
49   /* Schedule them all on all the first workstation */
50   XBT_INFO("------------------- Schedule tasks ---------------------------");
51   const sg_host_t *ws_list = sg_host_list();
52   int count = sg_host_count();
53   xbt_dynar_foreach(dot, cursor, task) {
54     if (SD_task_get_kind(task) == SD_TASK_COMP_PAR_AMDAHL) {
55         SD_task_schedulev(task, count, ws_list);
56     }
57   }
58
59   XBT_INFO("------------------- Run the schedule ---------------------------");
60   SD_simulate(-1);
61   XBT_INFO("Makespan: %f", SD_get_clock());
62   xbt_dynar_foreach(dot, cursor, task) {
63     SD_task_destroy(task);
64   }
65   xbt_dynar_free_container(&dot);
66
67   /* exit */
68   SD_exit();
69   return 0;
70 }