10 #include <xbt/dynar.h>
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
19 #include "deployment.h"
21 void MY_launch_application()
23 deployment_generator* gen;
24 gen = opt::topologies.new_instance(opt::auto_depl::topology);
26 gen->distribute_load();
31 deployment_generator::deployment_generator()
32 : hosts(opt::auto_depl::nhosts)
36 void deployment_generator::set_load(int host, double load)
38 hosts[host].load = load;
41 void deployment_generator::set_neighbor(int host, int neighbor)
43 hosts[host].neighbors.push_back(neighbor);
46 void deployment_generator::set_link(int host1, int host2)
48 set_neighbor(host1, host2);
49 set_neighbor(host2, host1);
52 void deployment_generator::distribute_load()
54 using std::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 std::bind(std::multiplies<double>(), _1, factor));
67 if (opt::integer_transfer) {
71 for (i = 0 ; i < hosts.size() - 1; ++i) {
73 iload = std::floor(loads[i]);
74 else if (residue > 0.0)
75 iload = std::ceil(loads[i]);
76 else // residue == 0.0
77 iload = std::round(loads[i]);
78 residue += (loads[i] - iload);
81 // abs(round(...)) to avoid rounding errors, or a value of -0
82 // Note: i == hosts.size() - 1
83 iload = std::abs(std::round(loads[i] + residue));
86 xbt_assert(opt::auto_depl::load ==
87 std::accumulate(loads.begin(), loads.end(), 0.0));
89 for (unsigned i = 0 ; i < hosts.size() ; ++i)
90 set_load(i, loads[i]);
93 void deployment_generator::deploy()
95 xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL);
96 for (unsigned i = 0 ; i < hosts.size() ; ++i) {
97 const char* hostname = hostdata::at(i).get_name();
98 std::ostringstream oss;
99 oss << std::setprecision(12) << hosts[i].load;
100 std::string strload = oss.str();
101 XBT_DEBUG("%s/load -> \"%s\"", hostname, strload.c_str());
102 xbt_dynar_push_as(args, const char*, strload.c_str());
103 for (unsigned j = 0 ; j < hosts[i].neighbors.size() ; ++j) {
104 int neighbor = hosts[i].neighbors[j];
105 const char* neighbor_name = hostdata::at(neighbor).get_name();
106 XBT_DEBUG("%s/neighbor -> \"%s\"", hostname, neighbor_name);
107 xbt_dynar_push_as(args, const char*, neighbor_name);
109 MSG_set_function(hostname, "compute", args);
110 xbt_dynar_reset(args);
112 xbt_dynar_free(&args);
115 void deployment_btree::generate()
117 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
118 unsigned left_child = 2 * i + 1;
119 unsigned right_child = 2 * i + 2;
120 if (left_child < size()) {
121 set_link(i, left_child);
122 if (right_child < size())
123 set_link(i, right_child);
128 void deployment_clique::generate()
130 for (unsigned i = 0 ; i < size() ; ++i)
131 for (unsigned j = 0 ; j < i ; ++j)
135 void deployment_hcube::generate()
137 for (unsigned i = 0 ; i < size() ; ++i)
138 for (unsigned j = 0 ; j < i ; ++j) {
139 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
141 unsigned val = i ^ j;
143 // Count the number of set bits
144 while (val && dist < 2) {
153 void deployment_line::generate()
155 for (unsigned i = 0 ; i < size() - 1 ; ++i)
159 void deployment_ring::generate()
161 set_neighbor(0, size() - 1);
162 for (unsigned i = 0 ; i < size() - 1 ; ++i)
164 set_neighbor(size() - 1, 0);
167 void deployment_star::generate()
169 for (unsigned i = 1 ; i < size() ; ++i)
173 void deployment_torus::generate()
178 unsigned c = (a + b) / 2;
185 // here width == std::ceil(std::sqrt(size))
187 unsigned first_on_last_line = (size() - 1) - (size() - 1) % width;
188 XBT_DEBUG("torus size = %zu ; width = %u ; height = %zu ; foll = %u",
189 size(), width, size() / width + !!(size() % width),
191 for (unsigned i = 0; i < size(); i++) {
194 unsigned next_column;
195 unsigned prev_column;
197 next_line = i + width;
198 if (next_line >= size())
199 next_line %= width; // rewind
202 prev_line = i - width;
204 prev_line = first_on_last_line + i; // rewind
205 if (prev_line >= size())
206 prev_line -= width; // need to go at last but one line
209 if (i != size() - 1) {
211 if (next_column % width == 0)
212 next_column -= width; // rewind
214 next_column = first_on_last_line; // special case for last cell
217 if (i % width != 0) {
219 } else if (i < first_on_last_line) {
220 prev_column = i + width - 1; // rewind
222 prev_column = size() - 1; // special case for 1st cell of last line
224 if (next_line != i) {
225 set_neighbor(i, next_line);
226 if (prev_line != next_line)
227 set_neighbor(i, prev_line);
229 if (next_column != i) {
230 set_neighbor(i, next_column);
231 if (prev_column != next_column)
232 set_neighbor(i, prev_column);