Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bugfixes to make the dax loader and typed task scheduler work
[simgrid.git] / examples / simdag / dax / dax_test.c
1 /* simple test trying to load a DAX file.                                   */
2
3 /* Copyright (c) 2009 Da SimGrid Team. All rights reserved.                 */
4
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. */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "simdag/simdag.h"
11 #include "xbt/log.h"
12 #include "xbt/ex.h"
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
15                              "Logging specific to this SimDag example");
16
17
18 int main(int argc, char **argv) {
19   xbt_dynar_t dax;
20   unsigned int cursor;
21   SD_task_t task;
22
23   /* initialisation of SD */
24   SD_init(&argc, argv);
25
26   /* Check our arguments */
27   if (argc < 3) {
28     INFO1("Usage: %s platform_file dax_file", argv[0]);
29     INFO1("example: %s ../sd_platform.xml Montage_50.xml", argv[0]);
30     exit(1);
31   }
32
33   /* creation of the environment */
34   SD_create_environment(argv[1]);
35
36   /* load the DAX file */
37   dax=SD_daxload(argv[2]);
38
39   /* Display all the tasks */
40   INFO0("------------------- Display all tasks of the loaded DAG ---------------------------");
41   xbt_dynar_foreach(dax,cursor,task) {
42     SD_task_dump(task);
43   }
44
45   FILE *out = fopen("dax.dot","w");
46   fprintf(out,"digraph A {\n");
47   xbt_dynar_foreach(dax,cursor,task) {
48     SD_task_dotty(task,out);
49   }
50   fprintf(out,"}\n");
51   fclose(out);
52
53   /* Schedule them all on the first workstation */
54   INFO0("------------------- Schedule tasks ---------------------------");
55   const SD_workstation_t *ws_list =  SD_workstation_get_list();
56   xbt_dynar_foreach(dax,cursor,task) {
57     if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ)
58       SD_task_schedulel(task,1,ws_list[0]);
59   }
60
61   INFO0("------------------- Run the schedule ---------------------------");
62   SD_simulate(-1);
63   INFO0("------------------- Produce the trace file---------------------------");
64   xbt_dynar_foreach(dax,cursor,task) {
65     int kind = SD_task_get_kind(task);
66     SD_workstation_t *wsl = SD_task_get_workstation_list(task);
67     switch (kind) {
68     case SD_TASK_COMP_SEQ:
69       INFO4("[%f] %s compute %f # %s",SD_task_get_start_time(task),
70           SD_workstation_get_name(wsl[0]),SD_task_get_amount(task),
71           SD_task_get_name(task));
72       break;
73     case SD_TASK_COMM_E2E:
74       INFO5("[%f] %s send %s %f # %s",SD_task_get_start_time(task),
75           SD_workstation_get_name(wsl[0]),SD_workstation_get_name(wsl[1]),
76           SD_task_get_amount(task), SD_task_get_name(task));
77       INFO5("[%f] %s recv %s %f # %s",SD_task_get_start_time(task),
78           SD_workstation_get_name(wsl[1]),SD_workstation_get_name(wsl[0]),
79           SD_task_get_amount(task), SD_task_get_name(task));
80       break;
81     default:
82       xbt_die(bprintf("Task %s is of unknown kind %d",SD_task_get_name(task),SD_task_get_kind(task)));
83     }
84   }
85   /* exit */
86   SD_exit();
87   return 1;
88 }