]> AND Private Git Repository - loba.git/blob - hostdata.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
ag_parameters: set -S0.5 and -g2000.
[loba.git] / hostdata.cpp
1 #include <algorithm>
2 #include <cstring>
3 #include <functional>
4 #include <stdexcept>
5 #include <xbt/log.h>
6 #include <xbt/sysdep.h>
7
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
9
10 #include "misc.h"
11 #include "options.h"
12
13 #include "hostdata.h"
14
15 std::vector<hostdata> hostdata::hosts;
16
17 void hostdata::create()
18 {
19     using std::placeholders::_1;
20     using std::placeholders::_2;
21
22 #if SIMGRID_VERSION < MAKE_SIMGRID_VERSION(3, 7, 0)
23     int nhosts = MSG_get_host_number();
24     m_host_t* host_list = MSG_get_host_table();
25 #else // API changed with SG 3.7.0
26     xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
27     int nhosts = xbt_dynar_length(host_dynar);
28     m_host_t* host_list = static_cast<m_host_t*>(xbt_dynar_to_array(host_dynar));
29 #endif
30     // only sort hosts for automatically created deployment
31     if (opt::auto_depl::enabled)
32         std::sort(host_list, host_list + nhosts,
33                   std::bind(std::less<int>(),
34                             std::bind(strcmp,
35                                       std::bind(MSG_host_get_name, _1),
36                                       std::bind(MSG_host_get_name, _2)), 0));
37     hosts.assign(host_list, host_list + nhosts);
38     xbt_free(host_list);
39
40     e_xbt_log_priority_t logp = xbt_log_priority_verbose;
41     if (!LOG_ISENABLED(logp))
42         return;
43     XBT_LOG(logp, "Got %zu hosts.", hosts.size());
44     for (int i = 0; i < nhosts; i++) {
45         XBT_LOG(logp, "Host #%d named \"%s\".", i, hosts[i].get_name());
46     }
47 }
48
49 void hostdata::destroy()
50 {
51     // hosts are automatically destroyed...
52 }
53
54 hostdata::hostdata(m_host_t host)
55     : name(MSG_host_get_name(host))
56     , ctrl_mbox(std::string(name) + "_ctrl")
57     , data_mbox(std::string(name) + "_data")
58 {
59     MSG_host_set_data(host, this);
60 }
61
62 hostdata::~hostdata()
63 {
64 }