10 #include <xbt/dynar.h>
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
19 #include "deployment.h"
21 void MY_launch_application()
23 deployment_generator* gen;
24 gen = opt::topologies.new_instance(opt::auto_depl::topology);
26 gen->distribute_load();
31 deployment_generator::deployment_generator()
32 : hosts(opt::auto_depl::nhosts)
36 void deployment_generator::set_load(int host, double load)
38 hosts[host].load = load;
41 void deployment_generator::set_neighbor(int host, int neighbor)
43 hosts[host].neighbors.push_back(neighbor);
46 void deployment_generator::set_link(int host1, int host2)
48 set_neighbor(host1, host2);
49 set_neighbor(host2, host1);
52 void deployment_generator::distribute_load()
54 using std::placeholders::_1;
56 if (!opt::auto_depl::random_distribution) {
57 set_load(0, opt::auto_depl::load);
60 srand48(opt::auto_depl::random_seed);
61 std::vector<double> loads(hosts.size());
62 std::generate(loads.begin(), loads.end(), drand48);
63 double factor = opt::auto_depl::load /
64 std::accumulate(loads.begin(), loads.end(), 0.0);
65 std::transform(loads.begin(), loads.end(), loads.begin(),
66 std::bind(std::multiplies<double>(), _1, factor));
67 if (opt::integer_transfer) {
71 for (i = 0 ; i < hosts.size() - 1; ++i) {
73 iload = floor(loads[i]);
74 else if (residue > 0.0)
75 iload = ceil(loads[i]);
76 else // residue == 0.0
77 iload = round(loads[i]);
78 residue += (loads[i] - iload);
81 // abs(round(...)) to avoid rounding errors, or a value of -0
82 iload = abs(round(loads[i] + residue)); // i == hosts.size() - 1
85 xbt_assert(opt::auto_depl::load ==
86 std::accumulate(loads.begin(), loads.end(), 0.0));
88 for (unsigned i = 0 ; i < hosts.size() ; ++i)
89 set_load(i, loads[i]);
92 void deployment_generator::deploy()
94 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL);
95 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
96 const char* hostname = hostdata::at(i).get_name();
97 std::ostringstream oss;
98 oss << std::setprecision(12) << hosts[i].load;
99 std::string strload = oss.str();
100 XBT_DEBUG("%s/load -> \"%s\"", hostname, strload.c_str());
101 xbt_dynar_push_as(args, const char*, strload.c_str());
102 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
103 int neighbor = hosts[i].neighbors[j];
104 const char* neighbor_name = hostdata::at(neighbor).get_name();
105 XBT_DEBUG("%s/neighbor -> \"%s\"", hostname, neighbor_name);
106 xbt_dynar_push_as(args, const char*, neighbor_name);
108 MSG_set_function(hostname, "compute", args);
109 xbt_dynar_reset(args);
111 xbt_dynar_free(&args);
114 void deployment_btree::generate()
116 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
117 unsigned left_child = 2 * i + 1;
118 unsigned right_child = 2 * i + 2;
119 if (left_child < size()) {
120 set_link(i, left_child);
121 if (right_child < size())
122 set_link(i, right_child);
127 void deployment_clique::generate()
129 for (unsigned i = 0 ; i < size() ; ++i)
130 for (unsigned j = 0 ; j < i ; ++j)
134 void deployment_hcube::generate()
136 for (unsigned i = 0 ; i < size() ; ++i)
137 for (unsigned j = 0 ; j < i ; ++j) {
138 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
140 unsigned val = i ^ j;
142 // Count the number of set bits
143 while (val && dist < 2) {
152 void deployment_line::generate()
154 for (unsigned i = 0 ; i < size() - 1 ; ++i)
158 void deployment_ring::generate()
160 set_neighbor(0, size() - 1);
161 for (unsigned i = 0 ; i < size() - 1 ; ++i)
163 set_neighbor(size() - 1, 0);
166 void deployment_star::generate()
168 for (unsigned i = 1 ; i < size() ; ++i)
172 void deployment_torus::generate()
177 unsigned c = (a + b) / 2;
184 // here width == ceil(sqrt(size))
186 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
187 XBT_DEBUG("torus size = %zu ; width = %u ; height = %zu ; foll = %u",
188 size(), width, size() / width + !!(size() % width),
190 for (unsigned i = 0; i < size(); i++) {
193 unsigned next_column;
194 unsigned prev_column;
196 next_line = i + width;
197 if (next_line >= size())
198 next_line %= width; // rewind
201 prev_line = i - width;
203 prev_line = first_on_last_line + i; // rewind
204 if (prev_line >= size())
205 prev_line -= width; // need to go at last but one line
208 if (i != size() - 1) {
210 if (next_column % width == 0)
211 next_column -= width; // rewind
213 next_column = first_on_last_line; // special case for last cell
216 if (i % width != 0) {
218 } else if (i < first_on_last_line) {
219 prev_column = i + width - 1; // rewind
221 prev_column = size() - 1; // special case for 1st cell of last line
223 if (next_line != i) {
224 set_neighbor(i, next_line);
225 if (prev_line != next_line)
226 set_neighbor(i, prev_line);
228 if (next_column != i) {
229 set_neighbor(i, next_column);
230 if (prev_column != next_column)
231 set_neighbor(i, prev_column);