Logo AND Algorithmique Numérique Distribuée

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