1 /* simple test trying to load a DOT file. */
3 /* Copyright (c) 2010. The SimGrid Team.
4 * All rights reserved. */
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. */
11 #include "simdag/simdag.h"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
17 "Logging specific to this SimDag example");
19 int main(int argc, char **argv)
21 xbt_dynar_t dot, changed;
25 /* initialisation of SD */
28 /* Check our arguments */
30 XBT_INFO("Usage: %s platform_file dot_file [trace_file]", argv[0]);
31 XBT_INFO("example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0]);
36 char *last = strrchr(argv[2], '.');
40 (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),
43 tracefilename = xbt_strdup(argv[3]);
46 /* creation of the environment */
47 SD_create_environment(argv[1]);
49 /* load the DOT file and schedule tasks */
50 dot = SD_dotload_with_sched(argv[2]);
52 XBT_INFO("The dot file with the provided scheduling is wrong, more information with the option : --log=sd_dotparse.thres:verbose");
56 /* Display all the tasks */
58 ("------------------- Display all tasks of the loaded DAG ---------------------------");
59 xbt_dynar_foreach(dot, cursor, task) {
63 FILE *dotout = fopen("dot.dot", "w");
64 fprintf(dotout, "digraph A {\n");
65 xbt_dynar_foreach(dot, cursor, task) {
66 SD_task_dotty(task, dotout);
68 fprintf(dotout, "}\n");
72 ("------------------- Run the schedule ---------------------------");
73 changed = SD_simulate(-1);
74 xbt_dynar_free_container(&changed);
76 ("------------------- Produce the trace file---------------------------");
77 XBT_INFO("Producing the trace of the run into %s", tracefilename);
78 FILE *out = fopen(tracefilename, "w");
79 xbt_assert(out, "Cannot write to %s", tracefilename);
82 xbt_dynar_foreach(dot, cursor, task) {
83 int kind = SD_task_get_kind(task);
84 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
86 case SD_TASK_COMP_SEQ:
87 fprintf(out, "[%f] %s compute %f # %s\n",
88 SD_task_get_start_time(task),
89 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
90 SD_task_get_name(task));
92 case SD_TASK_COMM_E2E:
93 fprintf(out, "[%f] %s send %s %f # %s\n",
94 SD_task_get_start_time(task),
95 SD_workstation_get_name(wsl[0]),
96 SD_workstation_get_name(wsl[1]), SD_task_get_amount(task),
97 SD_task_get_name(task));
98 fprintf(out, "[%f] %s recv %s %f # %s\n",
99 SD_task_get_finish_time(task),
100 SD_workstation_get_name(wsl[1]),
101 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
102 SD_task_get_name(task));
105 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task),
106 SD_task_get_kind(task));
108 SD_task_destroy(task);