From 54003ca6d54f59d8ecb8aee18f96a21321fc8a84 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sun, 10 Apr 2016 15:24:27 +0200 Subject: [PATCH] one step further in documenting MSG examples --- doc/Doxyfile.in | 12 ++--- examples/msg/app-pmm/app-pmm.c | 3 +- examples/msg/app-token-ring/app-token-ring.c | 48 +++++++++---------- .../msg/process-migration/process-migration.c | 2 +- .../msg/process-suspend/process-suspend.c | 37 +++++++------- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index b008e72c3b..6399984d59 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -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 diff --git a/examples/msg/app-pmm/app-pmm.c b/examples/msg/app-pmm/app-pmm.c index 5d4f6629ef..486584bd34 100644 --- a/examples/msg/app-pmm/app-pmm.c +++ b/examples/msg/app-pmm/app-pmm.c @@ -11,7 +11,8 @@ #include "xbt/xbt_os_time.h" /** @addtogroup MSG_examples - * + * @section MSG_ex_apps Examples of full applications + * * - pmm/msg_pmm.c: 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. */ diff --git a/examples/msg/app-token-ring/app-token-ring.c b/examples/msg/app-token-ring/app-token-ring.c index 4dc5d71b6a..b73ad927e6 100644 --- a/examples/msg/app-token-ring/app-token-ring.c +++ b/examples/msg/app-token-ring/app-token-ring.c @@ -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 - * - * - token_ring/ring_call.c: Classical token ring communication, where a token is exchanged along a ring to - * reach every participant. + * - Token Ring: app-token-ring/app-token-ring.c: 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; } diff --git a/examples/msg/process-migration/process-migration.c b/examples/msg/process-migration/process-migration.c index fcd2b185e8..7728ac9b97 100644 --- a/examples/msg/process-migration/process-migration.c +++ b/examples/msg/process-migration/process-migration.c @@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_migration, "Messages specific for this /** @addtogroup MSG_examples * - * - Process migration: process-migration/process-migration.c. Processes can move or be moved from a host to + * - Process Migration: process-migration/process-migration.c. Processes can move or be moved from a host to * another while they are running thanks to the @ref MSG_process_migrate function. */ diff --git a/examples/msg/process-suspend/process-suspend.c b/examples/msg/process-suspend/process-suspend.c index b7fc14a1bb..3f602810be 100644 --- a/examples/msg/process-suspend/process-suspend.c +++ b/examples/msg/process-suspend/process-suspend.c @@ -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 * - * - process-suspend/process-suspend.c: Process Suspend/Resume example. Demonstrates how to suspend and resume - * processes using the @ref MSG_process_suspend and @ref MSG_process_resume functions. + * - Process Suspend/Resume: process-suspend/process-suspend.c. 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; -- 2.20.1