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"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
16 static int name_compare_hosts(const void *n1, const void *n2)
18 return strcmp(sg_host_get_name(*(sg_host_t *) n1), sg_host_get_name(*(sg_host_t *) n2));
21 int main(int argc, char **argv)
27 /* SD initialization */
30 /* Check our arguments */
31 xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n"
32 "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", argv[0], argv[0]);
34 char *last = strrchr(argv[2], '.');
35 char * tracefilename = bprintf("%.*s.trace",(int) (last == NULL ? strlen(argv[2]):last - argv[2]), argv[2]);
37 tracefilename = xbt_strdup(argv[3]);
39 /* creation of the environment */
40 SD_create_environment(argv[1]);
42 /* load the DAX file */
43 dax = SD_daxload(argv[2]);
45 XBT_ERROR("A problem occurred during DAX parsing (cycle or syntax). Do not continue this test");
51 /* Display all the tasks */
52 XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
53 xbt_dynar_foreach(dax, cursor, task) {
57 FILE *dotout = fopen("dax.dot", "w");
58 fprintf(dotout, "digraph A {\n");
59 xbt_dynar_foreach(dax, cursor, task) {
60 SD_task_dotty(task, dotout);
62 fprintf(dotout, "}\n");
65 /* Schedule them all on the first host */
66 XBT_INFO("------------------- Schedule tasks ---------------------------");
67 const sg_host_t *ws_list = sg_host_list();
68 int hosts_count = sg_host_count();
69 qsort((void *) ws_list, hosts_count, sizeof(sg_host_t), name_compare_hosts);
71 xbt_dynar_foreach(dax, cursor, task) {
72 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
73 if (!strcmp(SD_task_get_name(task), "end"))
74 SD_task_schedulel(task, 1, ws_list[0]);
76 SD_task_schedulel(task, 1, ws_list[cursor % hosts_count]);
80 XBT_INFO("------------------- Run the schedule ---------------------------");
82 XBT_INFO("------------------- Produce the trace file---------------------------");
83 XBT_INFO("Producing the trace of the run into %s", xbt_basename(tracefilename));
84 FILE *out = fopen(tracefilename, "w");
85 xbt_assert(out, "Cannot write to %s", tracefilename);
88 xbt_dynar_foreach(dax, cursor, task) {
89 int kind = SD_task_get_kind(task);
90 sg_host_t *wsl = SD_task_get_workstation_list(task);
92 case SD_TASK_COMP_SEQ:
93 fprintf(out, "[%f] %s compute %f # %s\n", SD_task_get_start_time(task), sg_host_get_name(wsl[0]),
94 SD_task_get_amount(task), SD_task_get_name(task));
96 case SD_TASK_COMM_E2E:
97 fprintf(out, "[%f] %s send %s %f # %s\n", SD_task_get_start_time(task), sg_host_get_name(wsl[0]),
98 sg_host_get_name(wsl[1]), SD_task_get_amount(task), SD_task_get_name(task));
99 fprintf(out, "[%f] %s recv %s %f # %s\n", SD_task_get_finish_time(task), sg_host_get_name(wsl[1]),
100 sg_host_get_name(wsl[0]), SD_task_get_amount(task), SD_task_get_name(task));
103 xbt_die("Task %s is of unknown kind %d", SD_task_get_name(task), SD_task_get_kind(task));
105 SD_task_destroy(task);
108 xbt_dynar_free_container(&dax);