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

Private GIT Repository
Add option -X <double>, for testing and/or debugging purpose.
[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     int nhosts = MSG_get_host_number();
23     m_host_t* host_list = MSG_get_host_table();
24     // only sort hosts for automatically created deployment
25     if (opt::auto_depl::enabled)
26         std::sort(host_list, host_list + nhosts,
27                   std::bind(std::less<int>(),
28                             std::bind(strcmp,
29                                       std::bind(MSG_host_get_name, _1),
30                                       std::bind(MSG_host_get_name, _2)), 0));
31     hosts.assign(host_list, host_list + nhosts);
32     xbt_free(host_list);
33
34     e_xbt_log_priority_t logp = xbt_log_priority_verbose;
35     if (!LOG_ISENABLED(logp))
36         return;
37     XBT_LOG(logp, "Got %zu hosts.", hosts.size());
38     for (int i = 0; i < nhosts; i++) {
39         XBT_LOG(logp, "Host #%d named \"%s\".", i, hosts[i].get_name());
40     }
41 }
42
43 void hostdata::destroy()
44 {
45     // hosts are automatically destroyed...
46 }
47
48 hostdata::hostdata(m_host_t host)
49     : name(MSG_host_get_name(host))
50     , ctrl_mbox(std::string(name) + "_ctrl")
51     , data_mbox(std::string(name) + "_data")
52 {
53     MSG_host_set_data(host, this);
54 }
55
56 hostdata::~hostdata()
57 {
58 }