1 /* simple test trying to load a DAX file. */
3 /* Copyright (c) 2009-2013. 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 static int name_compare_hosts(const void *n1, const void *n2)
21 char name1[80], name2[80];
22 strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
23 strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
25 return strcmp(name1, name2);
28 int main(int argc, char **argv)
30 xbt_dynar_t dax, changed;
34 /* initialisation of SD */
37 /* Check our arguments */
39 XBT_INFO("Usage: %s platform_file dax_file [trace_file]", argv[0]);
41 ("example: %s ../sd_platform.xml Montage_50.xml Montage_50.mytrace",
47 char *last = strrchr(argv[2], '.');
51 (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),
54 tracefilename = xbt_strdup(argv[3]);
57 /* creation of the environment */
58 SD_create_environment(argv[1]);
60 /* load the DAX file */
61 dax = SD_daxload(argv[2]);
63 XBT_ERROR("A problem occurred during DAX parsing (cycle or syntax). Do not continue this test");
69 /* Display all the tasks */
71 ("------------------- Display all tasks of the loaded DAG ---------------------------");
72 xbt_dynar_foreach(dax, cursor, task) {
76 FILE *dotout = fopen("dax.dot", "w");
77 fprintf(dotout, "digraph A {\n");
78 xbt_dynar_foreach(dax, cursor, task) {
79 SD_task_dotty(task, dotout);
81 fprintf(dotout, "}\n");
84 /* Schedule them all on the first workstation */
85 XBT_INFO("------------------- Schedule tasks ---------------------------");
86 const SD_workstation_t *ws_list = SD_workstation_get_list();
87 int totalHosts = SD_workstation_get_number();
88 qsort((void *) ws_list, totalHosts, sizeof(SD_workstation_t),
91 int count = SD_workstation_get_number();
92 xbt_dynar_foreach(dax, cursor, task) {
93 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
94 if (!strcmp(SD_task_get_name(task), "end"))
95 SD_task_schedulel(task, 1, ws_list[0]);
97 SD_task_schedulel(task, 1, ws_list[cursor % count]);
102 ("------------------- Run the schedule ---------------------------");
103 changed = SD_simulate(-1);
104 xbt_dynar_free_container(&changed);
106 ("------------------- Produce the trace file---------------------------");
107 XBT_INFO("Producing the trace of the run into %s", tracefilename);
108 FILE *out = fopen(tracefilename, "w");
109 xbt_assert(out, "Cannot write to %s", tracefilename);
112 xbt_dynar_foreach(dax, cursor, task) {
113 int kind = SD_task_get_kind(task);
114 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
116 case SD_TASK_COMP_SEQ:
117 fprintf(out, "[%f] %s compute %f # %s\n",
118 SD_task_get_start_time(task),
119 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
120 SD_task_get_name(task));
122 case SD_TASK_COMM_E2E:
123 fprintf(out, "[%f] %s send %s %f # %s\n",
124 SD_task_get_start_time(task),
125 SD_workstation_get_name(wsl[0]),
126 SD_workstation_get_name(wsl[1]), SD_task_get_amount(task),
127 SD_task_get_name(task));
128 fprintf(out, "[%f] %s recv %s %f # %s\n",
129 SD_task_get_finish_time(task),
130 SD_workstation_get_name(wsl[1]),
131 SD_workstation_get_name(wsl[0]), SD_task_get_amount(task),
132 SD_task_get_name(task));
135 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task),
136 SD_task_get_kind(task));
138 SD_task_destroy(task);
141 xbt_dynar_free_container(&dax);