1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
11 #include "simdag/simdag.h"
14 #include "xbt/sysdep.h" /* calloc, printf */
16 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test,
17 "Logging specific to this SimDag example");
19 static int nameCompareHosts(const void *n1, const void *n2)
21 return strcmp(SD_workstation_get_name(*((SD_workstation_t *) n1)),
22 SD_workstation_get_name(*((SD_workstation_t *) n2)));
25 int main(int argc, char **argv)
28 xbt_dynar_t changed_tasks;
30 const SD_workstation_t *hosts;
34 SD_task_t ParComp_wocomm;
35 SD_task_t IntraRedist;
36 SD_task_t ParComp_wcomm1;
37 SD_task_t InterRedist;
39 SD_task_t ParComp_wcomm2;
40 SD_workstation_t PtoPcomm1_hosts[2];
41 SD_workstation_t PtoPcomm2_hosts[2];
42 double PtoPcomm1_table[] = { 0, 12500000, 0, 0 }; /* 100Mb */
43 double PtoPcomm2_table[] = { 0, 1250000, 0, 0 }; /* 10Mb */
44 double ParComp_wocomm_cost[] = { 1e+9, 1e+9, 1e+9, 1e+9, 1e+9 }; /* 1 Gflop per Proc */
45 double *ParComp_wocomm_table;
46 SD_workstation_t ParComp_wocomm_hosts[5];
47 double *IntraRedist_cost;
48 double *IntraRedist_table;
49 SD_workstation_t IntraRedist_hosts[5];
50 double ParComp_wcomm1_cost[] = { 1e+9, 1e+9, 1e+9, 1e+9, 1e+9 }; /* 1 Gflop per Proc */
51 double *ParComp_wcomm1_table;
52 SD_workstation_t ParComp_wcomm1_hosts[5];
53 double *InterRedist_cost;
54 double *InterRedist_table;
55 double ParComp_wcomm2_cost[] = { 1e+8, 1e+8, 1e+8, 1e+8, 1e+8 }; /* 1 Gflop per Proc (0.02sec duration) */
56 SD_workstation_t ParComp_wcomm2_hosts[5];
57 double final_cost = 5e+9;
58 double *ParComp_wcomm2_table;
60 /* initialisation of SD */
63 /* creation of the environment */
64 SD_create_environment(argv[1]);
66 /* getting platform infos */
67 n_hosts = SD_workstation_get_number();
68 hosts = SD_workstation_get_list();
70 /* sorting hosts by hostname */
71 qsort((void *) hosts, n_hosts, sizeof(SD_workstation_t),
74 /* creation of the tasks */
75 taskInit = SD_task_create("Initial", NULL, 1.0);
76 PtoPComm1 = SD_task_create("PtoP Comm 1", NULL, 1.0);
77 PtoPComm2 = SD_task_create("PtoP Comm 2", NULL, 1.0);
78 ParComp_wocomm = SD_task_create("Par Comp without comm", NULL, 1.0);
79 IntraRedist = SD_task_create("intra redist", NULL, 1.0);
80 ParComp_wcomm1 = SD_task_create("Par Comp with comm 1", NULL, 1.0);
81 InterRedist = SD_task_create("inter redist", NULL, 1.0);
82 taskFinal = SD_task_create("Final", NULL, 1.0);
83 ParComp_wcomm2 = SD_task_create("Par Comp with comm 2", NULL, 1.0);
86 /* creation of the dependencies */
87 SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm1);
88 SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm2);
89 SD_task_dependency_add(NULL, NULL, PtoPComm1, ParComp_wocomm);
90 SD_task_dependency_add(NULL, NULL, ParComp_wocomm, IntraRedist);
91 SD_task_dependency_add(NULL, NULL, IntraRedist, ParComp_wcomm1);
92 SD_task_dependency_add(NULL, NULL, ParComp_wcomm1, InterRedist);
93 SD_task_dependency_add(NULL, NULL, InterRedist, ParComp_wcomm2);
94 SD_task_dependency_add(NULL, NULL, ParComp_wcomm2, taskFinal);
95 SD_task_dependency_add(NULL, NULL, PtoPComm2, taskFinal);
98 /* scheduling parameters */
100 /* large point-to-point communication (0.1 sec duration) */
101 PtoPcomm1_hosts[0] = hosts[0];
102 PtoPcomm1_hosts[1] = hosts[1];
104 /* small point-to-point communication (0.01 sec duration) */
105 PtoPcomm2_hosts[0] = hosts[0];
106 PtoPcomm2_hosts[1] = hosts[2];
108 /* parallel task without intra communications (1 sec duration) */
109 ParComp_wocomm_table = xbt_new0(double, 25);
111 for (i = 0; i < 5; i++) {
112 ParComp_wocomm_hosts[i] = hosts[i];
115 /* redistribution within a cluster (small latencies) */
116 /* each host send (4*2.5Mb =) 10Mb */
117 /* bandwidth is shared between 5 flows (0.05sec duration) */
118 IntraRedist_cost = xbt_new0(double, 5);
119 IntraRedist_table = xbt_new0(double, 25);
120 for (i = 0; i < 5; i++) {
121 for (j = 0; j < 5; j++) {
123 IntraRedist_table[i * 5 + j] = 0.;
125 IntraRedist_table[i * 5 + j] = 312500.; /* 2.5Mb */
129 for (i = 0; i < 5; i++) {
130 IntraRedist_hosts[i] = hosts[i];
133 /* parallel task with intra communications */
134 /* Computation domination (1 sec duration) */
135 ParComp_wcomm1_table = xbt_new0(double, 25);
137 for (i = 0; i < 5; i++) {
138 ParComp_wcomm1_hosts[i] = hosts[i];
141 for (i = 0; i < 5; i++) {
142 for (j = 0; j < 5; j++) {
144 ParComp_wcomm1_table[i * 5 + j] = 0.;
146 ParComp_wcomm1_table[i * 5 + j] = 312500.; /* 2.5Mb */
150 /* inter cluster redistribution (big latency on the backbone) */
151 /* (0.5sec duration without latency impact) */
152 InterRedist_cost = xbt_new0(double, 10);
153 InterRedist_table = xbt_new0(double, 100);
154 for (i = 0; i < 5; i++) {
155 InterRedist_table[i * 10 + i + 5] = 1250000.; /* 10Mb */
158 /* parallel task with intra communications */
159 /* Communication domination (0.1 sec duration) */
161 ParComp_wcomm2_table = xbt_new0(double, 25);
163 for (i = 0; i < 5; i++) {
164 ParComp_wcomm2_hosts[i] = hosts[i + 5];
167 for (i = 0; i < 5; i++) {
168 for (j = 0; j < 5; j++) {
170 ParComp_wcomm2_table[i * 5 + j] = 0.;
172 ParComp_wcomm2_table[i * 5 + j] = 625000.; /* 5Mb */
176 /* Sequential task */
179 /* scheduling the tasks */
180 SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST,
182 SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST,
183 PtoPcomm1_table, -1.0);
184 SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST,
185 PtoPcomm2_table, -1.0);
186 SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts,
187 ParComp_wocomm_cost, ParComp_wocomm_table, -1.0);
188 SD_task_schedule(IntraRedist, 5, IntraRedist_hosts, IntraRedist_cost,
189 IntraRedist_table, -1.0);
190 SD_task_schedule(ParComp_wcomm1, 5, ParComp_wcomm1_hosts,
191 ParComp_wcomm1_cost, ParComp_wcomm1_table, -1.0);
192 SD_task_schedule(InterRedist, 10, hosts, InterRedist_cost,
193 InterRedist_table, -1.0);
194 SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts,
195 ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0);
196 SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost,
197 SD_SCHED_NO_COST, -1.0);
199 /* let's launch the simulation! */
200 changed_tasks = SD_simulate(-1.0);
202 INFO1("Simulation time: %f", SD_get_clock());
204 xbt_dynar_free_container(&changed_tasks);
206 free(ParComp_wocomm_table);
207 free(IntraRedist_cost);
208 free(IntraRedist_table);
209 free(ParComp_wcomm1_table);
210 free(InterRedist_cost);
211 free(InterRedist_table);
212 free(ParComp_wcomm2_table);
214 SD_task_destroy(taskInit);
215 SD_task_destroy(PtoPComm1);
216 SD_task_destroy(PtoPComm2);
217 SD_task_destroy(ParComp_wocomm);
218 SD_task_destroy(IntraRedist);
219 SD_task_destroy(ParComp_wcomm1);
220 SD_task_destroy(InterRedist);
221 SD_task_destroy(ParComp_wcomm2);
222 SD_task_destroy(taskFinal);