3 #include <tr1/functional>
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()
54 using std::tr1::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 bind(std::multiplies<double>(), _1, factor));
67 for (unsigned i = 0 ; i < hosts.size() ; ++i)
68 set_load(i, loads[i]);
71 void deployment_generator::deploy()
73 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL);
74 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
75 const char* hostname = hostdata::at(i).get_name();
76 std::ostringstream oss;
77 oss << std::setprecision(12) << hosts[i].load;
78 std::string strload = oss.str();
79 XBT_DEBUG("%s/load -> \"%s\"", hostname, strload.c_str());
80 xbt_dynar_push_as(args, const char*, strload.c_str());
81 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
82 int neighbor = hosts[i].neighbors[j];
83 const char* neighbor_name = hostdata::at(neighbor).get_name();
84 XBT_DEBUG("%s/neighbor -> \"%s\"", hostname, neighbor_name);
85 xbt_dynar_push_as(args, const char*, neighbor_name);
87 MSG_set_function(hostname, "compute", args);
88 xbt_dynar_reset(args);
90 xbt_dynar_free(&args);
93 void deployment_btree::generate()
95 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
96 unsigned left_child = 2 * i + 1;
97 unsigned right_child = 2 * i + 2;
98 if (left_child < size()) {
99 set_link(i, left_child);
100 if (right_child < size())
101 set_link(i, right_child);
106 void deployment_clique::generate()
108 for (unsigned i = 0 ; i < size() ; ++i)
109 for (unsigned j = 0 ; j < i ; ++j)
113 void deployment_hcube::generate()
115 for (unsigned i = 0 ; i < size() ; ++i)
116 for (unsigned j = 0 ; j < i ; ++j) {
117 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
119 unsigned val = i ^ j;
121 // Count the number of set bits
122 while (val && dist < 2) {
131 void deployment_line::generate()
133 for (unsigned i = 0 ; i < size() - 1 ; ++i)
137 void deployment_ring::generate()
139 set_neighbor(0, size() - 1);
140 for (unsigned i = 0 ; i < size() - 1 ; ++i)
142 set_neighbor(size() - 1, 0);
145 void deployment_star::generate()
147 for (unsigned i = 1 ; i < size() ; ++i)
151 void deployment_torus::generate()
156 unsigned c = (a + b) / 2;
163 // here width == ceil(sqrt(size))
165 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
166 XBT_DEBUG("torus size = %zu ; width = %u ; height = %zu ; foll = %u",
167 size(), width, size() / width + !!(size() % width),
169 for (unsigned i = 0; i < size(); i++) {
172 unsigned next_column;
173 unsigned prev_column;
175 next_line = i + width;
176 if (next_line >= size())
177 next_line %= width; // rewind
180 prev_line = i - width;
182 prev_line = first_on_last_line + i; // rewind
183 if (prev_line >= size())
184 prev_line -= width; // need to go at last but one line
187 if (i != size() - 1) {
189 if (next_column % width == 0)
190 next_column -= width; // rewind
192 next_column = first_on_last_line; // special case for last cell
195 if (i % width != 0) {
197 } else if (i < first_on_last_line) {
198 prev_column = i + width - 1; // rewind
200 prev_column = size() - 1; // special case for 1st cell of last line
202 if (next_line != i) {
203 set_neighbor(i, next_line);
204 if (prev_line != next_line)
205 set_neighbor(i, prev_line);
207 if (next_column != i) {
208 set_neighbor(i, next_column);
209 if (prev_column != next_column)
210 set_neighbor(i, prev_column);