From: Martin Quinson Date: Mon, 22 Aug 2016 21:26:16 +0000 (+0200) Subject: Cosmetics in the MSG version of app-token-ring X-Git-Tag: v3_14~508 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/38b7388c9f6ec1463d9cb2dabab9bb451ba8cc46 Cosmetics in the MSG version of app-token-ring --- diff --git a/examples/msg/app-token-ring/app-token-ring.c b/examples/msg/app-token-ring/app-token-ring.c index 858889e986..2ab30e693c 100644 --- a/examples/msg/app-token-ring/app-token-ring.c +++ b/examples/msg/app-token-ring/app-token-ring.c @@ -8,29 +8,33 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_app_token_ring, "Messages specific for this msg example"); /* Main function of all processes used in this example */ -static int foo(int argc, char *argv[]) +static int relay_runner(int argc, char *argv[]) { unsigned int task_comm_size = 1000000; /* The token is 1MB long*/ int rank = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Any process of this example must have a numerical name, not %s"); char mailbox[256]; - msg_task_t task = NULL; - XBT_ATTRIB_UNUSED int res; - if (rank == 0){ /* - The root (rank 0) first sends the token then waits to receive it back */ + + if (rank == 0) { + /* The root process (rank 0) first sends the token then waits to receive it back */ snprintf(mailbox,255, "%d", rank+1); - task = MSG_task_create("Token", 0, task_comm_size, NULL); + msg_task_t 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())); + int 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\"", rank, MSG_task_get_name(task)); MSG_task_destroy(task); - } 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())); + + } else { + /* The others processes receive from their left neighbor (rank-1) and send to their right neighbor (rank+1) */ + msg_task_t task = NULL; + int 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\"",rank, MSG_task_get_name(task)); - if(rank+1 == MSG_get_host_number()) /* - Except for the last one which sends the token back to rank 0 */ + if (rank+1 == MSG_get_host_number()) + /* But the last process, which sends the token back to rank 0 */ snprintf(mailbox,255, "0"); else snprintf(mailbox,255, "%d", rank+1); @@ -48,10 +52,10 @@ int main(int argc, char *argv[]) xbt_dynar_t hosts = MSG_hosts_as_dynar(); msg_host_t h; - XBT_INFO("Number of host '%d'",MSG_get_host_number()); - xbt_dynar_foreach (hosts, i, h){ /* - Give a unique rank to each host and create a @ref foo process on each */ + XBT_INFO("Number of hosts '%d'",MSG_get_host_number()); + xbt_dynar_foreach (hosts, i, h){ /* - Give a unique rank to each host and create a @ref relay_runner process on each */ char* name_host = bprintf("%u",i); - MSG_process_create(name_host, foo, NULL, h); + MSG_process_create(name_host, relay_runner, NULL, h); free(name_host); } xbt_dynar_free(&hosts); diff --git a/examples/msg/app-token-ring/app-token-ring.tesh b/examples/msg/app-token-ring/app-token-ring.tesh index 086637ce07..c513222c22 100644 --- a/examples/msg/app-token-ring/app-token-ring.tesh +++ b/examples/msg/app-token-ring/app-token-ring.tesh @@ -1,7 +1,7 @@ #! ./tesh $ $SG_TEST_EXENV ${bindir:=.}/app-token-ring ${srcdir:=.}/routing_cluster.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (0:maestro@) Number of host '6' +> [ 0.000000] (0:maestro@) Number of hosts '6' > [ 0.000000] (1:0@host1) Host "0" send 'Token' to Host "1" > [ 0.017354] (2:1@host2) Host "1" received "Token" > [ 0.017354] (2:1@host2) Host "1" send 'Token' to Host "2" @@ -18,7 +18,7 @@ $ $SG_TEST_EXENV ${bindir:=.}/app-token-ring ${srcdir:=.}/routing_cluster.xml "- $ $SG_TEST_EXENV ${bindir:=.}/app-token-ring ${srcdir:=.}/two_peers.xml --cfg=network/coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Configuration change: Set 'network/coordinates' to 'yes' -> [ 0.000000] (0:maestro@) Number of host '2' +> [ 0.000000] (0:maestro@) Number of hosts '2' > [ 0.000000] (1:0@peer_100030591) Host "0" send 'Token' to Host "1" > [ 0.637910] (2:1@peer_100036570) Host "1" received "Token" > [ 0.637910] (2:1@peer_100036570) Host "1" send 'Token' to Host "0" @@ -26,7 +26,7 @@ $ $SG_TEST_EXENV ${bindir:=.}/app-token-ring ${srcdir:=.}/two_peers.xml --cfg=ne > [ 1.275820] (0:maestro@) Simulation time 1.27582 $ $SG_TEST_EXENV ${bindir:=.}/app-token-ring ${srcdir:=.}/meta_cluster.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (0:maestro@) Number of host '60' +> [ 0.000000] (0:maestro@) Number of hosts '60' > [ 0.000000] (1:0@host-2.cluster1) Host "0" send 'Token' to Host "1" > [ 0.030364] (2:1@host-2.cluster2) Host "1" received "Token" > [ 0.030364] (2:1@host-2.cluster2) Host "1" send 'Token' to Host "2" diff --git a/teshsuite/lua/lua_platforms.tesh b/teshsuite/lua/lua_platforms.tesh index 03dd4cd1fa..17e7aecdb0 100644 --- a/teshsuite/lua/lua_platforms.tesh +++ b/teshsuite/lua/lua_platforms.tesh @@ -29,7 +29,7 @@ $ ${bindir:=.}/../../examples/msg/app-masterworker/app-masterworker ${srcdir:=.} > [5.133855] [msg_app_masterworker/INFO] Simulation time 5.13386 $ $SG_TEST_EXENV ${bindir:=.}/../../examples/msg/app-token-ring/app-token-ring ${srcdir:=.}/../../examples/platforms/routing_cluster.lua "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (0:maestro@) Number of host '6' +> [ 0.000000] (0:maestro@) Number of hosts '6' > [ 0.000000] (1:0@host1) Host "0" send 'Token' to Host "1" > [ 0.017354] (2:1@host2) Host "1" received "Token" > [ 0.017354] (2:1@host2) Host "1" send 'Token' to Host "2"