Logo AND Algorithmique Numérique Distribuée

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