1 /* simple test trying to load a DOT file. */
3 /* Copyright (c) 2010-2014. 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 */
40 dot = SD_dotload(argv[2]);
42 XBT_CRITICAL("No dot loaded. Do you have a cycle in your graph?");
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");
74 /* Schedule them all on the first workstation */
75 XBT_INFO("------------------- Schedule tasks ---------------------------");
76 const SD_workstation_t *ws_list = SD_workstation_get_list();
78 int count = SD_workstation_get_number();
79 xbt_dynar_foreach(dot, cursor, task) {
80 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
81 if (!strcmp(SD_task_get_name(task), "end"))
82 SD_task_schedulel(task, 1, ws_list[0]);
84 SD_task_schedulel(task, 1, ws_list[cursor % count]);
89 ("------------------- Run the schedule ---------------------------");
90 changed = SD_simulate(-1);
91 xbt_dynar_free_container(&changed);
93 ("------------------- Produce the trace file---------------------------");
94 XBT_INFO("Producing the trace of the run into %s", basename(tracefilename));
95 FILE *out = fopen(tracefilename, "w");
96 xbt_assert(out, "Cannot write to %s", tracefilename);
99 xbt_dynar_foreach(dot, cursor, task) {
100 int kind = SD_task_get_kind(task);
101 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
103 case SD_TASK_COMP_SEQ:
104 fprintf(out, "[%f->%f] %s compute %f flops # %s\n",
105 SD_task_get_start_time(task),
106 SD_task_get_finish_time(task),
107 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
108 SD_task_get_name(task));
110 case SD_TASK_COMM_E2E:
111 fprintf(out, "[%f -> %f] %s -> %s transfer of %.0f bytes # %s\n",
112 SD_task_get_start_time(task),
113 SD_task_get_finish_time(task),
114 SD_workstation_get_name(wsl[0]),
115 SD_workstation_get_name(wsl[1]), SD_task_get_amount(task),
116 SD_task_get_name(task));
119 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task),
120 SD_task_get_kind(task));
122 SD_task_destroy(task);
124 xbt_dynar_free_container(&dot);