1 /* simple test trying to load a DAX file. */
3 /* Copyright (c) 2009 Da SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "simdag/simdag.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
16 "Logging specific to this SimDag example");
18 static int name_compare_hosts(const void *n1, const void *n2)
20 char name1[80], name2[80];
21 strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
22 strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
24 return strcmp(name1, name2);
27 int main(int argc, char **argv) {
32 /* initialisation of SD */
35 /* Check our arguments */
37 INFO1("Usage: %s platform_file dax_file [trace_file]", argv[0]);
38 INFO1("example: %s ../sd_platform.xml Montage_50.xml Montage_50.mytrace", argv[0]);
43 char *last=strrchr(argv[2],'.');
45 tracefilename=bprintf("%.*s.trace",(int)(last==NULL?strlen(argv[2]):last-argv[2]),argv[2]);
47 tracefilename = xbt_strdup(argv[3]);
50 /* creation of the environment */
51 SD_create_environment(argv[1]);
53 /* load the DAX file */
54 dax=SD_daxload(argv[2]);
56 /* Display all the tasks */
57 INFO0("------------------- Display all tasks of the loaded DAG ---------------------------");
58 xbt_dynar_foreach(dax,cursor,task) {
62 FILE *dotout = fopen("dax.dot","w");
63 fprintf(dotout,"digraph A {\n");
64 xbt_dynar_foreach(dax,cursor,task) {
65 SD_task_dotty(task,dotout);
67 fprintf(dotout,"}\n");
70 /* Schedule them all on the first workstation */
71 INFO0("------------------- Schedule tasks ---------------------------");
72 const SD_workstation_t *ws_list = SD_workstation_get_list();
73 int totalHosts = SD_workstation_get_number();
74 qsort((void *) ws_list, totalHosts, sizeof(SD_workstation_t),
77 int count = SD_workstation_get_number();
78 xbt_dynar_foreach(dax,cursor,task) {
79 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
80 if (!strcmp(SD_task_get_name(task),"end"))
81 SD_task_schedulel(task,1,ws_list[0]);
83 SD_task_schedulel(task,1,ws_list[cursor%count]);
87 INFO0("------------------- Run the schedule ---------------------------");
88 SD_task_t *changed = SD_simulate(-1);
90 INFO0("------------------- Produce the trace file---------------------------");
91 INFO1("Producing the trace of the run into %s",tracefilename);
92 FILE*out = fopen(tracefilename,"w");
93 xbt_assert1(out,"Cannot write to %s",tracefilename);
96 xbt_dynar_foreach(dax,cursor,task) {
97 int kind = SD_task_get_kind(task);
98 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
100 case SD_TASK_COMP_SEQ:
101 fprintf(out,"[%f] %s compute %f # %s\n",SD_task_get_start_time(task),
102 SD_workstation_get_name(wsl[0]),SD_task_get_amount(task),
103 SD_task_get_name(task));
105 case SD_TASK_COMM_E2E:
106 fprintf(out,"[%f] %s send %s %f # %s\n",SD_task_get_start_time(task),
107 SD_workstation_get_name(wsl[0]),SD_workstation_get_name(wsl[1]),
108 SD_task_get_amount(task), SD_task_get_name(task));
109 fprintf(out,"[%f] %s recv %s %f # %s\n",SD_task_get_start_time(task),
110 SD_workstation_get_name(wsl[1]),SD_workstation_get_name(wsl[0]),
111 SD_task_get_amount(task), SD_task_get_name(task));
114 xbt_die(bprintf("Task %s is of unknown kind %d",SD_task_get_name(task),SD_task_get_kind(task)));
116 SD_task_destroy(task);