SIMGRID_DEPRECATED before loading the msg.h if you really need to
use these (crappy) functions in your code.
These functions will be removed at some point. Stop using them now.
+ * Deprecate MSG_get_host_{table,number}
+ Implement MSG_hosts_as_dynar() instead.
+ * Implement MSG_processes_as_dynar() (Closes gforge #13642)
Simix:
* Stabilize the parallel execution mode of user contexts
int i,res;
MSG_global_init(&argc, argv);
MSG_create_environment(argv[1]);
- m_host_t *host_table = MSG_get_host_table();
- int number_of_hosts = MSG_get_host_number();
+ xbt_dynar_t hosts = MSG_hosts_as_dynar();
MSG_function_register("host", host);
- XBT_INFO("Number of host '%d'",number_of_hosts);
- for(i = 0 ; i<number_of_hosts; i++)
+ XBT_INFO("Number of host '%zu'",xbt_dynar_length(hosts));
+ for(i = 0 ; i<xbt_dynar_length(hosts); i++)
{
char* name_host = bprintf("%d",i);
- MSG_process_create( name_host, host, NULL, host_table[i] );
+ MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,m_host_t) );
free(name_host);
}
- xbt_free(host_table);
+ xbt_dynar_free(&hosts);
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
number_of_jobs = atol(argv[2]);
number_of_slaves = atol(argv[3]);
- long number_max = MSG_get_host_number();
- XBT_INFO("Got %ld slaves, %ld tasks to process, and %d hosts", number_of_slaves, number_of_jobs,MSG_get_host_number());
+ xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
+ long number_max = xbt_dynar_length(host_dynar);
+ XBT_INFO("Got %ld slaves, %ld tasks to process, and %ld hosts", number_of_slaves, number_of_jobs,number_max);
- m_host_t *host_table = MSG_get_host_table();
+ m_host_t *host_table = xbt_dynar_to_array(host_dynar);
+ xbt_dynar_free(&host_dynar);
MSG_process_create( "master",
master,
static int surfxml_bufferstack_size = 2048;
static int surfxml_buffer_stack_stack_ptr = 0;
static int surfxml_buffer_stack_stack[1024];
+ xbt_dynar_t hosts = MSG_hosts_as_dynar();
/* allocating memory to the buffer, I think 2MB should be enough */
surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
- nb_host = MSG_get_host_number();
+
+ nb_host = xbt_dynar_length(hosts);
+ xbt_dynar_free(&hosts);
/* <platform> */
SURFXML_BUFFER_SET(platform_version, "3");
/** Emitter function */
int test(int argc, char *argv[])
{
+ xbt_dynar_t slaves_dynar;
int slaves_count = 0;
m_host_t *slaves = NULL;
double task_comp_size = 100000;
m_task_t ptask = NULL;
int i, j;
- slaves_count = MSG_get_host_number();
- slaves = MSG_get_host_table();
+ slaves_dynar = MSG_hosts_as_dynar();
+ slaves_count = xbt_dynar_length(slaves_dynar);
+ slaves = xbt_dynar_to_array(slaves_dynar);
+ xbt_dynar_free(&slaves_dynar);
computation_amount = xbt_new0(double, slaves_count);
communication_amount = xbt_new0(double, slaves_count * slaves_count);
MSG_error_t test_all(const char *platform_file)
{
MSG_error_t res = MSG_OK;
- m_host_t *hosts;
+ xbt_dynar_t all_hosts;
+ m_host_t first_host;
MSG_config("workstation/model", "ptask_L07");
MSG_create_environment(platform_file);
- hosts = MSG_get_host_table();
- MSG_process_create("test", test, NULL, hosts[0]);
+ all_hosts = MSG_hosts_as_dynar();
+ first_host = xbt_dynar_pop_as(all_hosts,m_host_t);
+ MSG_process_create("test", test, NULL, first_host);
res = MSG_main();
- xbt_free(hosts);
+ xbt_dynar_free(&all_hosts);
XBT_INFO("Simulation time %g", MSG_get_clock());
return res;
int host(int argc, char *argv[]);
unsigned int task_comp_size = 50000000;
unsigned int task_comm_size = 1000000;
-int number_of_hosts;
+
+xbt_dynar_t hosts; /* All declared hosts */
XBT_LOG_NEW_DEFAULT_CATEGORY(ring,
"Messages specific for this msg example");
xbt_assert(res == MSG_OK, "MSG_task_get failed");
XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
- if(host_number+1 == number_of_hosts )
+ if(host_number+1 == xbt_dynar_length(hosts) )
sprintf(mailbox, "0");
else
sprintf(mailbox, "%d", host_number+1);
int i,res;
MSG_global_init(&argc, argv);
MSG_create_environment(argv[1]);
- m_host_t *host_table = MSG_get_host_table();
- number_of_hosts = MSG_get_host_number();
+ hosts = MSG_hosts_as_dynar();
MSG_function_register("host", host);
- XBT_INFO("Number of host '%d'",number_of_hosts);
- for(i = 0 ; i<number_of_hosts; i++)
+ XBT_INFO("Number of host '%zu'",xbt_dynar_length(hosts));
+ for(i = 0 ; i<xbt_dynar_length(hosts); i++)
{
char* name_host = bprintf("%d",i);
- MSG_process_create( name_host, host, NULL, host_table[i] );
+ MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,m_host_t) );
free(name_host);
}
- xbt_free(host_table);
+ xbt_dynar_free(&hosts);
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
XBT_PUBLIC(void) MSG_load_platform_script(const char *script_file);
XBT_PUBLIC(m_host_t) MSG_get_host_by_name(const char *name);
-XBT_PUBLIC(int) MSG_get_host_number(void);
-XBT_PUBLIC(m_host_t *) MSG_get_host_table(void);
+XBT_PUBLIC(xbt_dynar_t) MSG_hosts_as_dynar(void);
/************************** Process handling *********************************/
XBT_PUBLIC(m_process_t) MSG_process_create(const char *name,
#ifdef MSG_USE_DEPRECATED
/* these are the functions which are deprecated. Do not use them, they may get removed in future releases */
+XBT_PUBLIC(int) MSG_get_host_number(void);
+XBT_PUBLIC(m_host_t *) MSG_get_host_table(void);
+
#define MSG_TIMEOUT_FAILURE MSG_TIMEOUT
#define MSG_TASK_CANCELLED MSG_TASK_CANCELED
#define MSG_mailbox_put_with_time_out(mailbox, task, timeout) \
free(host);
}
-/** \ingroup m_host_management
- * \brief Return the current number of #m_host_t.
- */
+#ifdef MSG_USE_DEPRECATED
int MSG_get_host_number(void)
{
return xbt_lib_length(host_lib);
}
-/** \ingroup m_host_management
- * \brief Return a array of all the #m_host_t.
- */
m_host_t *MSG_get_host_table(void)
{
void **array;
return (m_host_t *)array;
}
+#endif
+
+/** \ingroup m_host_management
+ * \brief Return a dynar containing all the hosts declared at a given point of time
+ */
+xbt_dynar_t MSG_hosts_as_dynar(void) {
+ xbt_lib_cursor_t cursor;
+ char *key;
+ void **data;
+ xbt_dynar_t res = xbt_dynar_new(sizeof(m_host_t),NULL);
+
+ xbt_lib_foreach(host_lib, cursor, key, data) {
+ if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST)
+ xbt_dynar_push(res, data + MSG_HOST_LEVEL);
+ }
+ return res;
+}
/** \ingroup m_host_management
* \brief Return the number of MSG tasks currently running on a
int main(int argc, char **argv)
{
int res;
+ xbt_dynar_t all_hosts;
+ m_host_t first_host;
MSG_global_init(&argc, argv);
MSG_create_environment(argv[1]);
MSG_function_register("host", host);
- MSG_process_create( "host", host, NULL, MSG_get_host_table()[0] );
+ all_hosts = MSG_hosts_as_dynar();
+ first_host = xbt_dynar_pop_as(all_hosts,m_host_t);
+ MSG_process_create( "host", host, NULL, first_host);
+ xbt_dynar_free(&all_hosts);
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());