Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] updating tesh'es according to header changes
[simgrid.git] / examples / simdag / sd_test2.c
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "simdag/simdag.h"
12 #include "xbt/log.h"
13
14 #include "xbt/sysdep.h"         /* calloc, printf */
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test,
17                              "Logging specific to this SimDag example");
18
19 static int nameCompareHosts(const void *n1, const void *n2)
20 {
21   return strcmp(SD_workstation_get_name(*((SD_workstation_t *) n1)),
22                 SD_workstation_get_name(*((SD_workstation_t *) n2)));
23 }
24
25 int main(int argc, char **argv)
26 {
27   int i, j;
28   xbt_dynar_t changed_tasks;
29   int n_hosts;
30   const SD_workstation_t *hosts;
31   SD_task_t taskInit;
32   SD_task_t PtoPComm1;
33   SD_task_t PtoPComm2;
34   SD_task_t ParComp_wocomm;
35   SD_task_t IntraRedist;
36   SD_task_t ParComp_wcomm1;
37   SD_task_t InterRedist;
38   SD_task_t taskFinal;
39   SD_task_t ParComp_wcomm2;
40   SD_workstation_t PtoPcomm1_hosts[2];
41   SD_workstation_t PtoPcomm2_hosts[2];
42   double PtoPcomm1_table[] = { 0, 12500000, 0, 0 };     /* 100Mb */
43   double PtoPcomm2_table[] = { 0, 1250000, 0, 0 };      /* 10Mb */
44   double ParComp_wocomm_cost[] = { 1e+9, 1e+9, 1e+9, 1e+9, 1e+9 };      /* 1 Gflop per Proc */
45   double *ParComp_wocomm_table;
46   SD_workstation_t ParComp_wocomm_hosts[5];
47   double *IntraRedist_cost;
48   double *IntraRedist_table;
49   SD_workstation_t IntraRedist_hosts[5];
50   double ParComp_wcomm1_cost[] = { 1e+9, 1e+9, 1e+9, 1e+9, 1e+9 };      /* 1 Gflop per Proc */
51   double *ParComp_wcomm1_table;
52   SD_workstation_t ParComp_wcomm1_hosts[5];
53   double *InterRedist_cost;
54   double *InterRedist_table;
55   double ParComp_wcomm2_cost[] = { 1e+8, 1e+8, 1e+8, 1e+8, 1e+8 };      /* 1 Gflop per Proc (0.02sec duration) */
56   SD_workstation_t ParComp_wcomm2_hosts[5];
57   double final_cost = 5e+9;
58   double *ParComp_wcomm2_table;
59
60   /* initialisation of SD */
61   SD_init(&argc, argv);
62
63   /* creation of the environment */
64   if (strstr(argv[1],".xml"))
65     SD_create_environment(argv[1]);
66   else
67     if (strstr(argv[1],".lua"))
68       SD_load_environment_script(argv[1]);
69     else
70       xbt_die("Unsupported platform description styel (neither XML nor lua): %s",
71               argv[1]);
72
73   /* getting platform infos */
74   n_hosts = SD_workstation_get_number();
75   hosts = SD_workstation_get_list();
76
77   /* sorting hosts by hostname */
78   qsort((void *) hosts, n_hosts, sizeof(SD_workstation_t),
79         nameCompareHosts);
80
81   /* creation of the tasks */
82   taskInit = SD_task_create("Initial", NULL, 1.0);
83   PtoPComm1 = SD_task_create("PtoP Comm 1", NULL, 1.0);
84   PtoPComm2 = SD_task_create("PtoP Comm 2", NULL, 1.0);
85   ParComp_wocomm = SD_task_create("Par Comp without comm", NULL, 1.0);
86   IntraRedist = SD_task_create("intra redist", NULL, 1.0);
87   ParComp_wcomm1 = SD_task_create("Par Comp with comm 1", NULL, 1.0);
88   InterRedist = SD_task_create("inter redist", NULL, 1.0);
89   taskFinal = SD_task_create("Final", NULL, 1.0);
90   ParComp_wcomm2 = SD_task_create("Par Comp with comm 2", NULL, 1.0);
91
92
93   /* creation of the dependencies */
94   SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm1);
95   SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm2);
96   SD_task_dependency_add(NULL, NULL, PtoPComm1, ParComp_wocomm);
97   SD_task_dependency_add(NULL, NULL, ParComp_wocomm, IntraRedist);
98   SD_task_dependency_add(NULL, NULL, IntraRedist, ParComp_wcomm1);
99   SD_task_dependency_add(NULL, NULL, ParComp_wcomm1, InterRedist);
100   SD_task_dependency_add(NULL, NULL, InterRedist, ParComp_wcomm2);
101   SD_task_dependency_add(NULL, NULL, ParComp_wcomm2, taskFinal);
102   SD_task_dependency_add(NULL, NULL, PtoPComm2, taskFinal);
103
104
105   /* scheduling parameters */
106
107   /* large point-to-point communication (0.1 sec duration) */
108   PtoPcomm1_hosts[0] = hosts[0];
109   PtoPcomm1_hosts[1] = hosts[1];
110
111   /* small point-to-point communication (0.01 sec duration) */
112   PtoPcomm2_hosts[0] = hosts[0];
113   PtoPcomm2_hosts[1] = hosts[2];
114
115   /* parallel task without intra communications (1 sec duration) */
116   ParComp_wocomm_table = xbt_new0(double, 25);
117
118   for (i = 0; i < 5; i++) {
119     ParComp_wocomm_hosts[i] = hosts[i];
120   }
121
122   /* redistribution within a cluster (small latencies) */
123   /* each host send (4*2.5Mb =) 10Mb */
124   /* bandwidth is shared between 5 flows (0.05sec duration) */
125   IntraRedist_cost = xbt_new0(double, 5);
126   IntraRedist_table = xbt_new0(double, 25);
127   for (i = 0; i < 5; i++) {
128     for (j = 0; j < 5; j++) {
129       if (i == j)
130         IntraRedist_table[i * 5 + j] = 0.;
131       else
132         IntraRedist_table[i * 5 + j] = 312500.; /* 2.5Mb */
133     }
134   }
135
136   for (i = 0; i < 5; i++) {
137     IntraRedist_hosts[i] = hosts[i];
138   }
139
140   /* parallel task with intra communications */
141   /* Computation domination (1 sec duration) */
142   ParComp_wcomm1_table = xbt_new0(double, 25);
143
144   for (i = 0; i < 5; i++) {
145     ParComp_wcomm1_hosts[i] = hosts[i];
146   }
147
148   for (i = 0; i < 5; i++) {
149     for (j = 0; j < 5; j++) {
150       if (i == j)
151         ParComp_wcomm1_table[i * 5 + j] = 0.;
152       else
153         ParComp_wcomm1_table[i * 5 + j] = 312500.;      /* 2.5Mb */
154     }
155   }
156
157   /* inter cluster redistribution (big latency on the backbone) */
158   /* (0.5sec duration without latency impact) */
159   InterRedist_cost = xbt_new0(double, 10);
160   InterRedist_table = xbt_new0(double, 100);
161   for (i = 0; i < 5; i++) {
162     InterRedist_table[i * 10 + i + 5] = 1250000.;       /* 10Mb */
163   }
164
165   /* parallel task with intra communications */
166   /* Communication domination (0.1 sec duration) */
167
168   ParComp_wcomm2_table = xbt_new0(double, 25);
169
170   for (i = 0; i < 5; i++) {
171     ParComp_wcomm2_hosts[i] = hosts[i + 5];
172   }
173
174   for (i = 0; i < 5; i++) {
175     for (j = 0; j < 5; j++) {
176       if (i == j)
177         ParComp_wcomm2_table[i * 5 + j] = 0.;
178       else
179         ParComp_wcomm2_table[i * 5 + j] = 625000.;      /* 5Mb */
180     }
181   }
182
183   /* Sequential task */
184
185
186   /* scheduling the tasks */
187   SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST,
188                    -1.0);
189   SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST,
190                    PtoPcomm1_table, -1.0);
191   SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST,
192                    PtoPcomm2_table, -1.0);
193   SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts,
194                    ParComp_wocomm_cost, ParComp_wocomm_table, -1.0);
195   SD_task_schedule(IntraRedist, 5, IntraRedist_hosts, IntraRedist_cost,
196                    IntraRedist_table, -1.0);
197   SD_task_schedule(ParComp_wcomm1, 5, ParComp_wcomm1_hosts,
198                    ParComp_wcomm1_cost, ParComp_wcomm1_table, -1.0);
199   SD_task_schedule(InterRedist, 10, hosts, InterRedist_cost,
200                    InterRedist_table, -1.0);
201   SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts,
202                    ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0);
203   SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost,
204                    SD_SCHED_NO_COST, -1.0);
205
206   /* let's launch the simulation! */
207   changed_tasks = SD_simulate(-1.0);
208
209   XBT_INFO("Simulation time: %f", SD_get_clock());
210
211   xbt_dynar_free_container(&changed_tasks);
212
213   free(ParComp_wocomm_table);
214   free(IntraRedist_cost);
215   free(IntraRedist_table);
216   free(ParComp_wcomm1_table);
217   free(InterRedist_cost);
218   free(InterRedist_table);
219   free(ParComp_wcomm2_table);
220
221   SD_task_destroy(taskInit);
222   SD_task_destroy(PtoPComm1);
223   SD_task_destroy(PtoPComm2);
224   SD_task_destroy(ParComp_wocomm);
225   SD_task_destroy(IntraRedist);
226   SD_task_destroy(ParComp_wcomm1);
227   SD_task_destroy(InterRedist);
228   SD_task_destroy(ParComp_wcomm2);
229   SD_task_destroy(taskFinal);
230
231   SD_exit();
232   return 0;
233 }