1 /* $Id: smx_host.c 4895 2007-10-27 07:34:39Z mquinson $ */
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) {
159 smx_host_t *res = xbt_new(smx_host_t,xbt_dict_size(simix_global->host));
165 xbt_dict_foreach(simix_global->host,c,name,h)
172 * \brief Return a dict of all the #smx_host_t.
174 * \return List of all hosts (as a #xbt_dict_t)
176 xbt_dict_t SIMIX_host_get_dict(void) {
177 return simix_global->host;
181 * \brief Return the speed of the processor.
183 * Return the speed (in Mflop/s), regardless of the current load on the machine.
184 * \param host SIMIX host
187 double SIMIX_host_get_speed(smx_host_t host)
189 xbt_assert0((host != NULL), "Invalid parameters");
191 return (surf_workstation_model->
192 extension_public->get_speed(host->simdata->host, 1.0));
196 * \brief Return the available speed of the processor.
198 * Return the available speed (in Mflop/s).
201 double SIMIX_host_get_available_speed(smx_host_t host)
203 xbt_assert0((host != NULL), "Invalid parameters");
205 return (surf_workstation_model->
206 extension_public->get_available_speed(host->simdata->host));
210 * \brief Return the host by its name
212 * Finds a smx_host_t using its name.
213 * \param name The name of an host.
214 * \return The corresponding host
216 smx_host_t SIMIX_host_get_by_name(const char *name)
218 xbt_assert0(((simix_global != NULL)
219 && (simix_global->host != NULL)),
220 "Environment not set yet");
222 return xbt_dict_get_or_null(simix_global->host, name);
226 * \brief Returns a xbt_dynar_t consisting of the list of properties assigned to this host
229 * \return the dynamic array consisting of property names
231 xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
233 xbt_assert0((host != NULL), "Invalid parameters");
235 return (surf_workstation_model->
236 common_public->get_properties(host->simdata->host));
242 * \brief Return the state of a workstation
244 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
245 * \param host The SIMIX host
246 * \return 1 if host is available or 0 if not.
248 int SIMIX_host_get_state(smx_host_t host)
250 xbt_assert0((host != NULL), "Invalid parameters");
252 return (surf_workstation_model->
253 extension_public->get_state(host->simdata->host));