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"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
18 "Logging specific to this SimDag example");
20 int main(int argc, char **argv)
22 xbt_dynar_t dot, changed;
26 /* initialisation of SD */
29 /* Check our arguments */
31 XBT_INFO("Usage: %s platform_file dot_file [trace_file]", argv[0]);
32 XBT_INFO("example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0]);
37 char *last = strrchr(argv[2], '.');
41 (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),
44 tracefilename = xbt_strdup(argv[3]);
47 /* creation of the environment */
48 SD_create_environment(argv[1]);
50 /* load the DOT file and schedule tasks */
51 dot = SD_dotload_with_sched(argv[2]);
54 xbt_die("The dot file with the provided scheduling is wrong, more information with the option : --log=sd_dotparse.thres:verbose");
57 /* Display all the tasks */
59 ("------------------- Display all tasks of the loaded DAG ---------------------------");
60 xbt_dynar_foreach(dot, cursor, task) {
64 FILE *dotout = fopen("dot.dot", "w");
65 fprintf(dotout, "digraph A {\n");
66 xbt_dynar_foreach(dot, cursor, task) {
67 SD_task_dotty(task, dotout);
69 fprintf(dotout, "}\n");
73 ("------------------- Run the schedule ---------------------------");
74 changed = SD_simulate(-1);
75 xbt_dynar_free_container(&changed);
77 ("------------------- Produce the trace file---------------------------");
78 XBT_INFO("Producing the trace of the run into %s", basename(tracefilename));
79 FILE *out = fopen(tracefilename, "w");
80 xbt_assert(out, "Cannot write to %s", tracefilename);
83 xbt_dynar_foreach(dot, cursor, task) {
84 int kind = SD_task_get_kind(task);
85 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
87 case SD_TASK_COMP_SEQ:
88 fprintf(out, "[%f] %s compute %f # %s\n",
89 SD_task_get_start_time(task),
90 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
91 SD_task_get_name(task));
93 case SD_TASK_COMM_E2E:
94 fprintf(out, "[%f] %s send %s %f # %s\n",
95 SD_task_get_start_time(task),
96 SD_workstation_get_name(wsl[0]),
97 SD_workstation_get_name(wsl[1]), SD_task_get_amount(task),
98 SD_task_get_name(task));
99 fprintf(out, "[%f] %s recv %s %f # %s\n",
100 SD_task_get_finish_time(task),
101 SD_workstation_get_name(wsl[1]),
102 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
103 SD_task_get_name(task));
106 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task),
107 SD_task_get_kind(task));
109 SD_task_destroy(task);