Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rework documentation for
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 9 Apr 2016 20:30:14 +0000 (22:30 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 9 Apr 2016 20:30:14 +0000 (22:30 +0200)
  + pingpong
  + master-worker
  + process-migration

doc/Doxyfile.in
doc/doxygen/module-msg.doc
examples/msg/app-masterworker/app-masterworker.c
examples/msg/app-pingpong/app-pingpong.c
examples/msg/process-migration/process-migration.c
examples/msg/process-migration/process-migration.tesh

index 383a2bc..b008e72 100644 (file)
@@ -699,10 +699,10 @@ INPUT +=                 @CMAKE_HOME_DIRECTORY@/examples/msg/app-pingpong/app-pi
                          @CMAKE_HOME_DIRECTORY@/examples/msg/app-masterworker/app-masterworker.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/process-migration/process-migration.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/process-suspend/process-suspend.c \
+                         @CMAKE_HOME_DIRECTORY@/examples/msg/task-priority/task-priority.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/properties \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/parallel_task \
-                         @CMAKE_HOME_DIRECTORY@/examples/msg/priority \
-                         @CMAKE_HOME_DIRECTORY@/examples/msg/icomms/peer.c \
+                         @CMAKE_HOME_DIRECTORY@/examples/msg/async-wait/async-wait.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/icomms/peer2.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/icomms/peer3.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/tracing/simple.c \
index dbe02f3..88bda8e 100644 (file)
@@ -158,9 +158,9 @@ Check the examples in <b>examples/msg/actions/actions.c</b> for details.
 /**
 @defgroup MSG_examples MSG examples
 @ingroup MSG_API
-@brief MSG examples from examples directory examples/msg
+@brief .
 
-MSG comes with an extensive set of examples. It is sometimes difficult to find the one you need. This list aims at helping you finding the example from which you can learn what you want to.
+Finding the right example in examples/msg is sometimes difficult. This list aims at helping you to find the example from which you can learn what you want to.
 
 \section msg_bsc_ex Basic examples
 
index e9d26e5..8780b23 100644 (file)
@@ -6,41 +6,41 @@
 
 #include "simgrid/msg.h"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_app_masterworker, "Messages specific for this msg example");
 
 /** @addtogroup MSG_examples
  *
- *  - <b>app-masterworker/app-masterworker.c: Master/workers example</b>. This good old example is also very simple. Its
+ *  - <b>Master/Workers: app-masterworker/app-masterworker.c</b>. This good old example is also very simple. Its
  *    basic version is fully commented on this page: \ref MSG_ex_master_worker.
  */
 
+/** @brief Master expects 4 arguments given in the XML deployment file: */
 static int master(int argc, char *argv[])
 {
-  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");
-  long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");    /** - Number of tasks      */
+  double comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");  /** - Task compute cost    */
+  double comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");  /** - Task communication size */
+  long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");    /** - Number of workers    */
 
   int i;
 
   XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks);
 
-  for (i = 0; i < number_of_tasks; i++) {
+  for (i = 0; i < number_of_tasks; i++) {  /** For each task to be executed: */
     char mailbox[256];
-    char sprintf_buffer[256];
-    msg_task_t task = NULL;
+    char task_name[256];
 
-    sprintf(mailbox, "worker-%ld", i % workers_count);
-    sprintf(sprintf_buffer, "Task_%d", i);
-    task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
+    sprintf(mailbox, "worker-%ld", i % workers_count); /** - Select a @ref worker in a round-robin way */
+    sprintf(task_name, "Task_%d", i);
+    msg_task_t task = MSG_task_create(task_name, comp_size, comm_size, NULL);   /** - Create a task */
     if (number_of_tasks < 10000 || i % 10000 == 0)
       XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox);
 
-    MSG_task_send(task, mailbox);
+    MSG_task_send(task, mailbox); /** - Send the task to the @ref worker */
   }
 
   XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
-  for (i = 0; i < workers_count; i++) {
+  for (i = 0; i < workers_count; i++) { /** - Eventually tell all the workers to stop by sending a "finalize" task */
     char mailbox[80];
 
     sprintf(mailbox, "worker-%ld", i % workers_count);
@@ -51,6 +51,7 @@ static int master(int argc, char *argv[])
   return 0;
 }
 
+/** @brief Worker expects a single argument given in the XML deployment file: */
 static int worker(int argc, char *argv[])
 {
   msg_task_t task = NULL;
@@ -58,19 +59,19 @@ static int worker(int argc, char *argv[])
 
   long id= xbt_str_parse_int(argv[1], "Invalid argument %s");
 
-  sprintf(mailbox, "worker-%ld", id);
+  sprintf(mailbox, "worker-%ld", id); /** - unique id of the worker */
 
-  while (1) {
+  while (1) {  /** The worker wait in an infinite loop for tasks sent by the \ref master */
     int res = MSG_task_receive(&(task), mailbox);
     xbt_assert(res == MSG_OK, "MSG_task_get failed");
 
 //  XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
     if (!strcmp(MSG_task_get_name(task), "finalize")) {
-      MSG_task_destroy(task);
+      MSG_task_destroy(task);  /** - Exit if 'finalize' is received */
       break;
     }
 //    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
-    MSG_task_execute(task);
+    MSG_task_execute(task);    /**  - Otherwise, process the task */
 //    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
     MSG_task_destroy(task);
     task = NULL;
@@ -85,13 +86,13 @@ int main(int argc, char *argv[])
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
 
-  MSG_create_environment(argv[1]);
+  MSG_create_environment(argv[1]);          /** - Load the platform description */
 
-  MSG_function_register("master", master);
+  MSG_function_register("master", master);  /** - Register the function to be executed by the processes */
   MSG_function_register("worker", worker);
-  MSG_launch_application(argv[2]);
+  MSG_launch_application(argv[2]);          /** - Deploy the application */
 
-  msg_error_t res = MSG_main();
+  msg_error_t res = MSG_main();             /** - Run the simulation */
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
 
index 3b6a9cb..59b3b74 100644 (file)
@@ -8,11 +8,11 @@
 
 /** @addtogroup MSG_examples
  *
- *  - <b>Ping-pong example: app-pingpong/app-pingpong.c </b>. It's hard to think of a simpler example. The tesh file
+ *  - <b>Ping-Pong: app-pingpong/app-pingpong.c </b>. It's hard to think of a simpler example. The tesh file
  *    laying in the directory is instructive concerning the way to pass options to the simulators (see \ref options).
  */
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(pingpong,"Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(mag_app_pingpong,"Messages specific for this msg example");
 
 static int pinger(int argc, char *argv[])
 {
index 8cf192b..fcd2b18 100644 (file)
@@ -7,38 +7,37 @@
 #include "simgrid/msg.h"
 #include "xbt/synchro_core.h"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_migration, "Messages specific for this msg example");
 
 /** @addtogroup MSG_examples
- *  
- *  - <b>process-migration/process-migration.c: Process migration example</b>. Demonstrates how to use the
- *    @ref MSG_process_migrate function to let processes change the host they run on after their start.
+ *
+ *  - <b>Process migration: process-migration/process-migration.c</b>. Processes can move or be moved from a host to
+ *    another  while they are running thanks to the @ref MSG_process_migrate function.
  */
 
-xbt_mutex_t mutex = NULL;
-xbt_cond_t cond = NULL;
-static msg_process_t process_to_migrate = NULL;
+xbt_mutex_t checkpoint = NULL;
+xbt_cond_t identification = NULL;
+static msg_process_t controlled_process = NULL;
 
-/** The guy we will move from host to host. It move alone and then is moved by policeman back  */
+/** The Emigrant will be moved from host to host. */
 static int emigrant(int argc, char *argv[])
 {
-  msg_task_t task;
-  XBT_INFO("I'll look for a new job on another machine where the grass is greener.");
-  MSG_process_migrate(MSG_process_self(), MSG_host_by_name("Boivin"));
+  XBT_INFO("I'll look for a new job on another machine ('Boivin') where the grass is greener.");
+  MSG_process_migrate(MSG_process_self(), MSG_host_by_name("Boivin"));    /** - First, move to another host by myself */
 
   XBT_INFO("Yeah, found something to do");
-  task = MSG_task_create("job", 98095000, 0, NULL);
+  msg_task_t task = MSG_task_create("job", 98095000, 0, NULL);            /** - Execute some work there */
   MSG_task_execute(task);
   MSG_task_destroy(task);
   MSG_process_sleep(2);
   XBT_INFO("Moving back home after work");
-  MSG_process_migrate(MSG_process_self(), MSG_host_by_name("Jacquelin"));
-  MSG_process_migrate(MSG_process_self(), MSG_host_by_name("Boivin"));
+  MSG_process_migrate(MSG_process_self(), MSG_host_by_name("Jacquelin")); /** - Move back to original location */
+  MSG_process_migrate(MSG_process_self(), MSG_host_by_name("Boivin"));    /** - Go back to the other host to sleep*/
   MSG_process_sleep(4);
-  xbt_mutex_acquire(mutex);
-  process_to_migrate = MSG_process_self();
-  xbt_cond_broadcast(cond);
-  xbt_mutex_release(mutex);
+  xbt_mutex_acquire(checkpoint);                                          /** - Get controlled at checkpoint */
+  controlled_process = MSG_process_self();                                /** - and get moved back by @ref policeman */
+  xbt_cond_broadcast(identification);
+  xbt_mutex_release(checkpoint);
   MSG_process_suspend(MSG_process_self());
   msg_host_t h = MSG_process_get_host(MSG_process_self());
   XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h));
@@ -46,16 +45,16 @@ static int emigrant(int argc, char *argv[])
   return 0;
 }
 
-/* This function move the emigrant on Jacquelin */
+/** The policeman check for emigrants and move them back to 'Jacquelin' */
 static int policeman(int argc, char *argv[])
 {
-  xbt_mutex_acquire(mutex);
-  XBT_INFO("Wait a bit before migrating the emigrant.");
-  while (process_to_migrate == NULL) xbt_cond_wait(cond, mutex);
-  MSG_process_migrate(process_to_migrate, MSG_host_by_name("Jacquelin"));
+  xbt_mutex_acquire(checkpoint);
+  XBT_INFO("Wait at the checkpoint.");  /** - Wait at @ref checkpoint to control the @ref identification of processes */
+  while (controlled_process == NULL) xbt_cond_wait(identification, checkpoint);
+  MSG_process_migrate(controlled_process, MSG_host_by_name("Jacquelin")); /** - Move an emigrant to Jacquelin */
   XBT_INFO("I moved the emigrant");
-  MSG_process_resume(process_to_migrate);
-  xbt_mutex_release(mutex);
+  MSG_process_resume(controlled_process);
+  xbt_mutex_release(checkpoint);
 
   return 0;
 }
@@ -67,17 +66,17 @@ int main(int argc, char *argv[])
   MSG_init(&argc, argv);
   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
 
-  MSG_create_environment(argv[1]);
-
+  MSG_create_environment(argv[1]);  /** - Load the platform description */
+  /** - Create and deploy @ref emigrant and @ref policeman processes */
   MSG_process_create("emigrant", emigrant, NULL, MSG_get_host_by_name("Jacquelin"));
   MSG_process_create("policeman", policeman, NULL, MSG_get_host_by_name("Boivin"));
 
-  mutex = xbt_mutex_init();
-  cond = xbt_cond_init();
-  res = MSG_main();
+  checkpoint = xbt_mutex_init();     /** - Initiate @ref checkpoint and @ref identification*/
+  identification = xbt_cond_init();
+  res = MSG_main();                  /** - Run the simulation */
   XBT_INFO("Simulation time %g", MSG_get_clock());
-  xbt_cond_destroy(cond);
-  xbt_mutex_destroy(mutex);
+  xbt_cond_destroy(identification);
+  xbt_mutex_destroy(checkpoint);
 
   return res != MSG_OK;
 }
index 2c2ed7c..5f1afdf 100644 (file)
@@ -4,9 +4,9 @@ p Testing the migration feature of MSG
 
 ! output sort 19
 $ $SG_TEST_EXENV ${bindir:=.}/process-migration ${srcdir:=.}/platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (1:emigrant@Jacquelin) I'll look for a new job on another machine where the grass is greener.
+> [  0.000000] (1:emigrant@Jacquelin) I'll look for a new job on another machine ('Boivin') where the grass is greener.
 > [  0.000000] (1:emigrant@Boivin) Yeah, found something to do
-> [  0.000000] (2:policeman@Boivin) Wait a bit before migrating the emigrant.
+> [  0.000000] (2:policeman@Boivin) Wait at the checkpoint.
 > [  3.000000] (1:emigrant@Boivin) Moving back home after work
 > [  7.000000] (0:maestro@) Simulation time 7
 > [  7.000000] (1:emigrant@Jacquelin) I've been moved on this new host: Jacquelin