1 /* simple test trying to load a DOT file. */
3 /* Copyright (c) 2010-2016. 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. */
10 #include "simgrid/simdag.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
17 int main(int argc, char **argv)
23 /* initialization of SD */
26 /* Check our arguments */
27 xbt_assert(argc > 2, "Usage: %s platform_file dot_file [trace_file]"
28 "example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0], argv[0]);
30 /* creation of the environment */
31 SD_create_environment(argv[1]);
33 /* load the DOT file and schedule tasks */
34 dot = SD_dotload_with_sched(argv[2]);
36 XBT_CRITICAL("The dot file with the provided scheduling is wrong, more information with the option : --log=sd_dotparse.thres:verbose");
42 char *last = strrchr(argv[2], '.');
43 tracefilename = bprintf("%.*s.trace", (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),argv[2]);
45 tracefilename = xbt_strdup(argv[3]);
48 /* Display all the tasks */
49 XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
50 xbt_dynar_foreach(dot, cursor, task) {
54 FILE *dotout = fopen("dot.dot", "w");
55 fprintf(dotout, "digraph A {\n");
56 xbt_dynar_foreach(dot, cursor, task) {
57 SD_task_dotty(task, dotout);
59 fprintf(dotout, "}\n");
62 XBT_INFO("------------------- Run the schedule ---------------------------");
65 XBT_INFO("------------------- Produce the trace file---------------------------");
66 XBT_INFO("Producing the trace of the run into %s", basename(tracefilename));
67 FILE *out = fopen(tracefilename, "w");
68 xbt_assert(out, "Cannot write to %s", tracefilename);
71 xbt_dynar_foreach(dot, cursor, task) {
72 int kind = SD_task_get_kind(task);
73 sg_host_t *wsl = SD_task_get_workstation_list(task);
75 case SD_TASK_COMP_SEQ:
76 fprintf(out, "[%f->%f] %s compute %f flops # %s\n",
77 SD_task_get_start_time(task), SD_task_get_finish_time(task),
78 sg_host_get_name(wsl[0]), SD_task_get_amount(task), SD_task_get_name(task));
80 case SD_TASK_COMM_E2E:
81 fprintf(out, "[%f -> %f] %s -> %s transfer of %.0f bytes # %s\n",
82 SD_task_get_start_time(task), SD_task_get_finish_time(task),
83 sg_host_get_name(wsl[0]), sg_host_get_name(wsl[1]), SD_task_get_amount(task), SD_task_get_name(task));
86 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task), SD_task_get_kind(task));
88 SD_task_destroy(task);
91 xbt_dynar_free_container(&dot);