3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
4 All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/sysdep.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
15 "Logging specific to SIMIX (hosts)");
17 /********************************* Host **************************************/
18 smx_host_t __SIMIX_host_create(const char *name,
19 void *workstation, void *data)
21 smx_simdata_host_t simdata = xbt_new0(s_smx_simdata_host_t, 1);
22 smx_host_t host = xbt_new0(s_smx_host_t, 1);
26 host->name = xbt_strdup(name);
27 host->simdata = simdata;
30 simdata->host = workstation;
32 simdata->process_list =
33 xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
34 /* Update global variables */
36 xbt_dict_set(simix_global->host, host->name, host, &__SIMIX_host_destroy);
42 * \brief Set the user data of a #smx_host_t.
44 * This functions checks whether some data has already been associated to \a host or not and attach \a data to \a host if it is possible.
45 * \param host SIMIX host
46 * \param data User data
49 void SIMIX_host_set_data(smx_host_t host, void *data)
51 xbt_assert0((host != NULL), "Invalid parameters");
52 xbt_assert0((host->data == NULL), "Data already set");
61 * \brief Return the user data of a #smx_host_t.
63 * This functions checks whether \a host is a valid pointer or not and return the user data associated to \a host if it is possible.
64 * \param host SIMIX host
66 void *SIMIX_host_get_data(smx_host_t host)
68 xbt_assert0((host != NULL), "Invalid parameters");
75 * \brief Return the name of the #smx_host_t.
77 * This functions checks whether \a host is a valid pointer or not and return its name.
78 * \param host SIMIX host
80 const char *SIMIX_host_get_name(smx_host_t host)
83 xbt_assert0((host != NULL)
84 && (host->simdata != NULL), "Invalid parameters");
91 * \brief Return the location on which the current process is executed.
93 * Return the host, more details in #SIMIX_process_get_host
96 smx_host_t SIMIX_host_self(void)
98 return SIMIX_process_get_host(SIMIX_process_self());
102 * Real function for destroy a host.
103 * MSG_host_destroy is just a front_end that also removes it from
106 void __SIMIX_host_destroy(void *h)
108 smx_host_t host = (smx_host_t) h;
109 smx_simdata_host_t simdata = NULL;
111 xbt_assert0((host != NULL), "Invalid parameters");
114 /* Clean Simulator data */
115 simdata = host->simdata;
117 if (xbt_swag_size(simdata->process_list) != 0) {
119 bprintf("Shutting down host %s, but it's not empty:", host->name);
121 smx_process_t process = NULL;
123 xbt_swag_foreach(process, simdata->process_list) {
124 tmp = bprintf("%s\n\t%s", msg, process->name);
128 THROW1(arg_error, 0, "%s", msg);
131 xbt_swag_free(simdata->process_list);
135 /* Clean host structure */
143 * \brief Return the current number of #smx_host_t.
145 * \return Number of hosts
147 int SIMIX_host_get_number(void)
149 return (xbt_dict_size(simix_global->host));
154 * \brief Return an array of all the #smx_host_t.
156 * \return List of all hosts (in a newly allocated table)
158 smx_host_t *SIMIX_host_get_table(void)
160 smx_host_t *res = xbt_new(smx_host_t, xbt_dict_size(simix_global->host));
166 xbt_dict_foreach(simix_global->host, c, name, h)
173 * \brief Return a dict of all the #smx_host_t.
175 * \return List of all hosts (as a #xbt_dict_t)
177 xbt_dict_t SIMIX_host_get_dict(void)
179 return simix_global->host;
183 * \brief Return the speed of the processor.
185 * Return the speed (in Mflop/s), regardless of the current load on the machine.
186 * \param host SIMIX host
189 double SIMIX_host_get_speed(smx_host_t host)
191 xbt_assert0((host != NULL), "Invalid parameters");
193 return (surf_workstation_model->extension_public->
194 get_speed(host->simdata->host, 1.0));
198 * \brief Return the available speed of the processor.
200 * Return the available speed (in Mflop/s).
203 double SIMIX_host_get_available_speed(smx_host_t host)
205 xbt_assert0((host != NULL), "Invalid parameters");
207 return (surf_workstation_model->extension_public->
208 get_available_speed(host->simdata->host));
212 * \brief Return the host by its name
214 * Finds a smx_host_t using its name.
215 * \param name The name of an host.
216 * \return The corresponding host
218 smx_host_t SIMIX_host_get_by_name(const char *name)
220 xbt_assert0(((simix_global != NULL)
221 && (simix_global->host != NULL)), "Environment not set yet");
223 return xbt_dict_get_or_null(simix_global->host, name);
227 * \brief Returns a xbt_dynar_t consisting of the list of properties assigned to this host
230 * \return the dynamic array consisting of property names
232 xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
234 xbt_assert0((host != NULL), "Invalid parameters");
236 return (surf_workstation_model->common_public->
237 get_properties(host->simdata->host));
243 * \brief Return the state of a workstation
245 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
246 * \param host The SIMIX host
247 * \return 1 if host is available or 0 if not.
249 int SIMIX_host_get_state(smx_host_t host)
251 xbt_assert0((host != NULL), "Invalid parameters");
253 return (surf_workstation_model->extension_public->
254 get_state(host->simdata->host));