1 #include "deployment.h"
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
13 void MY_launch_application()
15 deployment_generator* gen;
16 gen = opt::topologies.new_instance(opt::auto_depl::topology);
22 deployment_generator::deployment_generator()
23 : hosts(opt::auto_depl::nhosts)
25 set_load(0, opt::auto_depl::load);
28 void deployment_generator::set_load(int host, double load)
30 hosts[host].load = load;
33 void deployment_generator::set_neighbor(int host, int neighbor)
35 hosts[host].neighbors.push_back(neighbor);
38 void deployment_generator::set_link(int host1, int host2)
40 set_neighbor(host1, host2);
41 set_neighbor(host2, host1);
44 void deployment_generator::deploy()
46 const char* func = "simulation_main";
47 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL);
48 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
49 const char* hostname = hostdata::at(i).get_name();
50 std::ostringstream oss;
51 oss << std::setprecision(12) << hosts[i].load;
52 std::string strload = oss.str();
53 DEBUG2("%s/load -> \"%s\"", hostname, strload.c_str());
54 xbt_dynar_push_as(args, const char*, strload.c_str());
55 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
56 int neighbor = hosts[i].neighbors[j];
57 const char* neighbor_name = hostdata::at(neighbor).get_name();
58 DEBUG2("%s/neighbor -> \"%s\"", hostname, neighbor_name);
59 xbt_dynar_push_as(args, const char*, neighbor_name);
61 MSG_set_function(hostname, func, args);
62 xbt_dynar_reset(args);
64 xbt_dynar_free(&args);
67 void deployment_btree::generate()
69 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
70 unsigned left_child = 2 * i + 1;
71 unsigned right_child = 2 * i + 2;
72 if (left_child < size()) {
73 set_link(i, left_child);
74 if (right_child < size())
75 set_link(i, right_child);
80 void deployment_clique::generate()
82 for (unsigned i = 0 ; i < size() ; ++i)
83 for (unsigned j = 0 ; j < i ; ++j)
87 void deployment_hcube::generate()
89 for (unsigned i = 0 ; i < size() ; ++i)
90 for (unsigned j = 0 ; j < i ; ++j) {
91 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
95 // Count the number of set bits
96 while (val && dist < 2) {
105 void deployment_line::generate()
107 for (unsigned i = 0 ; i < size() - 1 ; ++i)
111 void deployment_ring::generate()
113 set_neighbor(0, size() - 1);
114 for (unsigned i = 0 ; i < size() - 1 ; ++i)
116 set_neighbor(size() - 1, 0);
119 void deployment_star::generate()
121 for (unsigned i = 1 ; i < size() ; ++i)
125 void deployment_torus::generate()
130 unsigned c = (a + b) / 2;
138 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
139 DEBUG4("torus size = %u ; width = %u ; height = %u ; foll = %u",
140 (unsigned )size(), width,
141 (unsigned )(size() / width + !!(size() % width)),
143 for (unsigned i = 0; i < size(); i++) {
146 unsigned next_column;
147 unsigned prev_column;
149 next_line = i + width;
150 if (next_line >= size())
151 next_line %= width; // rewind
154 prev_line = i - width;
156 prev_line = first_on_last_line + i; // rewind
157 if (prev_line >= size())
158 prev_line -= width; // need to go at last but one line
161 if (i != size() - 1) {
163 if (next_column % width == 0)
164 next_column -= width; // rewind
166 next_column = first_on_last_line; // special case for last cell
169 if (i % width != 0) {
171 } else if (i < first_on_last_line) {
172 prev_column = i + width - 1; // rewind
174 prev_column = size() - 1; // special case for 1st cell of last line
176 if (next_line != i) {
177 set_neighbor(i, next_line);
178 if (prev_line != next_line)
179 set_neighbor(i, prev_line);
181 if (next_column != i) {
182 set_neighbor(i, next_column);
183 if (prev_column != next_column)
184 set_neighbor(i, prev_column);