7 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
13 #include "deployment.h"
15 void MY_launch_application()
17 deployment_generator* gen;
18 gen = opt::topologies.new_instance(opt::auto_depl::topology);
24 deployment_generator::deployment_generator()
25 : hosts(opt::auto_depl::nhosts)
27 set_load(0, opt::auto_depl::load);
30 void deployment_generator::set_load(int host, double load)
32 hosts[host].load = load;
35 void deployment_generator::set_neighbor(int host, int neighbor)
37 hosts[host].neighbors.push_back(neighbor);
40 void deployment_generator::set_link(int host1, int host2)
42 set_neighbor(host1, host2);
43 set_neighbor(host2, host1);
46 void deployment_generator::deploy()
48 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL);
49 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
50 const char* hostname = hostdata::at(i).get_name();
51 std::ostringstream oss;
52 oss << std::setprecision(12) << hosts[i].load;
53 std::string strload = oss.str();
54 XBT_DEBUG("%s/load -> \"%s\"", hostname, strload.c_str());
55 xbt_dynar_push_as(args, const char*, strload.c_str());
56 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
57 int neighbor = hosts[i].neighbors[j];
58 const char* neighbor_name = hostdata::at(neighbor).get_name();
59 XBT_DEBUG("%s/neighbor -> \"%s\"", hostname, neighbor_name);
60 xbt_dynar_push_as(args, const char*, neighbor_name);
62 MSG_set_function(hostname, "compute", args);
63 xbt_dynar_reset(args);
65 xbt_dynar_free(&args);
68 void deployment_btree::generate()
70 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
71 unsigned left_child = 2 * i + 1;
72 unsigned right_child = 2 * i + 2;
73 if (left_child < size()) {
74 set_link(i, left_child);
75 if (right_child < size())
76 set_link(i, right_child);
81 void deployment_clique::generate()
83 for (unsigned i = 0 ; i < size() ; ++i)
84 for (unsigned j = 0 ; j < i ; ++j)
88 void deployment_hcube::generate()
90 for (unsigned i = 0 ; i < size() ; ++i)
91 for (unsigned j = 0 ; j < i ; ++j) {
92 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
96 // Count the number of set bits
97 while (val && dist < 2) {
106 void deployment_line::generate()
108 for (unsigned i = 0 ; i < size() - 1 ; ++i)
112 void deployment_ring::generate()
114 set_neighbor(0, size() - 1);
115 for (unsigned i = 0 ; i < size() - 1 ; ++i)
117 set_neighbor(size() - 1, 0);
120 void deployment_star::generate()
122 for (unsigned i = 1 ; i < size() ; ++i)
126 void deployment_torus::generate()
131 unsigned c = (a + b) / 2;
138 // here width == ceil(sqrt(size))
140 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
141 XBT_DEBUG("torus size = %zu ; width = %u ; height = %zu ; foll = %u",
142 size(), width, size() / width + !!(size() % width),
144 for (unsigned i = 0; i < size(); i++) {
147 unsigned next_column;
148 unsigned prev_column;
150 next_line = i + width;
151 if (next_line >= size())
152 next_line %= width; // rewind
155 prev_line = i - width;
157 prev_line = first_on_last_line + i; // rewind
158 if (prev_line >= size())
159 prev_line -= width; // need to go at last but one line
162 if (i != size() - 1) {
164 if (next_column % width == 0)
165 next_column -= width; // rewind
167 next_column = first_on_last_line; // special case for last cell
170 if (i % width != 0) {
172 } else if (i < first_on_last_line) {
173 prev_column = i + width - 1; // rewind
175 prev_column = size() - 1; // special case for 1st cell of last line
177 if (next_line != i) {
178 set_neighbor(i, next_line);
179 if (prev_line != next_line)
180 set_neighbor(i, prev_line);
182 if (next_column != i) {
183 set_neighbor(i, next_column);
184 if (prev_column != next_column)
185 set_neighbor(i, prev_column);