Logo AND Algorithmique Numérique Distribuée

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