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. */
9 #include "simgrid/simdag.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
16 int main(int argc, char **argv)
22 /* initialization of SD */
25 /* Check our arguments */
26 xbt_assert(argc > 2, "Usage: %s platform_file dot_file [trace_file]"
27 "example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0], argv[0]);
29 /* creation of the environment */
30 SD_create_environment(argv[1]);
32 /* load the DOT file */
33 dot = SD_dotload(argv[2]);
35 XBT_CRITICAL("No dot loaded. Do you have a cycle in your graph?");
41 char *last = strrchr(argv[2], '.');
42 tracefilename = bprintf("%.*s.trace", (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),argv[2]);
44 tracefilename = xbt_strdup(argv[3]);
46 /* Display all the tasks */
47 XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
48 xbt_dynar_foreach(dot, cursor, task) {
52 FILE *dotout = fopen("dot.dot", "w");
53 fprintf(dotout, "digraph A {\n");
54 xbt_dynar_foreach(dot, cursor, task) {
55 SD_task_dotty(task, dotout);
57 fprintf(dotout, "}\n");
60 /* Schedule them all on the first workstation */
61 XBT_INFO("------------------- Schedule tasks ---------------------------");
62 sg_host_t *hosts = sg_host_list();
64 int count = sg_host_count();
65 xbt_dynar_foreach(dot, cursor, task) {
66 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
67 if (!strcmp(SD_task_get_name(task), "end"))
68 SD_task_schedulel(task, 1, hosts[0]);
70 SD_task_schedulel(task, 1, hosts[cursor % count]);
75 XBT_INFO("------------------- Run the schedule ---------------------------");
78 XBT_INFO("------------------- Produce the trace file---------------------------");
79 XBT_INFO("Producing the trace of the run into %s", basename(tracefilename));
80 FILE *out = fopen(tracefilename, "w");
81 xbt_assert(out, "Cannot write to %s", tracefilename);
84 xbt_dynar_foreach(dot, cursor, task) {
85 int kind = SD_task_get_kind(task);
86 sg_host_t *wsl = SD_task_get_workstation_list(task);
88 case SD_TASK_COMP_SEQ:
89 fprintf(out, "[%f->%f] %s compute %f flops # %s\n",
90 SD_task_get_start_time(task), SD_task_get_finish_time(task),
91 sg_host_get_name(wsl[0]), SD_task_get_amount(task), SD_task_get_name(task));
93 case SD_TASK_COMM_E2E:
94 fprintf(out, "[%f -> %f] %s -> %s transfer of %.0f bytes # %s\n",
95 SD_task_get_start_time(task), SD_task_get_finish_time(task),
96 sg_host_get_name(wsl[0]), sg_host_get_name(wsl[1]), SD_task_get_amount(task), SD_task_get_name(task));
99 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task), SD_task_get_kind(task));
101 SD_task_destroy(task);
103 xbt_dynar_free_container(&dot);