Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
autogenerated files (sorry)
[simgrid.git] / testsuite / simdag / sd_test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "simdag/simdag.h"
4 #include "xbt/ex.h"
5 #include "xbt/log.h"
6
7 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test,
8                              "Logging specific to this SimDag example");
9
10 int main(int argc, char **argv) {
11   int i;
12   const char* platform_file;
13
14   const SD_workstation_t *workstations;
15   SD_workstation_t w1;
16   SD_workstation_t w2;
17   const char *name1;
18   const char *name2;
19   const double computation_amount1 = 2000000;
20   const double computation_amount2 = 1000000;
21   const double communication_amount12 = 2000000;
22   const double communication_amount21 = 3000000;
23   const SD_link_t *route;
24   int route_size;
25   SD_task_t taskA;
26   SD_task_t taskB;
27   SD_task_t taskC;
28   SD_task_t taskD;
29   xbt_ex_t ex;
30
31   /* initialisation of SD */
32   SD_init(&argc, argv);
33
34   if (argc < 2) {
35      INFO1("Usage: %s platform_file", argv[0]);
36      INFO1("example: %s sd_platform.xml", argv[0]);
37      exit(1);
38   }
39
40   /* creation of the environment */
41
42   platform_file = argv[1];
43   
44   SD_create_environment(platform_file);
45
46   /* test the estimation functions (use small_platform.xml) */
47   workstations = SD_workstation_get_list();
48   w1 = workstations[0];
49   w2 = workstations[1];
50   name1 = SD_workstation_get_name(w1);
51   name2 = SD_workstation_get_name(w2);
52   route = SD_route_get_list(w1, w2);
53   route_size = SD_route_get_size(w1, w2);
54   taskA = SD_task_create("Task A", NULL, 10.0);
55   taskB = SD_task_create("Task B", NULL, 40.0);
56   taskC = SD_task_create("Task C", NULL, 30.0);
57   taskD = SD_task_create("Task D", NULL, 60.0);
58
59   INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1,
60         SD_workstation_get_computation_time(w1, computation_amount1));
61   INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2,
62         SD_workstation_get_computation_time(w2, computation_amount2));
63
64   INFO2("Route between %s and %s:", name1, name2);
65   for (i = 0; i < route_size; i++) {
66     INFO3("\tLink %s: latency = %f, bandwidth = %f", SD_link_get_name(route[i]),
67           SD_link_get_current_latency(route[i]), SD_link_get_current_bandwidth(route[i]));
68   }
69   INFO2("Route latency = %f, route bandwidth = %f", SD_route_get_current_latency(w1, w2),
70         SD_route_get_current_bandwidth(w1, w2));
71   INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount12, name1, name2,
72         SD_route_get_communication_time(w1, w2, communication_amount12));
73   INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount21, name2, name1,
74         SD_route_get_communication_time(w2, w1, communication_amount21));
75
76   /* creation of the tasks and their dependencies */  
77
78   SD_task_dependency_add(NULL, NULL, taskB, taskA);
79   SD_task_dependency_add(NULL, NULL, taskC, taskA);
80   SD_task_dependency_add(NULL, NULL, taskD, taskB);
81   SD_task_dependency_add(NULL, NULL, taskD, taskC);
82   /*  SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
83
84   TRY {
85     SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
86     xbt_assert0(0, "Hey, I can add a dependency between Task A and Task A!");
87   }
88   CATCH (ex) {
89   }
90   
91   TRY {
92     SD_task_dependency_add(NULL, NULL, taskA, taskB); /* shouldn't work and must raise an exception */
93     xbt_assert0(0, "Oh oh, I can add an already existing dependency!");
94   }
95   CATCH (ex) {
96   }
97
98   SD_task_dependency_remove(taskA, taskB);
99
100   TRY {
101     SD_task_dependency_remove(taskC, taskA); /* shouldn't work and must raise an exception */
102     xbt_assert0(0, "Dude, I can remove an unknown dependency!");
103   }
104   CATCH (ex) {
105   }
106
107   TRY {
108     SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
109     xbt_assert0(0, "Wow, I can remove a dependency between Task C and itself!");
110   }
111   CATCH (ex) {
112   }
113
114
115   /* if everything is ok, no exception is forwarded or rethrown by main() */
116
117   /* watch points */
118   SD_task_watch(taskD, SD_DONE);
119   SD_task_watch(taskB, SD_DONE);
120   SD_task_unwatch(taskD, SD_DONE);
121
122
123   /* scheduling parameters */
124   {
125     const int workstation_number = 2;
126     const SD_workstation_t workstation_list[] = {w1, w2};
127     double computation_amount[] = {computation_amount1, computation_amount2};
128     double communication_amount[] =
129       {
130         0, communication_amount12,
131         communication_amount21, 0
132       };
133     SD_task_t *changed_tasks;
134     double rate = -1.0;
135         
136     /* estimated time */
137     SD_task_t task = taskD;
138     INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
139           SD_task_get_execution_time(task, workstation_number, workstation_list,
140                                      computation_amount, communication_amount, rate));
141     
142     /* let's launch the simulation! */
143     
144     SD_task_schedule(taskA, workstation_number, workstation_list,
145                      computation_amount, communication_amount, rate);
146     SD_task_schedule(taskB, workstation_number, workstation_list,
147                      computation_amount, communication_amount, rate);
148     SD_task_schedule(taskC, workstation_number, workstation_list,
149                      computation_amount, communication_amount, rate);
150     SD_task_schedule(taskD, workstation_number, workstation_list,
151                      computation_amount, communication_amount, rate);
152     
153     changed_tasks = SD_simulate(-1.0);
154     xbt_assert0(changed_tasks[0] == taskD &&
155                 changed_tasks[1] == taskC &&
156                 changed_tasks[2] == taskB &&
157                 changed_tasks[3] == NULL,
158                 "Unexpected simulation results");
159     
160     xbt_free(changed_tasks);
161   }
162   DEBUG0("Destroying tasks...");
163
164   SD_task_destroy(taskA);
165   SD_task_destroy(taskB);
166   SD_task_destroy(taskC);
167   SD_task_destroy(taskD);
168
169   DEBUG0("Tasks destroyed. Exiting SimDag...");
170
171   SD_exit();
172   return 0;
173 }
174