Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate MSG_get_host_{table,number}; Implement MSG_hosts_as_dynar() instead.
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 28 Feb 2012 10:22:30 +0000 (11:22 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 28 Feb 2012 10:22:30 +0000 (11:22 +0100)
ChangeLog
examples/msg/io/file.c
examples/msg/masterslave/masterslave_arg.c
examples/msg/masterslave/masterslave_cluster.c
examples/msg/parallel_task/parallel_task.c
examples/msg/token_ring/ring_call.c
include/msg/msg.h
src/msg/msg_host.c
teshsuite/simdag/platforms/basic_tracing.c

index 444c12f..4662d24 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,9 @@ SimGrid (3.7) NOT RELEASED; urgency=low
      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.
      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
 
   Simix:
   * Stabilize the parallel execution mode of user contexts
index ed5ed3a..3cd1c83 100644 (file)
@@ -39,18 +39,17 @@ int main(int argc, char **argv)
     int i,res;
   MSG_global_init(&argc, argv);
   MSG_create_environment(argv[1]);
     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);
 
   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);
   {
     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);
   }
     free(name_host);
   }
-  xbt_free(host_table);
+  xbt_dynar_free(&hosts);
 
   res = MSG_main();
   XBT_INFO("Simulation time %g", MSG_get_clock());
 
   res = MSG_main();
   XBT_INFO("Simulation time %g", MSG_get_clock());
index 249722a..78984f5 100644 (file)
@@ -109,10 +109,12 @@ int main(int argc, char *argv[])
 
   number_of_jobs = atol(argv[2]);
   number_of_slaves = atol(argv[3]);
 
   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,
 
   MSG_process_create( "master",
                       master,
index 7676189..6f871fd 100644 (file)
@@ -134,9 +134,12 @@ static int bypass_deployment(void)
        static int surfxml_bufferstack_size = 2048;
        static int surfxml_buffer_stack_stack_ptr = 0;
        static int surfxml_buffer_stack_stack[1024];
        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);
        /* 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");
 
        /* <platform> */
        SURFXML_BUFFER_SET(platform_version, "3");
index f546f6c..c45849b 100644 (file)
@@ -20,6 +20,7 @@ MSG_error_t test_all(const char *platform_file);
 /** Emitter function  */
 int test(int argc, char *argv[])
 {
 /** 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;
   int slaves_count = 0;
   m_host_t *slaves = NULL;
   double task_comp_size = 100000;
@@ -29,8 +30,10 @@ int test(int argc, char *argv[])
   m_task_t ptask = NULL;
   int i, j;
 
   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);
 
   computation_amount = xbt_new0(double, slaves_count);
   communication_amount = xbt_new0(double, slaves_count * slaves_count);
@@ -62,15 +65,17 @@ int test(int argc, char *argv[])
 MSG_error_t test_all(const char *platform_file)
 {
   MSG_error_t res = MSG_OK;
 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);
 
 
   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();
   res = MSG_main();
-  xbt_free(hosts);
+  xbt_dynar_free(&all_hosts);
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return res;
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return res;
index be67d1c..2793022 100644 (file)
@@ -12,7 +12,8 @@
 int host(int argc, char *argv[]);
 unsigned int task_comp_size = 50000000;
 unsigned int task_comm_size = 1000000;
 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_LOG_NEW_DEFAULT_CATEGORY(ring,
                              "Messages specific for this msg example");
@@ -40,7 +41,7 @@ int host(int argc, char *argv[])
     xbt_assert(res == MSG_OK, "MSG_task_get failed");
     XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
 
     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);
       sprintf(mailbox, "0");
     else
       sprintf(mailbox, "%d", host_number+1);
@@ -55,18 +56,17 @@ int main(int argc, char **argv)
        int i,res;
   MSG_global_init(&argc, argv);
   MSG_create_environment(argv[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);
 
   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);
   {
     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);
   }
     free(name_host);
   }
-  xbt_free(host_table);
+  xbt_dynar_free(&hosts);
 
   res = MSG_main();
   XBT_INFO("Simulation time %g", MSG_get_clock());
 
   res = MSG_main();
   XBT_INFO("Simulation time %g", MSG_get_clock());
index 8eafcb6..c5a41d1 100644 (file)
@@ -65,8 +65,7 @@ XBT_PUBLIC(void) MSG_create_environment(const char *file);
 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(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,
 
 /************************** Process handling *********************************/
 XBT_PUBLIC(m_process_t) MSG_process_create(const char *name,
@@ -224,6 +223,9 @@ MSG_error_t MSG_action_trace_run(char *path);
 
 #ifdef MSG_USE_DEPRECATED
 /* these are the functions which are deprecated. Do not use them, they may get removed in future releases */
 
 #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) \
 #define MSG_TIMEOUT_FAILURE MSG_TIMEOUT
 #define MSG_TASK_CANCELLED MSG_TASK_CANCELED
 #define MSG_mailbox_put_with_time_out(mailbox, task, timeout) \
index b2a53eb..9f35815 100644 (file)
@@ -147,17 +147,12 @@ void __MSG_host_destroy(m_host_t host)
   free(host);
 }
 
   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);
 }
 
 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;
 m_host_t *MSG_get_host_table(void)
 {
       void **array;
@@ -178,6 +173,23 @@ m_host_t *MSG_get_host_table(void)
 
          return (m_host_t *)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
 
 /** \ingroup m_host_management
  * \brief Return the number of MSG tasks currently running on a
index 10bb847..293aa6e 100644 (file)
@@ -23,10 +23,15 @@ int host(int argc, char *argv[])
 int main(int argc, char **argv)
 {
   int res;
 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_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());
 
   res = MSG_main();
   XBT_INFO("Simulation time %g", MSG_get_clock());