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,
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 = 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) && (host->simdata != NULL), "Invalid parameters");
89 * \brief Return the location on which the current process is executed.
91 * Return the host, more details in #SIMIX_process_get_host
94 smx_host_t SIMIX_host_self(void)
96 return SIMIX_process_get_host(SIMIX_process_self());
100 * Real function for destroy a host.
101 * MSG_host_destroy is just a front_end that also removes it from
104 void __SIMIX_host_destroy(smx_host_t host)
106 smx_simdata_host_t simdata = NULL;
108 xbt_assert0((host != NULL), "Invalid parameters");
111 /* Clean Simulator data */
112 simdata = host->simdata;
114 if (xbt_swag_size(simdata->process_list) != 0) {
115 char *msg=bprintf("Shutting down host %s, but it's not empty:", host->name);
117 smx_process_t process = NULL;
119 xbt_swag_foreach(process, simdata->process_list) {
120 tmp = bprintf("%s\n\t%s",msg,process->name);
124 THROW1(arg_error,0,"%s",msg);
127 xbt_swag_free(simdata->process_list);
131 /* Clean host structure */
139 * \brief Return the current number of #smx_host_t.
141 * \return Number of hosts
143 int SIMIX_host_get_number(void)
145 return (xbt_fifo_size(simix_global->host));
149 * \brief Return a array of all the #smx_host_t.
151 * \return List of all hosts
153 smx_host_t *SIMIX_host_get_table(void)
155 return ((smx_host_t *)xbt_fifo_to_array(simix_global->host));
160 * \brief Return the speed of the processor.
162 * Return the speed (in Mflop/s), regardless of the current load on the machine.
163 * \param host SIMIX host
166 double SIMIX_host_get_speed(smx_host_t host)
168 xbt_assert0((host!= NULL), "Invalid parameters");
170 return(surf_workstation_resource->
171 extension_public->get_speed(host->simdata->host,1.0));
175 * \brief Return the available speed of the processor.
177 * Return the available speed (in Mflop/s).
180 double SIMIX_host_get_available_speed(smx_host_t host)
182 xbt_assert0((host!= NULL), "Invalid parameters");
184 return(surf_workstation_resource->
185 extension_public->get_available_speed(host->simdata->host));
189 * \brief Return the host by its name
191 * Finds a smx_host_t using its name.
192 * \param name The name of an host.
193 * \return The corresponding host
195 smx_host_t SIMIX_host_get_by_name(const char *name)
197 xbt_fifo_item_t i = NULL;
198 smx_host_t host = NULL;
200 xbt_assert0(((simix_global != NULL)
201 && (simix_global->host != NULL)), "Environment not set yet");
203 xbt_fifo_foreach(simix_global->host,i,host,smx_host_t) {
204 if(strcmp(host->name, name) == 0) return host;
210 * \brief Return the state of a workstation
212 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
213 * \param host The SIMIX host
214 * \return 1 if host is available or 0 if not.
216 int SIMIX_host_get_state(smx_host_t host)
218 xbt_assert0((host!= NULL), "Invalid parameters");
220 return(surf_workstation_resource->
221 extension_public->get_state(host->simdata->host));