From e542387cf6c22f2cf646faede87320040dbaa884 Mon Sep 17 00:00:00 2001 From: Navarrop Date: Tue, 6 Dec 2011 12:51:52 +0100 Subject: [PATCH] Rewrite the token ring example --- examples/msg/token_ring/ring_call.c | 169 +++++++----------------- examples/msg/token_ring/token_ring.tesh | 56 ++++---- 2 files changed, 74 insertions(+), 151 deletions(-) diff --git a/examples/msg/token_ring/ring_call.c b/examples/msg/token_ring/ring_call.c index 305945b37c..8cdf4e9d3a 100644 --- a/examples/msg/token_ring/ring_call.c +++ b/examples/msg/token_ring/ring_call.c @@ -9,124 +9,45 @@ #include "msg/msg.h" #include "surf/surf_private.h" -extern routing_global_t global_routing; -int totalHosts= 0; -const m_host_t *hosts; - -int master(int argc, char *argv[]); -int slave(int argc, char *argv[]); +int host(int argc, char *argv[]); +unsigned int task_comp_size = 50000000; +unsigned int task_comm_size = 1000000; +int number_of_hosts; XBT_LOG_NEW_DEFAULT_CATEGORY(ring, "Messages specific for this msg example"); -int master(int argc, char *argv[]) -{ - m_task_t task_s = NULL; - m_task_t task_r = NULL; - unsigned int task_comp_size = 50000000; - unsigned int task_comm_size = 1000000; - char mailbox[80]; - char buffer[20]; - int num = atoi(argv[1]); - - sprintf(mailbox, "host%d", num+1); - if(num == totalHosts-1) - sprintf(mailbox, "host%d", 0); - sprintf(buffer, "Token"); - - task_s = MSG_task_create(buffer, - task_comp_size, - task_comm_size, - NULL); - MSG_task_send(task_s,mailbox); - XBT_INFO("Send Data to \"%s\"", mailbox); - - sprintf(mailbox, "host%d", num); - MSG_task_receive(&(task_r), mailbox); - XBT_INFO("Received \"%s\"", MSG_task_get_name(task_r)); - return 0; -} - -int slave(int argc, char *argv[]) -{ - m_task_t task_s = NULL; - m_task_t task_r = NULL; - unsigned int task_comp_size = 50000000; - unsigned int task_comm_size = 1000000; - char mailbox[80]; - char buffer[20]; - int num = atoi(argv[1]); - - sprintf(mailbox, "host%d", num); - MSG_task_receive(&(task_r), mailbox); - XBT_INFO("Received \"%s\"", MSG_task_get_name(task_r)); - sprintf(mailbox, "host%d", num+1); - if(num == totalHosts-1) - sprintf(mailbox, "host%d", 0); - sprintf(buffer, "Token"); - task_s = MSG_task_create(buffer, - task_comp_size, - task_comm_size, - NULL); - MSG_task_send(task_s, mailbox); - XBT_INFO("Send Data to \"%s\"", mailbox); - - return 0; -} - -static int surf_parse_bypass_application(void) +int host(int argc, char *argv[]) { - int i; - static int AX_ptr; - static int surfxml_bufferstack_size = 2048; - static int surfxml_buffer_stack_stack_ptr = 0; - static int surfxml_buffer_stack_stack[1024]; - /* allocating memory to the buffer, I think 2MB should be enough */ - surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size); - - totalHosts = MSG_get_host_number(); - hosts = MSG_get_host_table(); - - /* */ - SURFXML_BUFFER_SET(platform_version, "3"); - - SURFXML_START_TAG(platform); - - XBT_DEBUG("process : %s en master",MSG_host_get_name(hosts[0])); - /* */ - SURFXML_BUFFER_SET(process_host, MSG_host_get_name(hosts[0])); - SURFXML_BUFFER_SET(process_function, "master"); - SURFXML_BUFFER_SET(process_start_time, "-1.0"); - SURFXML_BUFFER_SET(process_kill_time, "-1.0"); - SURFXML_START_TAG(process); - - /* */ - SURFXML_BUFFER_SET(argument_value, "0"); - SURFXML_START_TAG(argument); - SURFXML_END_TAG(argument); - SURFXML_END_TAG(process); - - for(i=1;i */ - SURFXML_BUFFER_SET(process_host,MSG_host_get_name(hosts[i]) ); - SURFXML_BUFFER_SET(process_function, "slave"); - SURFXML_BUFFER_SET(process_start_time, "-1.0"); - SURFXML_BUFFER_SET(process_kill_time, "-1.0"); - SURFXML_START_TAG(process); - - /* */ - SURFXML_BUFFER_SET(argument_value, bprintf("%d",i)); - SURFXML_START_TAG(argument); - SURFXML_END_TAG(argument); - SURFXML_END_TAG(process); - } - /* */ - SURFXML_END_TAG(platform); - - free(surfxml_bufferstack); - return 0; + int host_number = atoi(MSG_process_get_name(MSG_process_self())); + char mailbox[256]; + m_task_t task = NULL; + _XBT_GNUC_UNUSED int res; + + if (host_number == 0){ //master 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); + 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)); + MSG_task_destroy(task); + } + else{ //slave receive then send + 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)); + + if(host_number+1 == number_of_hosts ) + sprintf(mailbox, "0"); + else + sprintf(mailbox, "%d", host_number+1); + XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox); + MSG_task_send(task, mailbox); + } + return 0; } typedef enum { @@ -136,22 +57,26 @@ typedef enum { int main(int argc, char **argv) { - int res; + int i,res; MSG_global_init(&argc, argv); MSG_set_channel_number(MAX_CHANNEL); MSG_create_environment(argv[1]); - - MSG_function_register("master", master); - MSG_function_register("slave", slave); - surf_parse = surf_parse_bypass_application; - MSG_launch_application(NULL); + m_host_t *host_table = MSG_get_host_table(); + number_of_hosts = MSG_get_host_number(); + MSG_function_register("host", host); + + XBT_INFO("Number of host '%d'",number_of_hosts); + for(i = 0 ; i [ 0.000000] (0:@) Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code. -> [ 0.066240] (1:master@bob1.hamburger.edu) Send Data to "host1" -> [ 0.066240] (2:slave@bob3.hamburger.edu) Received "Token" -> [ 0.242880] (2:slave@bob3.hamburger.edu) Send Data to "host2" -> [ 0.242880] (3:slave@alice2.crepe.fr) Received "Token" -> [ 0.309120] (3:slave@alice2.crepe.fr) Send Data to "host3" -> [ 0.309120] (4:slave@alice3.crepe.fr) Received "Token" -> [ 0.485760] (4:slave@alice3.crepe.fr) Send Data to "host4" -> [ 0.485760] (5:slave@bob0.hamburger.edu) Received "Token" -> [ 0.552000] (5:slave@bob0.hamburger.edu) Send Data to "host5" -> [ 0.552000] (6:slave@bob2.hamburger.edu) Received "Token" -> [ 0.618240] (6:slave@bob2.hamburger.edu) Send Data to "host6" -> [ 0.618240] (7:slave@bob4.hamburger.edu) Received "Token" -> [ 0.794880] (7:slave@bob4.hamburger.edu) Send Data to "host7" -> [ 0.794880] (8:slave@alice0.crepe.fr) Received "Token" -> [ 0.861120] (8:slave@alice0.crepe.fr) Send Data to "host8" -> [ 0.861120] (9:slave@alice4.crepe.fr) Received "Token" -> [ 0.927360] (10:slave@alice1.crepe.fr) Received "Token" -> [ 0.927360] (9:slave@alice4.crepe.fr) Send Data to "host9" +> [ 0.000000] (0:@) Number of host '10' +> [ 0.000000] (1:0@bob1.hamburger.edu) Host "0" send 'Token' to Host "1" +> [ 0.066240] (2:1@bob3.hamburger.edu) Host "1" received "Token" +> [ 0.066240] (2:1@bob3.hamburger.edu) Host "1" send 'Token' to Host "2" +> [ 0.242880] (3:2@alice2.crepe.fr) Host "2" received "Token" +> [ 0.242880] (3:2@alice2.crepe.fr) Host "2" send 'Token' to Host "3" +> [ 0.309120] (4:3@alice3.crepe.fr) Host "3" received "Token" +> [ 0.309120] (4:3@alice3.crepe.fr) Host "3" send 'Token' to Host "4" +> [ 0.485760] (5:4@bob0.hamburger.edu) Host "4" received "Token" +> [ 0.485760] (5:4@bob0.hamburger.edu) Host "4" send 'Token' to Host "5" +> [ 0.552000] (6:5@bob2.hamburger.edu) Host "5" received "Token" +> [ 0.552000] (6:5@bob2.hamburger.edu) Host "5" send 'Token' to Host "6" +> [ 0.618240] (7:6@bob4.hamburger.edu) Host "6" received "Token" +> [ 0.618240] (7:6@bob4.hamburger.edu) Host "6" send 'Token' to Host "7" +> [ 0.794880] (8:7@alice0.crepe.fr) Host "7" received "Token" +> [ 0.794880] (8:7@alice0.crepe.fr) Host "7" send 'Token' to Host "8" +> [ 0.861120] (9:8@alice4.crepe.fr) Host "8" received "Token" +> [ 0.861120] (9:8@alice4.crepe.fr) Host "8" send 'Token' to Host "9" +> [ 0.927360] (10:9@alice1.crepe.fr) Host "9" received "Token" +> [ 0.927360] (10:9@alice1.crepe.fr) Host "9" send 'Token' to Host "0" +> [ 1.104000] (1:0@bob1.hamburger.edu) Host "0" received "Token" > [ 1.104000] (0:@) Simulation time 1.104 -> [ 1.104000] (10:slave@alice1.crepe.fr) Send Data to "host0" -> [ 1.104000] (1:master@bob1.hamburger.edu) Received "Token" -! output sort $ $SG_TEST_EXENV ${bindir:=.}/token_ring ${srcdir:=.}/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:@) Configuration change: Set 'coordinates' to 'yes' -> [ 0.000000] (0:@) Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code. -> [ 5.221778] (1:master@peer_100030591) Send Data to "host1" -> [ 5.221778] (2:slave@peer_100036570) Received "Token" -> [ 10.443556] (0:@) Simulation time 10.4436 -> [ 10.443556] (1:master@peer_100030591) Received "Token" -> [ 10.443556] (2:slave@peer_100036570) Send Data to "host0" \ No newline at end of file +> [ 0.000000] (0:@) Number of host '2' +> [ 0.000000] (1:0@peer_100030591) Host "0" send 'Token' to Host "1" +> [ 0.110400] (2:1@peer_100036570) Host "1" received "Token" +> [ 0.110400] (2:1@peer_100036570) Host "1" send 'Token' to Host "0" +> [ 0.220800] (1:0@peer_100030591) Host "0" received "Token" +> [ 0.220800] (0:@) Simulation time 0.2208 \ No newline at end of file -- 2.20.1