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 using std::placeholders::_1;
55 if (!opt::auto_depl::random_distribution) {
56 set_load(0, opt::auto_depl::load);
59 srand48(opt::auto_depl::random_seed);
60 std::vector<double> loads(hosts.size());
61 std::generate(loads.begin(), loads.end(), drand48);
62 double factor = opt::auto_depl::load /
63 std::accumulate(loads.begin(), loads.end(), 0.0);
64 std::transform(loads.begin(), loads.end(), loads.begin(),
65 std::bind(std::multiplies<double>(), _1, factor));
66 if (opt::integer_transfer) {
70 for (i = 0 ; i < hosts.size() - 1; ++i) {
72 iload = floor(loads[i]);
73 else if (residue > 0.0)
74 iload = ceil(loads[i]);
75 else // residue == 0.0
76 iload = round(loads[i]);
77 residue += (loads[i] - iload);
80 // abs(round(...)) to avoid rounding errors, or a value of -0
81 iload = abs(round(loads[i] + residue)); // i == hosts.size() - 1
84 xbt_assert(opt::auto_depl::load ==
85 std::accumulate(loads.begin(), loads.end(), 0.0));
87 for (unsigned i = 0 ; i < hosts.size() ; ++i)
88 set_load(i, loads[i]);
91 void deployment_generator::deploy()
93 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL);
94 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
95 const char* hostname = hostdata::at(i).get_name();
96 std::ostringstream oss;
97 oss << std::setprecision(12) << hosts[i].load;
98 std::string strload = oss.str();
99 XBT_DEBUG("%s/load -> \"%s\"", hostname, strload.c_str());
100 xbt_dynar_push_as(args, const char*, strload.c_str());
101 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
102 int neighbor = hosts[i].neighbors[j];
103 const char* neighbor_name = hostdata::at(neighbor).get_name();
104 XBT_DEBUG("%s/neighbor -> \"%s\"", hostname, neighbor_name);
105 xbt_dynar_push_as(args, const char*, neighbor_name);
107 MSG_set_function(hostname, "compute", args);
108 xbt_dynar_reset(args);
110 xbt_dynar_free(&args);
113 void deployment_btree::generate()
115 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
116 unsigned left_child = 2 * i + 1;
117 unsigned right_child = 2 * i + 2;
118 if (left_child < size()) {
119 set_link(i, left_child);
120 if (right_child < size())
121 set_link(i, right_child);
126 void deployment_clique::generate()
128 for (unsigned i = 0 ; i < size() ; ++i)
129 for (unsigned j = 0 ; j < i ; ++j)
133 void deployment_hcube::generate()
135 for (unsigned i = 0 ; i < size() ; ++i)
136 for (unsigned j = 0 ; j < i ; ++j) {
137 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
139 unsigned val = i ^ j;
141 // Count the number of set bits
142 while (val && dist < 2) {
151 void deployment_line::generate()
153 for (unsigned i = 0 ; i < size() - 1 ; ++i)
157 void deployment_ring::generate()
159 set_neighbor(0, size() - 1);
160 for (unsigned i = 0 ; i < size() - 1 ; ++i)
162 set_neighbor(size() - 1, 0);
165 void deployment_star::generate()
167 for (unsigned i = 1 ; i < size() ; ++i)
171 void deployment_torus::generate()
176 unsigned c = (a + b) / 2;
183 // here width == ceil(sqrt(size))
185 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
186 XBT_DEBUG("torus size = %zu ; width = %u ; height = %zu ; foll = %u",
187 size(), width, size() / width + !!(size() % width),
189 for (unsigned i = 0; i < size(); i++) {
192 unsigned next_column;
193 unsigned prev_column;
195 next_line = i + width;
196 if (next_line >= size())
197 next_line %= width; // rewind
200 prev_line = i - width;
202 prev_line = first_on_last_line + i; // rewind
203 if (prev_line >= size())
204 prev_line -= width; // need to go at last but one line
207 if (i != size() - 1) {
209 if (next_column % width == 0)
210 next_column -= width; // rewind
212 next_column = first_on_last_line; // special case for last cell
215 if (i % width != 0) {
217 } else if (i < first_on_last_line) {
218 prev_column = i + width - 1; // rewind
220 prev_column = size() - 1; // special case for 1st cell of last line
222 if (next_line != i) {
223 set_neighbor(i, next_line);
224 if (prev_line != next_line)
225 set_neighbor(i, prev_line);
227 if (next_column != i) {
228 set_neighbor(i, next_column);
229 if (prev_column != next_column)
230 set_neighbor(i, prev_column);