Logo AND Algorithmique Numérique Distribuée

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