From: navarrop Date: Mon, 31 Jan 2011 13:35:28 +0000 (+0000) Subject: Add an example for communication between cluster or peer. X-Git-Tag: v3.6_beta2~397 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e56bea291e54aac63783fe568585d19a24528c2a Add an example for communication between cluster or peer. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9532 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/teshsuite/simdag/platforms/CMakeLists.txt b/teshsuite/simdag/platforms/CMakeLists.txt index 4e960d0dfd..ddda1e3ef9 100644 --- a/teshsuite/simdag/platforms/CMakeLists.txt +++ b/teshsuite/simdag/platforms/CMakeLists.txt @@ -5,15 +5,18 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") add_executable(basic_parsing_test basic_parsing_test.c) add_executable(is_router_test is_router_test.c) add_executable(flatifier flatifier.c) +add_executable(ring_call ring_call.c) ### Add definitions for compile if(NOT WIN32) target_link_libraries(basic_parsing_test simgrid m pthread ) target_link_libraries(is_router_test simgrid m pthread ) target_link_libraries(flatifier simgrid m pthread ) +target_link_libraries(ring_call simgrid m pthread ) else(NOT WIN32) target_link_libraries(basic_parsing_test simgrid) target_link_libraries(is_router_test simgrid) target_link_libraries(flatifier simgrid) +target_link_libraries(ring_call simgrid) endif(NOT WIN32) diff --git a/teshsuite/simdag/platforms/ring_call.c b/teshsuite/simdag/platforms/ring_call.c new file mode 100644 index 0000000000..d029335942 --- /dev/null +++ b/teshsuite/simdag/platforms/ring_call.c @@ -0,0 +1,178 @@ +/* Copyright (c) 2008, 2009, 2010. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include +#include "simdag/simdag.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[]); + +XBT_LOG_NEW_DEFAULT_CATEGORY(ring, + "Messages specific for this msg example"); + +static int name_compare_hosts(const void *n1, const void *n2) +{ + char name1[80], name2[80]; + strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1))); + strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2))); + + return strcmp(name1, name2); +} + +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, "Hello"); + + task_s = MSG_task_create(buffer, + task_comp_size, + task_comm_size, + NULL); + MSG_task_send(task_s,mailbox); + + //MSG_comm_wait(comm, -1); + INFO1("Send Data to \"%s\"", mailbox); + + sprintf(mailbox, "host%d", num); + MSG_task_receive(&(task_r), mailbox); + //res = MSG_comm_wait(res_irecv, -1); + INFO1("Received \"%s\"", MSG_task_get_name(task_r)); + //MSG_comm_destroy(res_irecv); + 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); + //res = MSG_comm_wait(res_irecv, -1); + INFO1("Received \"%s\"", MSG_task_get_name(task_r)); + //MSG_comm_destroy(res_irecv); + //Receive something now need to tell it! + + sprintf(mailbox, "host%d", num+1); + if(num == totalHosts-1) + sprintf(mailbox, "host%d", 0); + sprintf(buffer, "Hello"); + task_s = MSG_task_create(buffer, + task_comp_size, + task_comm_size, + NULL); + MSG_task_send(task_s, mailbox); + //MSG_comm_wait(comm, -1); + INFO1("Send Data to \"%s\"", mailbox); + + return 0; +} + +static int surf_parse_bypass_application(void) +{ + 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); + + INFO1("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; +} + +typedef enum { + PORT_22 = 20, + MAX_CHANNEL +} channel_t; + +int main(int argc, char **argv) +{ + int 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); + + res = MSG_main(); + + INFO1("Simulation time %g", MSG_get_clock()); + + MSG_clean(); + + if (res == MSG_OK) + return 0; + else + return 1; + +}