Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Massive cleanup in masterslave
[simgrid.git] / examples / msg / masterslave / masterslave.c
similarity index 61%
rename from examples/msg/masterslave/masterslave_forwarder.c
rename to examples/msg/masterslave/masterslave.c
index 74e3858..c731acd 100644 (file)
@@ -10,31 +10,23 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example")
 
 /** @addtogroup MSG_examples
  * 
- *  - <b>masterslave/masterslave_forwarder.c: Master/slaves example</b>. This good old example is also very simple. Its
+ *  - <b>masterslave/masterslave.c: Master/slaves example</b>. This good old example is also very simple. Its
  *    basic version is fully commented on this page: \ref MSG_ex_master_slave, but several variants can be found in the
  *    same directory.
  */
 
 #define FINALIZE ((void*)221297)        /* a magic number to tell people to stop working */
 
-/** Emitter function  */
 static int master(int argc, char *argv[])
 {
-  int slaves_count = 0;
   msg_host_t *slaves = NULL;
   msg_task_t *todo = NULL;
-  int number_of_tasks = 0;
-  double task_comp_size = 0;
-  double task_comm_size = 0;
-
+  long slaves_count = 0;
   int i;
 
-  XBT_ATTRIB_UNUSED int res = sscanf(argv[1], "%d", &number_of_tasks);
-  xbt_assert(res,"Invalid argument %s\n", argv[1]);
-  res = sscanf(argv[2], "%lg", &task_comp_size);
-  xbt_assert(res, "Invalid argument %s\n", argv[2]);
-  res = sscanf(argv[3], "%lg", &task_comm_size);
-  xbt_assert(res, "Invalid argument %s\n", argv[3]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
+  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
 
   {                             /*  Task creation */
     char sprintf_buffer[64];
@@ -57,7 +49,7 @@ static int master(int argc, char *argv[])
     }
   }
 
-  XBT_INFO("Got %d slaves and %d tasks to process", slaves_count, number_of_tasks);
+  XBT_INFO("Got %ld slaves and %ld tasks to process", slaves_count, number_of_tasks);
   for (i = 0; i < slaves_count; i++)
     XBT_DEBUG("%s", MSG_host_get_name(slaves[i]));
 
@@ -107,53 +99,6 @@ static int slave(int argc, char *argv[])
   return 0;
 }
 
-static int forwarder(int argc, char *argv[])
-{
-  int i;
-  int slaves_count;
-  msg_host_t *slaves;
-
-  {                             /* Process organization */
-    slaves_count = argc - 1;
-    slaves = xbt_new0(msg_host_t, slaves_count);
-
-    for (i = 1; i < argc; i++) {
-      slaves[i - 1] = MSG_host_by_name(argv[i]);
-      if (slaves[i - 1] == NULL) {
-        XBT_INFO("Unknown host %s. Stopping Now! ", argv[i]);
-        abort();
-      }
-    }
-  }
-
-  i = 0;
-  while (1) {
-    msg_task_t task = NULL;
-    int a;
-    a = MSG_task_receive(&(task),MSG_host_get_name(MSG_host_self()));
-    if (a == MSG_OK) {
-      XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
-      if (MSG_task_get_data(task) == FINALIZE) {
-        XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
-        for (i = 0; i < slaves_count; i++)
-          MSG_task_send(MSG_task_create("finalize", 0, 0, FINALIZE), MSG_host_get_name(slaves[i]));
-        MSG_task_destroy(task);
-        break;
-      }
-      XBT_INFO("Sending \"%s\" to \"%s\"", MSG_task_get_name(task), MSG_host_get_name(slaves[i % slaves_count]));
-      MSG_task_send(task, MSG_host_get_name(slaves[i % slaves_count]));
-      i++;
-    } else {
-      XBT_INFO("Hey ?! What's up ? ");
-      xbt_die("Unexpected behavior");
-    }
-  }
-  xbt_free(slaves);
-
-  XBT_INFO("I'm done. See you!");
-  return 0;
-}
-
 int main(int argc, char *argv[])
 {
   msg_error_t res = MSG_OK;
@@ -166,7 +111,6 @@ int main(int argc, char *argv[])
 
   MSG_function_register("master", master);
   MSG_function_register("slave", slave);
-  MSG_function_register("forwarder", forwarder);
   MSG_launch_application(argv[2]);
 
   res = MSG_main();