1 /* simple test trying to load a DOT file. */
3 /* Copyright (c) 2010-2015. 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 "simgrid/simdag.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
19 int main(int argc, char **argv)
25 /* initialization of SD */
28 /* Check our arguments */
29 xbt_assert(argc > 2, "Usage: %s platform_file dot_file [trace_file]"
30 "example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0], argv[0]);
32 /* creation of the environment */
33 SD_create_environment(argv[1]);
35 /* load the DOT file */
36 dot = SD_dotload(argv[2]);
38 XBT_CRITICAL("No dot loaded. Do you have a cycle in your graph?");
44 char *last = strrchr(argv[2], '.');
45 tracefilename = bprintf("%.*s.trace", (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),argv[2]);
47 tracefilename = xbt_strdup(argv[3]);
49 /* Display all the tasks */
50 XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
51 xbt_dynar_foreach(dot, cursor, task) {
55 FILE *dotout = fopen("dot.dot", "w");
56 fprintf(dotout, "digraph A {\n");
57 xbt_dynar_foreach(dot, cursor, task) {
58 SD_task_dotty(task, dotout);
60 fprintf(dotout, "}\n");
63 /* Schedule them all on the first workstation */
64 XBT_INFO("------------------- Schedule tasks ---------------------------");
65 const sg_host_t *ws_list = sg_host_list();
67 int count = sg_host_count();
68 xbt_dynar_foreach(dot, cursor, task) {
69 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
70 if (!strcmp(SD_task_get_name(task), "end"))
71 SD_task_schedulel(task, 1, ws_list[0]);
73 SD_task_schedulel(task, 1, ws_list[cursor % count]);
77 XBT_INFO("------------------- Run the schedule ---------------------------");
80 XBT_INFO("------------------- Produce the trace file---------------------------");
81 XBT_INFO("Producing the trace of the run into %s", basename(tracefilename));
82 FILE *out = fopen(tracefilename, "w");
83 xbt_assert(out, "Cannot write to %s", tracefilename);
86 xbt_dynar_foreach(dot, cursor, task) {
87 int kind = SD_task_get_kind(task);
88 sg_host_t *wsl = SD_task_get_workstation_list(task);
90 case SD_TASK_COMP_SEQ:
91 fprintf(out, "[%f->%f] %s compute %f flops # %s\n",
92 SD_task_get_start_time(task), SD_task_get_finish_time(task),
93 sg_host_get_name(wsl[0]), SD_task_get_amount(task), SD_task_get_name(task));
95 case SD_TASK_COMM_E2E:
96 fprintf(out, "[%f -> %f] %s -> %s transfer of %.0f bytes # %s\n",
97 SD_task_get_start_time(task), SD_task_get_finish_time(task),
98 sg_host_get_name(wsl[0]), sg_host_get_name(wsl[1]), SD_task_get_amount(task), SD_task_get_name(task));
101 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task), SD_task_get_kind(task));
103 SD_task_destroy(task);
105 xbt_dynar_free_container(&dot);