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. */
9 #include "simgrid/simdag.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
15 static int name_compare_hosts(const void *n1, const void *n2)
17 return strcmp(sg_host_get_name(*(sg_host_t *) n1), sg_host_get_name(*(sg_host_t *) n2));
20 int main(int argc, char **argv)
26 /* SD initialization */
29 /* Check our arguments */
30 xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n"
31 "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", argv[0], argv[0]);
33 char *last = strrchr(argv[2], '.');
34 char * tracefilename = bprintf("%.*s.trace",(int) (last == NULL ? strlen(argv[2]):last - argv[2]), argv[2]);
36 tracefilename = xbt_strdup(argv[3]);
38 /* creation of the environment */
39 SD_create_environment(argv[1]);
41 /* load the DAX file */
42 dax = SD_daxload(argv[2]);
44 XBT_ERROR("A problem occurred during DAX parsing (cycle or syntax). Do not continue this test");
50 /* Display all the tasks */
51 XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
52 xbt_dynar_foreach(dax, cursor, task) {
56 FILE *dotout = fopen("dax.dot", "w");
57 fprintf(dotout, "digraph A {\n");
58 xbt_dynar_foreach(dax, cursor, task) {
59 SD_task_dotty(task, dotout);
61 fprintf(dotout, "}\n");
64 /* Schedule them all on the first host */
65 XBT_INFO("------------------- Schedule tasks ---------------------------");
66 const sg_host_t *ws_list = sg_host_list();
67 int hosts_count = sg_host_count();
68 qsort((void *) ws_list, hosts_count, sizeof(sg_host_t), name_compare_hosts);
70 xbt_dynar_foreach(dax, cursor, task) {
71 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
72 if (!strcmp(SD_task_get_name(task), "end"))
73 SD_task_schedulel(task, 1, ws_list[0]);
75 SD_task_schedulel(task, 1, ws_list[cursor % hosts_count]);
79 XBT_INFO("------------------- Run the schedule ---------------------------");
81 XBT_INFO("------------------- Produce the trace file---------------------------");
82 XBT_INFO("Producing the trace of the run into %s", tracefilename);
83 FILE *out = fopen(tracefilename, "w");
84 xbt_assert(out, "Cannot write to %s", tracefilename);
87 xbt_dynar_foreach(dax, cursor, task) {
88 int kind = SD_task_get_kind(task);
89 sg_host_t *wsl = SD_task_get_workstation_list(task);
91 case SD_TASK_COMP_SEQ:
92 fprintf(out, "[%f] %s compute %f # %s\n", SD_task_get_start_time(task), sg_host_get_name(wsl[0]),
93 SD_task_get_amount(task), SD_task_get_name(task));
95 case SD_TASK_COMM_E2E:
96 fprintf(out, "[%f] %s send %s %f # %s\n", SD_task_get_start_time(task), sg_host_get_name(wsl[0]),
97 sg_host_get_name(wsl[1]), SD_task_get_amount(task), SD_task_get_name(task));
98 fprintf(out, "[%f] %s recv %s %f # %s\n", SD_task_get_finish_time(task), sg_host_get_name(wsl[1]),
99 sg_host_get_name(wsl[0]), SD_task_get_amount(task), SD_task_get_name(task));
102 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task), SD_task_get_kind(task));
104 SD_task_destroy(task);
107 xbt_dynar_free_container(&dax);