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);
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);
#! ./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"
$ $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"
> [ 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"