1 /* simple test trying to load a DAX file. */
3 /* Copyright (c) 2009, 2010. 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 "simdag/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)
21 char name1[80], name2[80];
22 strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
23 strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
25 return strcmp(name1, name2);
28 int main(int argc, char **argv) {
33 /* initialisation of SD */
36 /* Check our arguments */
38 INFO1("Usage: %s platform_file dax_file [trace_file]", argv[0]);
39 INFO1("example: %s ../sd_platform.xml Montage_50.xml Montage_50.mytrace", argv[0]);
44 char *last=strrchr(argv[2],'.');
46 tracefilename=bprintf("%.*s.trace",(int)(last==NULL?strlen(argv[2]):last-argv[2]),argv[2]);
48 tracefilename = xbt_strdup(argv[3]);
51 /* creation of the environment */
52 SD_create_environment(argv[1]);
54 /* load the DAX file */
55 dax=SD_daxload(argv[2]);
57 /* Display all the tasks */
58 INFO0("------------------- Display all tasks of the loaded DAG ---------------------------");
59 xbt_dynar_foreach(dax,cursor,task) {
63 FILE *dotout = fopen("dax.dot","w");
64 fprintf(dotout,"digraph A {\n");
65 xbt_dynar_foreach(dax,cursor,task) {
66 SD_task_dotty(task,dotout);
68 fprintf(dotout,"}\n");
71 /* Schedule them all on the first workstation */
72 INFO0("------------------- Schedule tasks ---------------------------");
73 const SD_workstation_t *ws_list = SD_workstation_get_list();
74 int totalHosts = SD_workstation_get_number();
75 qsort((void *) ws_list, totalHosts, sizeof(SD_workstation_t),
78 int count = SD_workstation_get_number();
79 xbt_dynar_foreach(dax,cursor,task) {
80 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
81 if (!strcmp(SD_task_get_name(task),"end"))
82 SD_task_schedulel(task,1,ws_list[0]);
84 SD_task_schedulel(task,1,ws_list[cursor%count]);
88 INFO0("------------------- Run the schedule ---------------------------");
89 SD_task_t *changed = SD_simulate(-1);
91 INFO0("------------------- Produce the trace file---------------------------");
92 INFO1("Producing the trace of the run into %s",tracefilename);
93 FILE*out = fopen(tracefilename,"w");
94 xbt_assert1(out,"Cannot write to %s",tracefilename);
97 xbt_dynar_foreach(dax,cursor,task) {
98 int kind = SD_task_get_kind(task);
99 SD_workstation_t *wsl = SD_task_get_workstation_list(task);
101 case SD_TASK_COMP_SEQ:
102 fprintf(out,"[%f] %s compute %f # %s\n",SD_task_get_start_time(task),
103 SD_workstation_get_name(wsl[0]),SD_task_get_amount(task),
104 SD_task_get_name(task));
106 case SD_TASK_COMM_E2E:
107 fprintf(out,"[%f] %s send %s %f # %s\n",SD_task_get_start_time(task),
108 SD_workstation_get_name(wsl[0]),SD_workstation_get_name(wsl[1]),
109 SD_task_get_amount(task), SD_task_get_name(task));
110 fprintf(out,"[%f] %s recv %s %f # %s\n",SD_task_get_finish_time(task),
111 SD_workstation_get_name(wsl[1]),SD_workstation_get_name(wsl[0]),
112 SD_task_get_amount(task), SD_task_get_name(task));
115 xbt_die(bprintf("Task %s is of unknown kind %d",SD_task_get_name(task),SD_task_get_kind(task)));
117 SD_task_destroy(task);