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)
22 sg_host_t PtoPcomm1_hosts[2];
23 sg_host_t PtoPcomm2_hosts[2];
24 double PtoPcomm1_table[] = { 0, 12500000, 0, 0 }; /* 100Mb */
25 double PtoPcomm2_table[] = { 0, 1250000, 0, 0 }; /* 10Mb */
26 double ParComp_wocomm_cost[] = { 1e+9, 1e+9, 1e+9, 1e+9, 1e+9 }; /* 1 Gflop per Proc */
27 double *ParComp_wocomm_table;
28 sg_host_t ParComp_wocomm_hosts[5];
29 double *IntraRedist_cost;
30 double *IntraRedist_table;
31 sg_host_t IntraRedist_hosts[5];
32 double ParComp_wcomm1_cost[] = { 1e+9, 1e+9, 1e+9, 1e+9, 1e+9 }; /* 1 Gflop per Proc */
33 double *ParComp_wcomm1_table;
34 sg_host_t ParComp_wcomm1_hosts[5];
35 double *InterRedist_cost;
36 double *InterRedist_table;
37 double ParComp_wcomm2_cost[] = { 1e+8, 1e+8, 1e+8, 1e+8, 1e+8 }; /* 1 Gflop per Proc (0.02sec duration) */
38 sg_host_t ParComp_wcomm2_hosts[5];
39 double final_cost = 5e+9;
40 double *ParComp_wcomm2_table;
44 xbt_assert(strstr(argv[1],".xml"), "Unsupported platform description style (not XML): %s", argv[1]);
45 SD_create_environment(argv[1]);
47 /* getting platform infos */
48 int n_hosts = sg_host_count();
49 const sg_host_t *hosts = sg_host_list();
51 /* sorting hosts by hostname */
52 qsort((void *) hosts, n_hosts, sizeof(sg_host_t), nameCompareHosts);
54 /* creation of the tasks */
55 SD_task_t taskInit = SD_task_create("Initial", NULL, 1.0);
56 SD_task_t PtoPComm1 = SD_task_create("PtoP Comm 1", NULL, 1.0);
57 SD_task_t PtoPComm2 = SD_task_create("PtoP Comm 2", NULL, 1.0);
58 SD_task_t ParComp_wocomm = SD_task_create("Par Comp without comm", NULL, 1.0);
59 SD_task_t IntraRedist = SD_task_create("intra redist", NULL, 1.0);
60 SD_task_t ParComp_wcomm1 = SD_task_create("Par Comp with comm 1", NULL, 1.0);
61 SD_task_t InterRedist = SD_task_create("inter redist", NULL, 1.0);
62 SD_task_t taskFinal = SD_task_create("Final", NULL, 1.0);
63 SD_task_t ParComp_wcomm2 = SD_task_create("Par Comp with comm 2", NULL, 1.0);
65 /* creation of the dependencies */
66 SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm1);
67 SD_task_dependency_add(NULL, NULL, taskInit, PtoPComm2);
68 SD_task_dependency_add(NULL, NULL, PtoPComm1, ParComp_wocomm);
69 SD_task_dependency_add(NULL, NULL, ParComp_wocomm, IntraRedist);
70 SD_task_dependency_add(NULL, NULL, IntraRedist, ParComp_wcomm1);
71 SD_task_dependency_add(NULL, NULL, ParComp_wcomm1, InterRedist);
72 SD_task_dependency_add(NULL, NULL, InterRedist, ParComp_wcomm2);
73 SD_task_dependency_add(NULL, NULL, ParComp_wcomm2, taskFinal);
74 SD_task_dependency_add(NULL, NULL, PtoPComm2, taskFinal);
76 /* large point-to-point communication (0.1 sec duration) */
77 PtoPcomm1_hosts[0] = hosts[0];
78 PtoPcomm1_hosts[1] = hosts[1];
80 /* small point-to-point communication (0.01 sec duration) */
81 PtoPcomm2_hosts[0] = hosts[0];
82 PtoPcomm2_hosts[1] = hosts[2];
84 /* parallel task without intra communications (1 sec duration) */
85 ParComp_wocomm_table = xbt_new0(double, 25);
87 for (i = 0; i < 5; i++) {
88 ParComp_wocomm_hosts[i] = hosts[i];
91 /* redistribution within a cluster (small latencies) */
92 /* each host send (4*2.5Mb =) 10Mb */
93 /* bandwidth is shared between 5 flows (0.05sec duration) */
94 IntraRedist_cost = xbt_new0(double, 5);
95 IntraRedist_table = xbt_new0(double, 25);
96 for (i = 0; i < 5; i++) {
97 for (j = 0; j < 5; j++) {
99 IntraRedist_table[i * 5 + j] = 0.;
101 IntraRedist_table[i * 5 + j] = 312500.; /* 2.5Mb */
105 for (i = 0; i < 5; i++) {
106 IntraRedist_hosts[i] = hosts[i];
109 /* parallel task with intra communications */
110 /* Computation domination (1 sec duration) */
111 ParComp_wcomm1_table = xbt_new0(double, 25);
113 for (i = 0; i < 5; i++) {
114 ParComp_wcomm1_hosts[i] = hosts[i];
117 for (i = 0; i < 5; i++) {
118 for (j = 0; j < 5; j++) {
120 ParComp_wcomm1_table[i * 5 + j] = 0.;
122 ParComp_wcomm1_table[i * 5 + j] = 312500.; /* 2.5Mb */
126 /* inter cluster redistribution (big latency on the backbone) */
127 /* (0.5sec duration without latency impact) */
128 InterRedist_cost = xbt_new0(double, 10);
129 InterRedist_table = xbt_new0(double, 100);
130 for (i = 0; i < 5; i++) {
131 InterRedist_table[i * 10 + i + 5] = 1250000.; /* 10Mb */
134 /* parallel task with intra communications */
135 /* Communication domination (0.1 sec duration) */
136 ParComp_wcomm2_table = xbt_new0(double, 25);
138 for (i = 0; i < 5; i++) {
139 ParComp_wcomm2_hosts[i] = hosts[i + 5];
142 for (i = 0; i < 5; i++) {
143 for (j = 0; j < 5; j++) {
145 ParComp_wcomm2_table[i * 5 + j] = 0.;
147 ParComp_wcomm2_table[i * 5 + j] = 625000.; /* 5Mb */
151 /* scheduling the tasks */
152 SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST, -1.0);
153 SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST, PtoPcomm1_table, -1.0);
154 SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST, PtoPcomm2_table, -1.0);
155 SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts, ParComp_wocomm_cost, ParComp_wocomm_table, -1.0);
156 SD_task_schedule(IntraRedist, 5, IntraRedist_hosts, IntraRedist_cost, IntraRedist_table, -1.0);
157 SD_task_schedule(ParComp_wcomm1, 5, ParComp_wcomm1_hosts, ParComp_wcomm1_cost, ParComp_wcomm1_table, -1.0);
158 SD_task_schedule(InterRedist, 10, hosts, InterRedist_cost, InterRedist_table, -1.0);
159 SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts, ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0);
160 SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, SD_SCHED_NO_COST, -1.0);
162 /* let's launch the simulation! */
165 XBT_INFO("Simulation time: %f", SD_get_clock());
167 free(ParComp_wocomm_table);
168 free(IntraRedist_cost);
169 free(IntraRedist_table);
170 free(ParComp_wcomm1_table);
171 free(InterRedist_cost);
172 free(InterRedist_table);
173 free(ParComp_wcomm2_table);
175 SD_task_destroy(taskInit);
176 SD_task_destroy(PtoPComm1);
177 SD_task_destroy(PtoPComm2);
178 SD_task_destroy(ParComp_wocomm);
179 SD_task_destroy(IntraRedist);
180 SD_task_destroy(ParComp_wcomm1);
181 SD_task_destroy(InterRedist);
182 SD_task_destroy(ParComp_wcomm2);
183 SD_task_destroy(taskFinal);