7 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
12 #include "deployment.h"
14 void MY_launch_application()
16 deployment_generator* gen;
17 gen = opt::topologies.new_instance(opt::auto_depl::topology);
23 deployment_generator::deployment_generator()
24 : hosts(opt::auto_depl::nhosts)
26 set_load(0, opt::auto_depl::load);
29 void deployment_generator::set_load(int host, double load)
31 hosts[host].load = load;
34 void deployment_generator::set_neighbor(int host, int neighbor)
36 hosts[host].neighbors.push_back(neighbor);
39 void deployment_generator::set_link(int host1, int host2)
41 set_neighbor(host1, host2);
42 set_neighbor(host2, host1);
45 void deployment_generator::deploy()
47 const char* func = "loba";
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 DEBUG2("%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 DEBUG2("%s/neighbor -> \"%s\"", hostname, neighbor_name);
60 xbt_dynar_push_as(args, const char*, neighbor_name);
62 MSG_set_function(hostname, func, 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 DEBUG4("torus size = %u ; width = %u ; height = %u ; foll = %u",
142 (unsigned )size(), width,
143 (unsigned )(size() / width + !!(size() % width)),
145 for (unsigned i = 0; i < size(); i++) {
148 unsigned next_column;
149 unsigned prev_column;
151 next_line = i + width;
152 if (next_line >= size())
153 next_line %= width; // rewind
156 prev_line = i - width;
158 prev_line = first_on_last_line + i; // rewind
159 if (prev_line >= size())
160 prev_line -= width; // need to go at last but one line
163 if (i != size() - 1) {
165 if (next_column % width == 0)
166 next_column -= width; // rewind
168 next_column = first_on_last_line; // special case for last cell
171 if (i % width != 0) {
173 } else if (i < first_on_last_line) {
174 prev_column = i + width - 1; // rewind
176 prev_column = size() - 1; // special case for 1st cell of last line
178 if (next_line != i) {
179 set_neighbor(i, next_line);
180 if (prev_line != next_line)
181 set_neighbor(i, prev_line);
183 if (next_column != i) {
184 set_neighbor(i, next_column);
185 if (prev_column != next_column)
186 set_neighbor(i, prev_column);