A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Cosmetics in the MSG version of app-token-ring
[simgrid.git]
/
examples
/
msg
/
app-token-ring
/
app-token-ring.c
diff --git
a/examples/msg/app-token-ring/app-token-ring.c
b/examples/msg/app-token-ring/app-token-ring.c
index
858889e
..
2ab30e6
100644
(file)
--- 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 */
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];
{
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);
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;
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);
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));
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);
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_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 host
s
'%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);
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);
free(name_host);
}
xbt_dynar_free(&hosts);