8 #include <simgrid/msg.h>
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
18 #include "deployment.h"
20 void MY_launch_application()
22 deployment_generator* gen;
23 gen = opt::topologies.new_instance(opt::auto_depl::topology);
25 gen->distribute_load();
30 deployment_generator::deployment_generator()
31 : hosts(opt::auto_depl::nhosts)
35 void deployment_generator::set_load(int host, double load)
37 hosts[host].load = load;
40 void deployment_generator::set_neighbor(int host, int neighbor)
42 hosts[host].neighbors.push_back(neighbor);
45 void deployment_generator::set_link(int host1, int host2)
47 set_neighbor(host1, host2);
48 set_neighbor(host2, host1);
51 void deployment_generator::distribute_load()
53 if (!opt::auto_depl::random_distribution) {
54 set_load(0, opt::auto_depl::load);
57 std::vector<double> loads(hosts.size());
58 if (opt::auto_depl::random_seed != 1) {
59 srand48(opt::auto_depl::random_seed);
60 std::generate(loads.begin(), loads.end(), drand48);
62 std::fill(loads.begin(), loads.end(), 1.0);
64 double factor = opt::auto_depl::load /
65 std::accumulate(loads.begin(), loads.end(), 0.0);
66 std::transform(loads.begin(), loads.end(), loads.begin(),
67 [&factor](double a) { return factor * a; });
68 if (opt::integer_transfer) {
72 for (i = 0 ; i < hosts.size() - 1; ++i) {
74 iload = std::floor(loads[i]);
75 else if (residue > 0.0)
76 iload = std::ceil(loads[i]);
77 else // residue == 0.0
78 iload = std::round(loads[i]);
79 residue += (loads[i] - iload);
82 // abs(round(...)) to avoid rounding errors, or a value of -0
83 // Note: i == hosts.size() - 1
84 iload = std::abs(std::round(loads[i] + residue));
87 xbt_assert(opt::auto_depl::load ==
88 std::accumulate(loads.begin(), loads.end(), 0.0));
90 for (unsigned i = 0 ; i < hosts.size() ; ++i)
91 set_load(i, loads[i]);
94 void deployment_generator::deploy()
96 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), nullptr);
97 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
98 const char* hostname = hostdata::at(i).get_name();
99 std::ostringstream oss;
100 oss << std::setprecision(12) << hosts[i].load;
101 std::string strload = oss.str();
102 XBT_DEBUG("%s/load -> \"%s\"", hostname, strload.c_str());
103 xbt_dynar_push_as(args, const char*, strload.c_str());
104 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
105 int neighbor = hosts[i].neighbors[j];
106 const char* neighbor_name = hostdata::at(neighbor).get_name();
107 XBT_DEBUG("%s/neighbor -> \"%s\"", hostname, neighbor_name);
108 xbt_dynar_push_as(args, const char*, neighbor_name);
110 MSG_set_function(hostname, "compute", args);
111 xbt_dynar_reset(args);
113 xbt_dynar_free(&args);
116 void deployment_btree::generate()
118 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
119 unsigned left_child = 2 * i + 1;
120 unsigned right_child = 2 * i + 2;
121 if (left_child < size()) {
122 set_link(i, left_child);
123 if (right_child < size())
124 set_link(i, right_child);
129 void deployment_clique::generate()
131 for (unsigned i = 0 ; i < size() ; ++i)
132 for (unsigned j = 0 ; j < i ; ++j)
136 void deployment_hcube::generate()
138 for (unsigned i = 0 ; i < size() ; ++i)
139 for (unsigned j = 0 ; j < i ; ++j) {
140 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
142 unsigned val = i ^ j;
144 // Count the number of set bits
145 while (val && dist < 2) {
154 void deployment_line::generate()
156 for (unsigned i = 0 ; i < size() - 1 ; ++i)
160 void deployment_ring::generate()
162 set_neighbor(0, size() - 1);
163 for (unsigned i = 0 ; i < size() - 1 ; ++i)
165 set_neighbor(size() - 1, 0);
168 void deployment_star::generate()
170 for (unsigned i = 1 ; i < size() ; ++i)
174 void deployment_torus::generate()
179 unsigned c = (a + b) / 2;
186 // here width == std::ceil(std::sqrt(size))
188 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
189 XBT_DEBUG("torus size = %zu ; width = %u ; height = %zu ; foll = %u",
190 size(), width, size() / width + !!(size() % width),
192 for (unsigned i = 0; i < size(); i++) {
195 unsigned next_column;
196 unsigned prev_column;
198 next_line = i + width;
199 if (next_line >= size())
200 next_line %= width; // rewind
203 prev_line = i - width;
205 prev_line = first_on_last_line + i; // rewind
206 if (prev_line >= size())
207 prev_line -= width; // need to go at last but one line
210 if (i != size() - 1) {
212 if (next_column % width == 0)
213 next_column -= width; // rewind
215 next_column = first_on_last_line; // special case for last cell
218 if (i % width != 0) {
220 } else if (i < first_on_last_line) {
221 prev_column = i + width - 1; // rewind
223 prev_column = size() - 1; // special case for 1st cell of last line
225 if (next_line != i) {
226 set_neighbor(i, next_line);
227 if (prev_line != next_line)
228 set_neighbor(i, prev_line);
230 if (next_column != i) {
231 set_neighbor(i, next_column);
232 if (prev_column != next_column)
233 set_neighbor(i, prev_column);