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 /********************************* Host **************************************/
15 smx_host_t __SIMIX_host_create(const char *name,
19 smx_simdata_host_t simdata = xbt_new0(s_smx_simdata_host_t,1);
20 smx_host_t host = xbt_new0(s_smx_host_t,1);
24 host->name = xbt_strdup(name);
25 host->simdata = simdata;
28 simdata->host = workstation;
30 simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
31 /* Update global variables */
33 xbt_fifo_unshift(simix_global->host, host);
39 * \brief Set the user data of a #smx_host_t.
41 * 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.
42 * \param host SIMIX host
43 * \param data User data
46 void SIMIX_host_set_data(smx_host_t host, void *data)
48 xbt_assert0((host!=NULL), "Invalid parameters");
49 xbt_assert0((host->data == NULL), "Data already set");
58 * \brief Return the user data of a #smx_host_t.
60 * 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.
61 * \param host SIMIX host
63 void *SIMIX_host_get_data(smx_host_t host)
65 xbt_assert0((host != NULL), "Invalid parameters");
72 * \brief Return the name of the #smx_host_t.
74 * This functions checks whether \a host is a valid pointer or not and return its name.
75 * \param host SIMIX host
77 const char *SIMIX_host_get_name(smx_host_t host)
80 xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
87 * \brief Return the location on which the current process is executed.
89 * Return the host, more details in #SIMIX_process_get_host
92 smx_host_t SIMIX_host_self(void)
94 return SIMIX_process_get_host(SIMIX_process_self());
98 * Real function for destroy a host.
99 * MSG_host_destroy is just a front_end that also removes it from
102 void __SIMIX_host_destroy(smx_host_t host)
104 smx_simdata_host_t simdata = NULL;
106 xbt_assert0((host != NULL), "Invalid parameters");
109 /* Clean Simulator data */
110 simdata = host->simdata;
112 xbt_assert0((xbt_swag_size(simdata->process_list)==0),
113 "Some process are still running on this host");
114 xbt_swag_free(simdata->process_list);
118 /* Clean host structure */
126 * \brief Return the current number of #smx_host_t.
128 * \return Number of hosts
130 int SIMIX_host_get_number(void)
132 return (xbt_fifo_size(simix_global->host));
136 * \brief Return a array of all the #smx_host_t.
138 * \return List of all hosts
140 smx_host_t *SIMIX_host_get_table(void)
142 return ((smx_host_t *)xbt_fifo_to_array(simix_global->host));
147 * \brief Return the speed of the processor.
149 * Return the speed (in Mflop/s), regardless of the current load on the machine.
150 * \param host SIMIX host
153 double SIMIX_host_get_speed(smx_host_t host)
155 xbt_assert0((host!= NULL), "Invalid parameters");
157 return(surf_workstation_resource->
158 extension_public->get_speed(host->simdata->host,1.0));
162 * \brief Return the available speed of the processor.
164 * Return the available speed (in Mflop/s).
167 double SIMIX_host_get_available_speed(smx_host_t host)
169 xbt_assert0((host!= NULL), "Invalid parameters");
171 return(surf_workstation_resource->
172 extension_public->get_available_speed(host->simdata->host));
176 * \brief Return the host by its name
178 * Finds a smx_host_t using its name.
179 * \param name The name of an host.
180 * \return The corresponding host
182 smx_host_t SIMIX_host_get_by_name(const char *name)
184 xbt_fifo_item_t i = NULL;
185 smx_host_t host = NULL;
187 xbt_assert0(((simix_global != NULL)
188 && (simix_global->host != NULL)), "Environment not set yet");
190 xbt_fifo_foreach(simix_global->host,i,host,smx_host_t) {
191 if(strcmp(host->name, name) == 0) return host;
197 * \brief Return the state of a workstation
199 * Return the state of a workstation. Two states are possible, 1 if the host is active or 0 if it has crashed.
200 * \param host The SIMIX host
201 * \return 1 if host is available or 0 if not.
203 int SIMIX_host_get_state(smx_host_t host)
205 xbt_assert0((host!= NULL), "Invalid parameters");
207 return(surf_workstation_resource->
208 extension_public->get_state(host->simdata->host));