Logo AND Algorithmique Numérique Distribuée

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