Logo AND Algorithmique Numérique Distribuée

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