1 /* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_HOST_H_
7 #define SIMGRID_HOST_H_
12 #include <xbt/dynar.h>
14 #include <simgrid/forward.h>
18 XBT_PUBLIC sg_host_t* sg_host_list();
20 /** \ingroup m_host_management
21 * \brief Return the current number MSG hosts.
23 XBT_PUBLIC size_t sg_host_count();
24 #define MSG_get_host_number() sg_host_count()
26 /** \ingroup m_host_management
27 * \brief Return a dynar containing all the hosts declared at a given point of time (including VMs)
28 * \remark The host order in the returned array is generally different from the host creation/declaration order in the
29 * XML platform (we use a hash table internally)
31 XBT_PUBLIC xbt_dynar_t sg_hosts_as_dynar();
32 #define MSG_hosts_as_dynar() sg_hosts_as_dynar()
34 XBT_PUBLIC size_t sg_host_extension_create(void (*deleter)(void*));
35 XBT_PUBLIC void* sg_host_extension_get(sg_host_t host, size_t rank);
37 /** \ingroup m_host_management
38 * \brief Finds a msg_host_t using its name.
40 * This is a name directory service
41 * \param name the name of an host.
42 * \return the corresponding host
44 XBT_PUBLIC sg_host_t sg_host_by_name(const char* name);
45 #define MSG_host_by_name(name) sg_host_by_name(name)
46 #define MSG_get_host_by_name(n) sg_host_by_name(n) /* Rewrite the old name into the new one transparently */
48 /** \ingroup m_host_management
50 * \brief Return the name of the #msg_host_t. */
51 XBT_PUBLIC const char* sg_host_get_name(sg_host_t host);
52 #define MSG_host_get_name(host) sg_host_get_name(host)
54 // ========== User Data ==============
55 /** \ingroup m_host_management
57 * \brief Return the user data of a #msg_host_t.
59 * This functions returns the user data associated to \a host if it is possible.
61 XBT_PUBLIC void* sg_host_user(sg_host_t host);
62 #define MSG_host_get_data(host) sg_host_user(host)
63 /** \ingroup m_host_management
65 * \brief Set the user data of a #msg_host_t.
67 * This functions attach \a data to \a host if it is possible.
69 XBT_PUBLIC void sg_host_user_set(sg_host_t host, void* userdata);
70 #define MSG_host_set_data(host, data) sg_host_user_set(host, data)
71 XBT_PUBLIC void sg_host_user_destroy(sg_host_t host);
73 // ========= storage related functions ============
74 /** \ingroup m_host_management
75 * \brief Return the list of mount point names on an host.
77 * \return a dict containing all mount point on the host (mount_name => msg_storage_t)
79 XBT_PUBLIC xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host);
80 #define MSG_host_get_mounted_storage_list(host) sg_host_get_mounted_storage_list(host)
82 /** \ingroup m_host_management
83 * \brief Return the list of storages attached to an host.
85 * \return a dynar containing all storages (name) attached to the host
87 XBT_PUBLIC xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host);
88 #define MSG_host_get_attached_storage_list(host) host_get_attached_storage_list(host)
90 // =========== user-level functions ===============
91 /** \ingroup m_host_management
92 * \brief Return the speed of the processor (in flop/s), regardless of the current load on the machine.
94 XBT_PUBLIC double sg_host_speed(sg_host_t host);
95 #define MSG_host_get_speed(host) sg_host_speed(host)
96 XBT_PUBLIC double sg_host_get_available_speed(sg_host_t host);
98 XBT_PUBLIC int sg_host_core_count(sg_host_t host);
99 #define MSG_host_get_core_number(host) sg_host_core_count(host)
101 /** \ingroup m_process_management
102 * \brief Return the location on which a process is running.
103 * \param process a process (nullptr means the current one)
104 * \return the msg_host_t corresponding to the location on which \a process is running.
106 XBT_PUBLIC sg_host_t sg_host_self();
107 #define MSG_host_self() sg_host_self()
109 XBT_PUBLIC const char* sg_host_self_get_name();
111 /** \ingroup m_host_management
112 * \brief Return the total count of pstates defined for a host. See also @ref plugin_energy.
114 * \param host host to test
116 XBT_PUBLIC int sg_host_get_nb_pstates(sg_host_t host);
117 #define MSG_host_get_nb_pstates(host) sg_host_get_nb_pstates(host)
119 XBT_PUBLIC int sg_host_get_pstate(sg_host_t host);
120 #define MSG_host_get_pstate(h) sg_host_get_pstate(h) /* users don't know that MSG is the C version of SimGrid */
121 XBT_PUBLIC void sg_host_set_pstate(sg_host_t host, int pstate);
122 #define MSG_host_set_pstate(h, pstate) sg_host_set_pstate(h, pstate) /* (same here) */
124 XBT_PUBLIC void sg_host_turn_on(sg_host_t host);
125 #define MSG_host_on(h) sg_host_turn_on(h)
126 XBT_PUBLIC void sg_host_turn_off(sg_host_t host);
127 #define MSG_host_off(h) sg_host_turn_off(h)
128 XBT_PUBLIC int sg_host_is_on(sg_host_t host);
129 #define MSG_host_is_on(h) sg_host_is_on(h)
130 XBT_PUBLIC int sg_host_is_off(sg_host_t host);
131 #define MSG_host_is_off(h) sg_host_is_off(h)
133 /** \ingroup m_host_management
134 * \brief Returns a xbt_dict_t consisting of the list of properties assigned to this host
137 * \return a dict containing the properties
139 XBT_PUBLIC xbt_dict_t sg_host_get_properties(sg_host_t host);
140 #define MSG_host_get_properties(host) sg_host_get_properties(host)
142 /** \ingroup m_host_management
143 * \brief Returns the value of a given host property
146 * \param name a property name
147 * \return value of a property (or nullptr if property not set)
149 XBT_PUBLIC const char* sg_host_get_property_value(sg_host_t host, const char* name);
150 #define MSG_host_get_property_value(host, name) sg_host_get_property_value(host, name)
152 /** \ingroup m_host_management
153 * \brief Change the value of a given host property
156 * \param name a property name
157 * \param value what to change the property to
159 XBT_PUBLIC void sg_host_set_property_value(sg_host_t host, const char* name, const char* value);
160 #define MSG_host_set_property_value(host, name, value) sg_host_set_property_value(host, name, value)
162 XBT_PUBLIC void sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links);
163 XBT_PUBLIC double sg_host_route_latency(sg_host_t from, sg_host_t to);
164 XBT_PUBLIC double sg_host_route_bandwidth(sg_host_t from, sg_host_t to);
165 XBT_PUBLIC void sg_host_dump(sg_host_t ws);
168 #endif /* SIMGRID_HOST_H_ */