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"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
14 "Logging specific to SIMIX (hosts)");
16 /********************************* Host **************************************/
17 smx_host_t __SIMIX_host_create(const char *name,
18 void *workstation, void *data)
20 smx_simdata_host_t simdata = xbt_new0(s_smx_simdata_host_t, 1);
21 smx_host_t host = xbt_new0(s_smx_host_t, 1);
25 host->name = xbt_strdup(name);
26 host->simdata = simdata;
29 simdata->host = workstation;
31 simdata->process_list =
32 xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
33 /* Update global variables */
35 xbt_fifo_unshift(simix_global->host, host);
41 * \brief Set the user data of a #smx_host_t.
43 * 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.
44 * \param host SIMIX host
45 * \param data User data
48 void SIMIX_host_set_data(smx_host_t host, void *data)
50 xbt_assert0((host != NULL), "Invalid parameters");
51 xbt_assert0((host->data == NULL), "Data already set");
60 * \brief Return the user data of a #smx_host_t.
62 * 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.
63 * \param host SIMIX host
65 void *SIMIX_host_get_data(smx_host_t host)
67 xbt_assert0((host != NULL), "Invalid parameters");
74 * \brief Return the name of the #smx_host_t.
76 * This functions checks whether \a host is a valid pointer or not and return its name.
77 * \param host SIMIX host
79 const char *SIMIX_host_get_name(smx_host_t host)
82 xbt_assert0((host != NULL)
83 && (host->simdata != NULL), "Invalid parameters");
90 * \brief Return the location on which the current process is executed.
92 * Return the host, more details in #SIMIX_process_get_host
95 smx_host_t SIMIX_host_self(void)
97 return SIMIX_process_get_host(SIMIX_process_self());
101 * Real function for destroy a host.
102 * MSG_host_destroy is just a front_end that also removes it from
105 void __SIMIX_host_destroy(smx_host_t host)
107 smx_simdata_host_t simdata = NULL;
109 xbt_assert0((host != NULL), "Invalid parameters");
112 /* Clean Simulator data */
113 simdata = host->simdata;
115 if (xbt_swag_size(simdata->process_list) != 0) {
117 bprintf("Shutting down host %s, but it's not empty:", host->name);
119 smx_process_t process = NULL;
121 xbt_swag_foreach(process, simdata->process_list) {
122 tmp = bprintf("%s\n\t%s", msg, process->name);
126 THROW1(arg_error, 0, "%s", msg);
129 xbt_swag_free(simdata->process_list);
133 /* Clean host structure */
141 * \brief Return the current number of #smx_host_t.
143 * \return Number of hosts
145 int SIMIX_host_get_number(void)
147 return (xbt_fifo_size(simix_global->host));
151 * \brief Return a array of all the #smx_host_t.
153 * \return List of all hosts
155 smx_host_t *SIMIX_host_get_table(void)
157 return ((smx_host_t *) xbt_fifo_to_array(simix_global->host));
162 * \brief Return the speed of the processor.
164 * Return the speed (in Mflop/s), regardless of the current load on the machine.
165 * \param host SIMIX host
168 double SIMIX_host_get_speed(smx_host_t host)
170 xbt_assert0((host != NULL), "Invalid parameters");
172 return (surf_workstation_resource->
173 extension_public->get_speed(host->simdata->host, 1.0));
177 * \brief Return the available speed of the processor.
179 * Return the available speed (in Mflop/s).
182 double SIMIX_host_get_available_speed(smx_host_t host)
184 xbt_assert0((host != NULL), "Invalid parameters");
186 return (surf_workstation_resource->
187 extension_public->get_available_speed(host->simdata->host));
191 * \brief Return the host by its name
193 * Finds a smx_host_t using its name.
194 * \param name The name of an host.
195 * \return The corresponding host
197 smx_host_t SIMIX_host_get_by_name(const char *name)
199 xbt_fifo_item_t i = NULL;
200 smx_host_t host = NULL;
202 xbt_assert0(((simix_global != NULL)
203 && (simix_global->host != NULL)),
204 "Environment not set yet");
206 xbt_fifo_foreach(simix_global->host, i, host, smx_host_t) {
207 if (strcmp(host->name, name) == 0)
214 * \brief Return the state of a workstation
216 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
217 * \param host The SIMIX host
218 * \return 1 if host is available or 0 if not.
220 int SIMIX_host_get_state(smx_host_t host)
222 xbt_assert0((host != NULL), "Invalid parameters");
224 return (surf_workstation_resource->
225 extension_public->get_state(host->simdata->host));