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"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
14 static int name_compare_hosts(const void *n1, const void *n2)
16 return strcmp(sg_host_get_name(*(sg_host_t *) n1), sg_host_get_name(*(sg_host_t *) n2));
19 int main(int argc, char **argv)
25 /* SD initialization */
28 /* Check our arguments */
29 xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n"
30 "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", argv[0], argv[0]);
32 char *last = strrchr(argv[2], '.');
33 char * tracefilename = bprintf("%.*s.trace",(int) (last == NULL ? strlen(argv[2]):last - argv[2]), argv[2]);
35 tracefilename = xbt_strdup(argv[3]);
37 /* creation of the environment */
38 SD_create_environment(argv[1]);
40 /* load the DAX file */
41 dax = SD_daxload(argv[2]);
43 XBT_ERROR("A problem occurred during DAX parsing (cycle or syntax). Do not continue this test");
49 /* Display all the tasks */
50 XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
51 xbt_dynar_foreach(dax, cursor, task) {
55 FILE *dotout = fopen("dax.dot", "w");
56 fprintf(dotout, "digraph A {\n");
57 xbt_dynar_foreach(dax, cursor, task) {
58 SD_task_dotty(task, dotout);
60 fprintf(dotout, "}\n");
63 /* Schedule them all on the first host */
64 XBT_INFO("------------------- Schedule tasks ---------------------------");
65 sg_host_t *host_list = sg_host_list();
66 int hosts_count = sg_host_count();
67 qsort((void *) host_list, hosts_count, sizeof(sg_host_t), name_compare_hosts);
69 xbt_dynar_foreach(dax, cursor, task) {
70 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
71 if (!strcmp(SD_task_get_name(task), "end"))
72 SD_task_schedulel(task, 1, host_list[0]);
74 SD_task_schedulel(task, 1, host_list[cursor % hosts_count]);
79 XBT_INFO("------------------- Run the schedule ---------------------------");
81 XBT_INFO("------------------- Produce the trace file---------------------------");
82 char * basename = xbt_basename(tracefilename);
83 XBT_INFO("Producing the trace of the run into %s", basename);
85 FILE *out = fopen(tracefilename, "w");
86 xbt_assert(out, "Cannot write to %s", tracefilename);
89 xbt_dynar_foreach(dax, cursor, task) {
90 int kind = SD_task_get_kind(task);
91 sg_host_t *wsl = SD_task_get_workstation_list(task);
93 case SD_TASK_COMP_SEQ:
94 fprintf(out, "[%f] %s compute %f # %s\n", SD_task_get_start_time(task), sg_host_get_name(wsl[0]),
95 SD_task_get_amount(task), SD_task_get_name(task));
97 case SD_TASK_COMM_E2E:
98 fprintf(out, "[%f] %s send %s %f # %s\n", SD_task_get_start_time(task), sg_host_get_name(wsl[0]),
99 sg_host_get_name(wsl[1]), SD_task_get_amount(task), SD_task_get_name(task));
100 fprintf(out, "[%f] %s recv %s %f # %s\n", SD_task_get_finish_time(task), sg_host_get_name(wsl[1]),
101 sg_host_get_name(wsl[0]), SD_task_get_amount(task), SD_task_get_name(task));
104 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task), SD_task_get_kind(task));
106 SD_task_destroy(task);
109 xbt_dynar_free_container(&dax);