Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sed -i -e 's/\t/ /g' [sources] Please people, stop using tabs
[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(sg_host_get_name(*((sg_host_t *) n1)),
22                 sg_host_get_name(*((sg_host_t *) n2)));
23 }
24
25 int main(int argc, char **argv)
26 {
27   int i, j;
28   int n_hosts;
29   const sg_host_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   sg_host_t PtoPcomm1_hosts[2];
40   sg_host_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   sg_host_t ParComp_wocomm_hosts[5];
46   double *IntraRedist_cost;
47   double *IntraRedist_table;
48   sg_host_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   sg_host_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   sg_host_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   xbt_assert(strstr(argv[1],".xml"), 
64        "Unsupported platform description style (not XML): %s",
65        argv[1]);
66   SD_create_environment(argv[1]);
67
68   /* getting platform infos */
69   n_hosts = sg_host_count();
70   hosts = sg_host_list();
71
72   /* sorting hosts by hostname */
73   qsort((void *) hosts, n_hosts, sizeof(sg_host_t),
74         nameCompareHosts);
75
76   /* creation of the tasks */
77   taskInit = SD_task_create("Initial", NULL, 1.0);
78   PtoPComm1 = SD_task_create("PtoP Comm 1", NULL, 1.0);
79   PtoPComm2 = SD_task_create("PtoP Comm 2", NULL, 1.0);
80   ParComp_wocomm = SD_task_create("Par Comp without comm", NULL, 1.0);
81   IntraRedist = SD_task_create("intra redist", NULL, 1.0);
82   ParComp_wcomm1 = SD_task_create("Par Comp with comm 1", NULL, 1.0);
83   InterRedist = SD_task_create("inter redist", NULL, 1.0);
84   taskFinal = SD_task_create("Final", NULL, 1.0);
85   ParComp_wcomm2 = SD_task_create("Par Comp with comm 2", NULL, 1.0);
86
87
88   /* creation of the dependencies */
89   SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm1);
90   SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm2);
91   SD_task_dependency_add(NULL, NULL, PtoPComm1, ParComp_wocomm);
92   SD_task_dependency_add(NULL, NULL, ParComp_wocomm, IntraRedist);
93   SD_task_dependency_add(NULL, NULL, IntraRedist, ParComp_wcomm1);
94   SD_task_dependency_add(NULL, NULL, ParComp_wcomm1, InterRedist);
95   SD_task_dependency_add(NULL, NULL, InterRedist, ParComp_wcomm2);
96   SD_task_dependency_add(NULL, NULL, ParComp_wcomm2, taskFinal);
97   SD_task_dependency_add(NULL, NULL, PtoPComm2, taskFinal);
98
99
100   /* scheduling parameters */
101
102   /* large point-to-point communication (0.1 sec duration) */
103   PtoPcomm1_hosts[0] = hosts[0];
104   PtoPcomm1_hosts[1] = hosts[1];
105
106   /* small point-to-point communication (0.01 sec duration) */
107   PtoPcomm2_hosts[0] = hosts[0];
108   PtoPcomm2_hosts[1] = hosts[2];
109
110   /* parallel task without intra communications (1 sec duration) */
111   ParComp_wocomm_table = xbt_new0(double, 25);
112
113   for (i = 0; i < 5; i++) {
114     ParComp_wocomm_hosts[i] = hosts[i];
115   }
116
117   /* redistribution within a cluster (small latencies) */
118   /* each host send (4*2.5Mb =) 10Mb */
119   /* bandwidth is shared between 5 flows (0.05sec duration) */
120   IntraRedist_cost = xbt_new0(double, 5);
121   IntraRedist_table = xbt_new0(double, 25);
122   for (i = 0; i < 5; i++) {
123     for (j = 0; j < 5; j++) {
124       if (i == j)
125         IntraRedist_table[i * 5 + j] = 0.;
126       else
127         IntraRedist_table[i * 5 + j] = 312500.; /* 2.5Mb */
128     }
129   }
130
131   for (i = 0; i < 5; i++) {
132     IntraRedist_hosts[i] = hosts[i];
133   }
134
135   /* parallel task with intra communications */
136   /* Computation domination (1 sec duration) */
137   ParComp_wcomm1_table = xbt_new0(double, 25);
138
139   for (i = 0; i < 5; i++) {
140     ParComp_wcomm1_hosts[i] = hosts[i];
141   }
142
143   for (i = 0; i < 5; i++) {
144     for (j = 0; j < 5; j++) {
145       if (i == j)
146         ParComp_wcomm1_table[i * 5 + j] = 0.;
147       else
148         ParComp_wcomm1_table[i * 5 + j] = 312500.;      /* 2.5Mb */
149     }
150   }
151
152   /* inter cluster redistribution (big latency on the backbone) */
153   /* (0.5sec duration without latency impact) */
154   InterRedist_cost = xbt_new0(double, 10);
155   InterRedist_table = xbt_new0(double, 100);
156   for (i = 0; i < 5; i++) {
157     InterRedist_table[i * 10 + i + 5] = 1250000.;       /* 10Mb */
158   }
159
160   /* parallel task with intra communications */
161   /* Communication domination (0.1 sec duration) */
162
163   ParComp_wcomm2_table = xbt_new0(double, 25);
164
165   for (i = 0; i < 5; i++) {
166     ParComp_wcomm2_hosts[i] = hosts[i + 5];
167   }
168
169   for (i = 0; i < 5; i++) {
170     for (j = 0; j < 5; j++) {
171       if (i == j)
172         ParComp_wcomm2_table[i * 5 + j] = 0.;
173       else
174         ParComp_wcomm2_table[i * 5 + j] = 625000.;      /* 5Mb */
175     }
176   }
177
178   /* Sequential task */
179
180
181   /* scheduling the tasks */
182   SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST,
183                    -1.0);
184   SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST,
185                    PtoPcomm1_table, -1.0);
186   SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST,
187                    PtoPcomm2_table, -1.0);
188   SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts,
189                    ParComp_wocomm_cost, ParComp_wocomm_table, -1.0);
190   SD_task_schedule(IntraRedist, 5, IntraRedist_hosts, IntraRedist_cost,
191                    IntraRedist_table, -1.0);
192   SD_task_schedule(ParComp_wcomm1, 5, ParComp_wcomm1_hosts,
193                    ParComp_wcomm1_cost, ParComp_wcomm1_table, -1.0);
194   SD_task_schedule(InterRedist, 10, hosts, InterRedist_cost,
195                    InterRedist_table, -1.0);
196   SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts,
197                    ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0);
198   SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost,
199                    SD_SCHED_NO_COST, -1.0);
200
201   /* let's launch the simulation! */
202   SD_simulate(-1.0);
203
204   XBT_INFO("Simulation time: %f", SD_get_clock());
205
206
207   free(ParComp_wocomm_table);
208   free(IntraRedist_cost);
209   free(IntraRedist_table);
210   free(ParComp_wcomm1_table);
211   free(InterRedist_cost);
212   free(InterRedist_table);
213   free(ParComp_wcomm2_table);
214
215   SD_task_destroy(taskInit);
216   SD_task_destroy(PtoPComm1);
217   SD_task_destroy(PtoPComm2);
218   SD_task_destroy(ParComp_wocomm);
219   SD_task_destroy(IntraRedist);
220   SD_task_destroy(ParComp_wcomm1);
221   SD_task_destroy(InterRedist);
222   SD_task_destroy(ParComp_wcomm2);
223   SD_task_destroy(taskFinal);
224
225   SD_exit();
226   return 0;
227 }