Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rework all examples and test cases of the properties
[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   int i,j;
21   SD_task_t *changed_tasks;
22   int n_hosts;
23   const SD_workstation_t * hosts;
24   SD_task_t taskInit;
25   SD_task_t PtoPComm1;
26   SD_task_t PtoPComm2;
27   SD_task_t ParComp_wocomm;
28   SD_task_t IntraRedist;
29   SD_task_t ParComp_wcomm1;
30   SD_task_t InterRedist;
31   SD_task_t taskFinal;
32   SD_task_t ParComp_wcomm2;
33   const double no_cost[] = {1.0, 1.0};
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,
66         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, -1.0);
176   SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, no_cost, PtoPcomm2_table, -1.0);
177   SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts, ParComp_wocomm_cost, ParComp_wocomm_table, -1.0);
178   SD_task_schedule(IntraRedist, 5, IntraRedist_hosts, IntraRedist_cost, IntraRedist_table, -1.0);
179   SD_task_schedule(ParComp_wcomm1, 5, ParComp_wcomm1_hosts, ParComp_wcomm1_cost, ParComp_wcomm1_table, -1.0);
180   SD_task_schedule(InterRedist, 10, hosts, InterRedist_cost, InterRedist_table, -1.0);
181   SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts, ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0);
182   SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, no_cost, -1.0);
183   
184   /* let's launch the simulation! */
185   changed_tasks = SD_simulate(-1.0);
186
187   free(changed_tasks);
188
189   free(ParComp_wocomm_table);
190   free(IntraRedist_cost);
191   free(IntraRedist_table);
192   free(ParComp_wcomm1_table);
193   free(InterRedist_cost);
194   free(InterRedist_table);
195   free(ParComp_wcomm2_table);
196   
197   SD_task_destroy(taskInit);
198   SD_task_destroy(PtoPComm1);
199   SD_task_destroy(PtoPComm2);
200   SD_task_destroy(ParComp_wocomm);
201   SD_task_destroy(IntraRedist);
202   SD_task_destroy(ParComp_wcomm1);
203   SD_task_destroy(InterRedist);
204   SD_task_destroy(ParComp_wcomm2);
205   SD_task_destroy(taskFinal);
206
207   SD_exit();
208   return 0;
209 }
210