1 /* simple test trying to load a DAX file. */
3 /* Copyright (c) 2009-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"
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)
22 sg_host_get_name(*(sg_host_t *) n1),
23 sg_host_get_name(*(sg_host_t *) n2)
27 int main(int argc, char **argv)
33 /* SD initialization */
36 /* Check our arguments */
37 xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n"
38 "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed",
41 char *last = strrchr(argv[2], '.');
42 char * tracefilename = bprintf("%.*s.trace",(int) (last == NULL ?
44 last - argv[2]), argv[2]);
46 tracefilename = xbt_strdup(argv[3]);
48 /* creation of the environment */
49 SD_create_environment(argv[1]);
51 /* load the DAX file */
52 dax = SD_daxload(argv[2]);
54 XBT_ERROR("A problem occurred during DAX parsing (cycle or syntax). Do not continue this test");
60 /* Display all the tasks */
62 ("------------------- Display all tasks of the loaded DAG ---------------------------");
63 xbt_dynar_foreach(dax, cursor, task) {
67 FILE *dotout = fopen("dax.dot", "w");
68 fprintf(dotout, "digraph A {\n");
69 xbt_dynar_foreach(dax, cursor, task) {
70 SD_task_dotty(task, dotout);
72 fprintf(dotout, "}\n");
75 /* Schedule them all on the first workstation */
76 XBT_INFO("------------------- Schedule tasks ---------------------------");
77 const sg_host_t *ws_list = sg_host_list();
78 int hosts_count = sg_host_count();
79 qsort((void *) ws_list, hosts_count, sizeof(sg_host_t),
82 xbt_dynar_foreach(dax, cursor, task) {
83 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
84 if (!strcmp(SD_task_get_name(task), "end"))
85 SD_task_schedulel(task, 1, ws_list[0]);
87 SD_task_schedulel(task, 1, ws_list[cursor % hosts_count]);
92 ("------------------- Run the schedule ---------------------------");
95 ("------------------- Produce the trace file---------------------------");
96 XBT_INFO("Producing the trace of the run into %s", tracefilename);
97 FILE *out = fopen(tracefilename, "w");
98 xbt_assert(out, "Cannot write to %s", tracefilename);
101 xbt_dynar_foreach(dax, cursor, task) {
102 int kind = SD_task_get_kind(task);
103 sg_host_t *wsl = SD_task_get_workstation_list(task);
105 case SD_TASK_COMP_SEQ:
106 fprintf(out, "[%f] %s compute %f # %s\n",
107 SD_task_get_start_time(task),
108 sg_host_get_name(wsl[0]), SD_task_get_amount(task),
109 SD_task_get_name(task));
111 case SD_TASK_COMM_E2E:
112 fprintf(out, "[%f] %s send %s %f # %s\n",
113 SD_task_get_start_time(task),
114 sg_host_get_name(wsl[0]),
115 sg_host_get_name(wsl[1]), SD_task_get_amount(task),
116 SD_task_get_name(task));
117 fprintf(out, "[%f] %s recv %s %f # %s\n",
118 SD_task_get_finish_time(task),
119 sg_host_get_name(wsl[1]),
120 sg_host_get_name(wsl[0]), SD_task_get_amount(task),
121 SD_task_get_name(task));
124 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task),
125 SD_task_get_kind(task));
127 SD_task_destroy(task);
130 xbt_dynar_free_container(&dax);