Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
one step further in documenting MSG examples
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 10 Apr 2016 13:24:27 +0000 (15:24 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 10 Apr 2016 13:32:09 +0000 (15:32 +0200)
doc/Doxyfile.in
examples/msg/app-pmm/app-pmm.c
examples/msg/app-token-ring/app-token-ring.c
examples/msg/process-migration/process-migration.c
examples/msg/process-suspend/process-suspend.c

index b008e72..6399984 100644 (file)
@@ -696,16 +696,17 @@ INPUT                  = doxygen/index.doc \
 ###################################################
 
 INPUT +=                 @CMAKE_HOME_DIRECTORY@/examples/msg/app-pingpong/app-pingpong.c \
+                         @CMAKE_HOME_DIRECTORY@/examples/msg/app-token-ring/app-token-ring.c \
                          @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/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/process-suspend/process-suspend.c \
+                         @CMAKE_HOME_DIRECTORY@/examples/msg/process-migration/process-migration.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/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 \
+                         @CMAKE_HOME_DIRECTORY@/examples/msg/trace-simple/trace-simple.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/tracing/ms.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/tracing/categories.c \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/tracing/procmig.c \
@@ -717,7 +718,6 @@ INPUT +=                 @CMAKE_HOME_DIRECTORY@/examples/msg/app-pingpong/app-pi
                          @CMAKE_HOME_DIRECTORY@/examples/msg/io \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/gpu \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/actions \
-                         @CMAKE_HOME_DIRECTORY@/examples/msg/token_ring \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/pmm \
                          @CMAKE_HOME_DIRECTORY@/examples/msg/chord
 
index 5d4f662..486584b 100644 (file)
@@ -11,7 +11,8 @@
 #include "xbt/xbt_os_time.h"
 
 /** @addtogroup MSG_examples
- * 
+ *  @section MSG_ex_apps Examples of full applications
+ *
  * - <b>pmm/msg_pmm.c</b>: Parallel Matrix Multiplication is a little application. This is something that most MPI
  *   developers have written during their class, here implemented using MSG instead of MPI.
  */
index 4dc5d71..b73ad92 100644 (file)
@@ -10,64 +10,62 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(ring, "Messages specific for this msg example");
 
 /** @addtogroup MSG_examples
  * 
- *  @section MSG_ex_apps Examples of full applications
- * 
- * - <b>token_ring/ring_call.c</b>: Classical token ring communication, where a token is exchanged along a ring to
- *   reach every participant.
+ * - <b>Token Ring: app-token-ring/app-token-ring.c</b>: Classical token ring communication, where a token is exchanged
+ *   along a ring to reach every participant. The tesh file laying in the directory shows how to run the same example on
+ *   different platforms.
  */
 
-static int host(int argc, char *argv[])
+/** Single function for all hosts */
+static int foo(int argc, char *argv[])
 {
-  unsigned int task_comp_size = 50000000;
-  unsigned int task_comm_size = 1000000;
-  int host_number =
-          xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Process name must be an integer but is: %s");
+  unsigned int task_comm_size = 1000000; /** The token is 1MB long*/
+  int rank = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Invalid process name: %s");
   char mailbox[256];
   msg_task_t task = NULL;
   XBT_ATTRIB_UNUSED int res;
-  if (host_number == 0){ //root: send then receive
-    sprintf(mailbox, "%d", host_number+1);
-    task = MSG_task_create("Token", task_comp_size, task_comm_size, NULL);
-    XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
+  if (rank == 0){ /** - The root (rank 0) first sends the token then waits to receive it back */
+    sprintf(mailbox, "%d", rank+1);
+    task = MSG_task_create("Token", 0, task_comm_size, NULL);
+    XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name,mailbox);
     MSG_task_send(task, mailbox);
     task = NULL;
     res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
     xbt_assert(res == MSG_OK, "MSG_task_get failed");
-    XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
+    XBT_INFO("Host \"%d\" received \"%s\"", rank, MSG_task_get_name(task));
     MSG_task_destroy(task);
-  } else{ // receive then send
+  } else{ /** - The others receive from their left neighbor (rank-1) and send to their right neighbor (rank+1) */
     res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
     xbt_assert(res == MSG_OK, "MSG_task_get failed");
-    XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
+    XBT_INFO("Host \"%d\" received \"%s\"",rank, MSG_task_get_name(task));
 
-    if(host_number+1 == MSG_get_host_number())
+    if(rank+1 == MSG_get_host_number()) /** - Except for the last one which sends the token back to rank 0 */
       sprintf(mailbox, "0");
     else
-      sprintf(mailbox, "%d", host_number+1);
-    XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
+      sprintf(mailbox, "%d", rank+1);
+    XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",rank,task->name,mailbox);
     MSG_task_send(task, mailbox);
   }
   return 0;
 }
 
-int main(int argc, char **argv)
+int main(int argc, char *argv[])
 {
   unsigned int i;
   MSG_init(&argc, argv);
-  MSG_create_environment(argv[1]);
+  MSG_create_environment(argv[1]);       /** - Load the platform description */
   xbt_dynar_t hosts = MSG_hosts_as_dynar();
   msg_host_t h;
-  MSG_function_register("host", host);
+  MSG_function_register("foo", foo);
 
   XBT_INFO("Number of host '%d'",MSG_get_host_number());
-  xbt_dynar_foreach (hosts, i, h){
+  xbt_dynar_foreach (hosts, i, h){      /** - Give a unique rank to each host and create a @ref foo process on each */
     char* name_host = bprintf("%u",i);
-    MSG_process_create(name_host, host, NULL, h);
+    MSG_process_create(name_host, foo, NULL, h);
     free(name_host);
   }
   xbt_dynar_free(&hosts);
 
-  int res = MSG_main();
+  int res = MSG_main();                 /** - Run the simulation */
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return res != MSG_OK;
 }
index fcd2b18..7728ac9 100644 (file)
@@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_migration, "Messages specific for this
 
 /** @addtogroup MSG_examples
  *
- *  - <b>Process migration: process-migration/process-migration.c</b>. Processes can move or be moved from a host to
+ *  - <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.
  */
 
index b7fc14a..3f60281 100644 (file)
@@ -6,26 +6,27 @@
 
 #include "simgrid/msg.h"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_suspend, "Messages specific for this msg example");
 
 #define SLEEP(duration)                                 \
   if (MSG_process_sleep(duration) != MSG_OK)            \
     xbt_die("What's going on??? I failed to sleep!");
 
 /** @addtogroup MSG_examples
+ *  @section MSG_ex_process Acting on Processes
  * 
- * - <b>process-suspend/process-suspend.c: Process Suspend/Resume example</b>. Demonstrates how to suspend and resume
- *   processes using the @ref MSG_process_suspend and @ref MSG_process_resume functions.
+ * - <b>Process Suspend/Resume: process-suspend/process-suspend.c</b>. Processes can be suspended and resumed during
+ *   their executions thanks to the @ref MSG_process_suspend and @ref MSG_process_resume functions.
  */
 
-/** Lazy guy function. This process suspends itself asap.  */
+/** The Lazy guy only wants to sleep, but can be awaken by the @ref dream_master. */
 static int lazy_guy(int argc, char *argv[])
 {
   XBT_INFO("Nobody's watching me ? Let's go to sleep.");
-  MSG_process_suspend(MSG_process_self());
+  MSG_process_suspend(MSG_process_self());       /** - Start by suspending itself */
   XBT_INFO("Uuuh ? Did somebody call me ?");
 
-  XBT_INFO("Going to sleep...");
+  XBT_INFO("Going to sleep...");                 /** - Then repetitively go to sleep, but got awaken */
   SLEEP(10.0);
   XBT_INFO("Mmm... waking up.");
 
@@ -37,25 +38,25 @@ static int lazy_guy(int argc, char *argv[])
   return 0;
 }
 
-/** Dream master function. This process creates a lazy_guy process and resumes it 10 seconds later. */
+/** The Dream master: */
 static int dream_master(int argc, char *argv[])
 {
   msg_process_t lazy = NULL;
 
-  XBT_INFO("Let's create a lazy guy.");
+  XBT_INFO("Let's create a lazy guy."); /** - Create a @ref lazy_guy process */
   lazy = MSG_process_create("Lazy", lazy_guy, NULL, MSG_host_self());
   XBT_INFO("Let's wait a little bit...");
-  SLEEP(10.0);
+  SLEEP(10.0);                          /** - Wait for 10 seconds */
   XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
-  MSG_process_resume(lazy);
+  MSG_process_resume(lazy);             /** - Then wake up the @ref lazy_guy */
 
-  SLEEP(5.0);
+  SLEEP(5.0);                           /** Repeat two times: */
   XBT_INFO("Suspend the lazy guy while he's sleeping...");
-  MSG_process_suspend(lazy);
+  MSG_process_suspend(lazy);            /** - Suspend the @ref lazy_guy while he's asleep */
   XBT_INFO("Let him finish his siesta.");
-  SLEEP(10.0);
+  SLEEP(10.0);                          /** - Wait for 10 seconds */
   XBT_INFO("Wake up, lazy guy!");
-  MSG_process_resume(lazy);
+  MSG_process_resume(lazy);             /** - Then wake up the @ref lazy_guy again */
 
   SLEEP(5.0);
   XBT_INFO("Suspend again the lazy guy while he's sleeping...");
@@ -67,7 +68,7 @@ static int dream_master(int argc, char *argv[])
 
   XBT_INFO("OK, goodbye now.");
   return 0;
-}                               /* end_of_dream_master */
+}
 
 int main(int argc, char *argv[])
 {
@@ -76,12 +77,12 @@ int main(int argc, char *argv[])
   MSG_init(&argc, argv);
   xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
 
-  MSG_create_environment(argv[1]);
-  MSG_function_register("dream_master", dream_master);
+  MSG_create_environment(argv[1]);  /** - Load the platform description */
+  MSG_function_register("dream_master", dream_master); /** - Create and deploy the @ref dream_master */
   xbt_dynar_t hosts = MSG_hosts_as_dynar();
   MSG_process_create("dream_master", dream_master, NULL, xbt_dynar_getfirst_as(hosts, msg_host_t));
   xbt_dynar_free(&hosts);
-  res = MSG_main();
+  res = MSG_main();                 /** - Run the simulation */
 
   XBT_INFO("Simulation time %g", MSG_get_clock());
   return res != MSG_OK;