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_line::generate()
69 for (unsigned i = 0 ; i < size() - 1 ; ++i)
73 void deployment_ring::generate()
75 set_neighbor(0, size() - 1);
76 for (unsigned i = 0 ; i < size() - 1 ; ++i)
78 set_neighbor(size() - 1, 0);
81 void deployment_star::generate()
83 for (unsigned i = 1 ; i < size() ; ++i)
87 void deployment_clique::generate()
89 for (unsigned i = 0 ; i < size() ; ++i)
90 for (unsigned j = 0 ; j < i ; ++j)
94 void deployment_btree::generate()
96 for (unsigned i = 0 ; i < size() / 2 ; ++i) {
97 unsigned left_child = 2 * i + 1;
98 unsigned right_child = 2 * i + 2;
99 if (left_child < size()) {
100 set_link(i, left_child);
101 if (right_child < size())
102 set_link(i, right_child);
107 // void deployment_torus::generate()
111 void deployment_hcube::generate()
113 for (unsigned i = 0 ; i < size() ; ++i)
114 for (unsigned j = 0 ; j < i ; ++j) {
115 // Adapted from rom http://en.wikipedia.org/wiki/Hamming_distance
117 unsigned val = i ^ j;
119 // Count the number of set bits
120 while (val && dist < 2) {