Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : add comments for the example bugged2_liveness
[simgrid.git] / examples / msg / masterslave / masterslave_arg.c
index 7ad5d0b..1fc804f 100644 (file)
@@ -23,8 +23,9 @@ int slave(int argc, char *argv[]);
 long number_of_jobs;
 long number_of_slaves;
 
-long my_random(long n) {
-  return n*(rand()/(RAND_MAX+1));
+static long my_random(long n)
+{
+  return n * (rand() / ((double)RAND_MAX + 1));
 }
 
 /** Emitter function  */
@@ -67,7 +68,6 @@ int slave(int argc, char *argv[])
 {
   m_task_t task = NULL;
   _XBT_GNUC_UNUSED int res;
-  int id = -1;
 
   XBT_DEBUG("mailbox: %s",MSG_process_get_name(MSG_process_self()));
   while (1) {
@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
 
   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());
 
   m_host_t *host_table =  MSG_get_host_table();
@@ -118,17 +118,20 @@ int main(int argc, char *argv[])
   MSG_process_create( "master",
                       master,
                       NULL,
-                      host_table[my_random(number_of_slaves)]
+                      host_table[my_random(number_max)]
                       );
 
   for(i = 0 ; i<number_of_slaves; i++)
   {
-      MSG_process_create(bprintf("slave-%ld",i),
+    char* name_host = bprintf("slave-%ld",i);
+      MSG_process_create( name_host,
                           slave,
                           NULL,
-                          host_table[my_random(number_of_slaves)]
+                          host_table[my_random(number_max)]
                           );
+      free(name_host);
   }
+  xbt_free(host_table);
 
   res = MSG_main();