1 /* Copyright (c) 2007-2015. 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. */
9 #include "simgrid/simdag.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test, "Logging specific to this SimDag example");
14 static int nameCompareHosts(const void *n1, const void *n2)
16 return strcmp(sg_host_get_name(*((sg_host_t *) n1)), sg_host_get_name(*((sg_host_t *) n2)));
19 int main(int argc, char **argv)
23 const sg_host_t *hosts;
27 SD_task_t ParComp_wocomm;
28 SD_task_t IntraRedist;
29 SD_task_t ParComp_wcomm1;
30 SD_task_t InterRedist;
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;
55 xbt_assert(strstr(argv[1],".xml"), "Unsupported platform description style (not XML): %s", argv[1]);
56 SD_create_environment(argv[1]);
58 /* getting platform infos */
59 n_hosts = sg_host_count();
60 hosts = sg_host_list();
62 /* sorting hosts by hostname */
63 qsort((void *) hosts, n_hosts, sizeof(sg_host_t), nameCompareHosts);
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);
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);
87 /* large point-to-point communication (0.1 sec duration) */
88 PtoPcomm1_hosts[0] = hosts[0];
89 PtoPcomm1_hosts[1] = hosts[1];
91 /* small point-to-point communication (0.01 sec duration) */
92 PtoPcomm2_hosts[0] = hosts[0];
93 PtoPcomm2_hosts[1] = hosts[2];
95 /* parallel task without intra communications (1 sec duration) */
96 ParComp_wocomm_table = xbt_new0(double, 25);
98 for (i = 0; i < 5; i++) {
99 ParComp_wocomm_hosts[i] = hosts[i];
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++) {
110 IntraRedist_table[i * 5 + j] = 0.;
112 IntraRedist_table[i * 5 + j] = 312500.; /* 2.5Mb */
116 for (i = 0; i < 5; i++) {
117 IntraRedist_hosts[i] = hosts[i];
120 /* parallel task with intra communications */
121 /* Computation domination (1 sec duration) */
122 ParComp_wcomm1_table = xbt_new0(double, 25);
124 for (i = 0; i < 5; i++) {
125 ParComp_wcomm1_hosts[i] = hosts[i];
128 for (i = 0; i < 5; i++) {
129 for (j = 0; j < 5; j++) {
131 ParComp_wcomm1_table[i * 5 + j] = 0.;
133 ParComp_wcomm1_table[i * 5 + j] = 312500.; /* 2.5Mb */
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 */
145 /* parallel task with intra communications */
146 /* Communication domination (0.1 sec duration) */
147 ParComp_wcomm2_table = xbt_new0(double, 25);
149 for (i = 0; i < 5; i++) {
150 ParComp_wcomm2_hosts[i] = hosts[i + 5];
153 for (i = 0; i < 5; i++) {
154 for (j = 0; j < 5; j++) {
156 ParComp_wcomm2_table[i * 5 + j] = 0.;
158 ParComp_wcomm2_table[i * 5 + j] = 625000.; /* 5Mb */
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);
173 /* let's launch the simulation! */
176 XBT_INFO("Simulation time: %f", SD_get_clock());
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);
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);