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"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
17 "Logging specific to this SimDag example");
19 int main(int argc, char **argv)
21 xbt_dynar_t dot, changed;
25 /* initialisation of SD */
30 /* Check our arguments */
32 INFO1("Usage: %s platform_file dot_file [trace_file]", argv[0]);
33 INFO1("example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0]);
38 char *last = strrchr(argv[2], '.');
42 (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),
45 tracefilename = xbt_strdup(argv[3]);
48 /* creation of the environment */
49 SD_create_environment(argv[1]);
51 /* load the DOT file */
52 dot = SD_dotload(argv[2]);
54 /* Display all the tasks */
56 ("------------------- Display all tasks of the loaded DAG ---------------------------");
57 xbt_dynar_foreach(dot, cursor, task) {
61 FILE *dotout = fopen("dot.dot", "w");
62 fprintf(dotout, "digraph A {\n");
63 xbt_dynar_foreach(dot, cursor, task) {
64 SD_task_dotty(task, dotout);
66 fprintf(dotout, "}\n");
69 /* Schedule them all on the first workstation */
70 INFO0("------------------- Schedule tasks ---------------------------");
71 const SD_workstation_t *ws_list = SD_workstation_get_list();
73 int count = SD_workstation_get_number();
74 xbt_dynar_foreach(dot, cursor, task) {
75 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
76 if (!strcmp(SD_task_get_name(task), "end"))
77 SD_task_schedulel(task, 1, ws_list[0]);
79 SD_task_schedulel(task, 1, ws_list[cursor % count]);
84 ("------------------- Run the schedule ---------------------------");
85 changed = SD_simulate(-1);
86 xbt_dynar_free_container(&changed);
88 ("------------------- Produce the trace file---------------------------");
89 INFO1("Producing the trace of the run into %s", tracefilename);
90 FILE *out = fopen(tracefilename, "w");
91 xbt_assert1(out, "Cannot write to %s", tracefilename);
94 xbt_dynar_foreach(dot, cursor, task) {
95 int kind = SD_task_get_kind(task);
96 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
98 case SD_TASK_COMP_SEQ:
99 fprintf(out, "[%f] %s compute %f # %s\n",
100 SD_task_get_start_time(task),
101 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
102 SD_task_get_name(task));
104 case SD_TASK_COMM_E2E:
105 fprintf(out, "[%f] %s send %s %f # %s\n",
106 SD_task_get_start_time(task),
107 SD_workstation_get_name(wsl[0]),
108 SD_workstation_get_name(wsl[1]), SD_task_get_amount(task),
109 SD_task_get_name(task));
110 fprintf(out, "[%f] %s recv %s %f # %s\n",
111 SD_task_get_finish_time(task),
112 SD_workstation_get_name(wsl[1]),
113 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
114 SD_task_get_name(task));
118 ("Task %s is of unknown kind %d", SD_task_get_name(task),
119 SD_task_get_kind(task)));
121 SD_task_destroy(task);