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()
53 using std::placeholders::_1;
55 if (!opt::auto_depl::random_distribution) {
56 set_load(0, opt::auto_depl::load);
59 srand48(opt::auto_depl::random_seed);
60 std::vector<double> loads(hosts.size());
61 std::generate(loads.begin(), loads.end(), drand48);
62 double factor = opt::auto_depl::load /
63 std::accumulate(loads.begin(), loads.end(), 0.0);
64 std::transform(loads.begin(), loads.end(), loads.begin(),
65 std::bind(std::multiplies<double>(), _1, factor));
66 for (unsigned i = 0 ; i < hosts.size() ; ++i)
67 set_load(i, loads[i]);
70 void deployment_generator::deploy()
72 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL);
73 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
74 const char* hostname = hostdata::at(i).get_name();
75 std::ostringstream oss;
76 oss << std::setprecision(12) << hosts[i].load;
77 std::string strload = oss.str();
78 XBT_DEBUG("%s/load -> \"%s\"", hostname, strload.c_str());
79 xbt_dynar_push_as(args, const char*, strload.c_str());
80 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
81 int neighbor = hosts[i].neighbors[j];
82 const char* neighbor_name = hostdata::at(neighbor).get_name();
83 XBT_DEBUG("%s/neighbor -> \"%s\"", hostname, neighbor_name);
84 xbt_dynar_push_as(args, const char*, neighbor_name);
86 MSG_set_function(hostname, "compute", args);
87 xbt_dynar_reset(args);
89 xbt_dynar_free(&args);
92 void deployment_btree::generate()
94 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
95 unsigned left_child = 2 * i + 1;
96 unsigned right_child = 2 * i + 2;
97 if (left_child < size()) {
98 set_link(i, left_child);
99 if (right_child < size())
100 set_link(i, right_child);
105 void deployment_clique::generate()
107 for (unsigned i = 0 ; i < size() ; ++i)
108 for (unsigned j = 0 ; j < i ; ++j)
112 void deployment_hcube::generate()
114 for (unsigned i = 0 ; i < size() ; ++i)
115 for (unsigned j = 0 ; j < i ; ++j) {
116 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
118 unsigned val = i ^ j;
120 // Count the number of set bits
121 while (val && dist < 2) {
130 void deployment_line::generate()
132 for (unsigned i = 0 ; i < size() - 1 ; ++i)
136 void deployment_ring::generate()
138 set_neighbor(0, size() - 1);
139 for (unsigned i = 0 ; i < size() - 1 ; ++i)
141 set_neighbor(size() - 1, 0);
144 void deployment_star::generate()
146 for (unsigned i = 1 ; i < size() ; ++i)
150 void deployment_torus::generate()
155 unsigned c = (a + b) / 2;
162 // here width == ceil(sqrt(size))
164 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
165 XBT_DEBUG("torus size = %zu ; width = %u ; height = %zu ; foll = %u",
166 size(), width, size() / width + !!(size() % width),
168 for (unsigned i = 0; i < size(); i++) {
171 unsigned next_column;
172 unsigned prev_column;
174 next_line = i + width;
175 if (next_line >= size())
176 next_line %= width; // rewind
179 prev_line = i - width;
181 prev_line = first_on_last_line + i; // rewind
182 if (prev_line >= size())
183 prev_line -= width; // need to go at last but one line
186 if (i != size() - 1) {
188 if (next_column % width == 0)
189 next_column -= width; // rewind
191 next_column = first_on_last_line; // special case for last cell
194 if (i % width != 0) {
196 } else if (i < first_on_last_line) {
197 prev_column = i + width - 1; // rewind
199 prev_column = size() - 1; // special case for 1st cell of last line
201 if (next_line != i) {
202 set_neighbor(i, next_line);
203 if (prev_line != next_line)
204 set_neighbor(i, prev_line);
206 if (next_column != i) {
207 set_neighbor(i, next_column);
208 if (prev_column != next_column)
209 set_neighbor(i, prev_column);