1 /* simple test trying to load a DOT file. */
3 /* Copyright (c) 2010-2013. 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 /* initialization 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]);
36 /* creation of the environment */
37 SD_create_environment(argv[1]);
39 /* load the DOT file and schedule tasks */
40 dot = SD_dotload_with_sched(argv[2]);
42 XBT_CRITICAL("The dot file with the provided scheduling is wrong, more information with the option : --log=sd_dotparse.thres:verbose");
49 char *last = strrchr(argv[2], '.');
53 (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),
56 tracefilename = xbt_strdup(argv[3]);
59 /* Display all the tasks */
61 ("------------------- Display all tasks of the loaded DAG ---------------------------");
62 xbt_dynar_foreach(dot, cursor, task) {
66 FILE *dotout = fopen("dot.dot", "w");
67 fprintf(dotout, "digraph A {\n");
68 xbt_dynar_foreach(dot, cursor, task) {
69 SD_task_dotty(task, dotout);
71 fprintf(dotout, "}\n");
75 ("------------------- Run the schedule ---------------------------");
76 changed = SD_simulate(-1);
77 xbt_dynar_free_container(&changed);
79 ("------------------- Produce the trace file---------------------------");
80 XBT_INFO("Producing the trace of the run into %s", basename(tracefilename));
81 FILE *out = fopen(tracefilename, "w");
82 xbt_assert(out, "Cannot write to %s", tracefilename);
85 xbt_dynar_foreach(dot, cursor, task) {
86 int kind = SD_task_get_kind(task);
87 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
89 case SD_TASK_COMP_SEQ:
90 fprintf(out, "[%f->%f] %s compute %f flops # %s\n",
91 SD_task_get_start_time(task),
92 SD_task_get_finish_time(task),
93 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
94 SD_task_get_name(task));
96 case SD_TASK_COMM_E2E:
97 fprintf(out, "[%f -> %f] %s -> %s transfer of %.0f bytes # %s\n",
98 SD_task_get_start_time(task),
99 SD_task_get_finish_time(task),
100 SD_workstation_get_name(wsl[0]),
101 SD_workstation_get_name(wsl[1]), 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);
111 xbt_dynar_free_container(&dot);