From: navarro Date: Wed, 8 Aug 2012 12:08:58 +0000 (+0200) Subject: First example for bypass platform wit sg_platf_new* functions. X-Git-Tag: v3_8~184 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/be242659a7ff46b729f9610dc089c9fd968b4e86 First example for bypass platform wit sg_platf_new* functions. --- diff --git a/examples/msg/token_ring/CMakeLists.txt b/examples/msg/token_ring/CMakeLists.txt index eb4186b1d9..c87894efe6 100644 --- a/examples/msg/token_ring/CMakeLists.txt +++ b/examples/msg/token_ring/CMakeLists.txt @@ -3,12 +3,15 @@ cmake_minimum_required(VERSION 2.6) set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") add_executable(token_ring ring_call.c) +add_executable(token_bypass token_bypass.c) ### Add definitions for compile if(NOT WIN32) target_link_libraries(token_ring simgrid m pthread ) + target_link_libraries(token_bypass simgrid m pthread ) else(NOT WIN32) target_link_libraries(token_ring simgrid) + target_link_libraries(token_bypass simgrid) endif(NOT WIN32) set(tesh_files @@ -23,6 +26,7 @@ set(xml_files set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/ring_call.c + ${CMAKE_CURRENT_SOURCE_DIR}/token_bypass.c PARENT_SCOPE ) set(bin_files diff --git a/examples/msg/token_ring/token_bypass.c b/examples/msg/token_ring/token_bypass.c new file mode 100644 index 0000000000..bbd4d2c9a2 --- /dev/null +++ b/examples/msg/token_ring/token_bypass.c @@ -0,0 +1,156 @@ +/* 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 "msg/msg.h" +#include "surf/surf_private.h" + +int host(int argc, char *argv[]); +unsigned int task_comp_size = 50000000; +unsigned int task_comm_size = 1000000; + +int nb_hosts; /* All declared hosts */ + +XBT_LOG_NEW_DEFAULT_CATEGORY(ring, + "Messages specific for this msg example"); + +/** @addtogroup MSG_examples + * + * @section MSG_ex_apps Examples of full applications + * + * - token_ring/ring_call.c: Classical token ring + * communication, where a token is exchanged along a ring to reach + * every participant. + * + */ + +int host(int argc, char *argv[]) +{ + int host_number = atoi(MSG_process_get_name(MSG_process_self())); + char mailbox[256]; + msg_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 == nb_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; +} + +static int surf_parse_bypass_platform(void) +{ + sg_platf_begin(); + sg_platf_new_AS_begin("AS0", A_surfxml_AS_routing_Full); + + s_sg_platf_host_cbarg_t bob; + memset(&bob,0,sizeof(bob)); + bob.id = "bob"; + bob.power_peak = 98095000; + bob.power_scale = 1.0; + bob.core_amount = 1; + bob.initial_state = A_surfxml_host_state_ON; + bob.power_trace = NULL; + bob.state_trace = NULL; + bob.coord = NULL; + bob.properties = NULL; + + s_sg_platf_host_cbarg_t alice; + memset(&alice,0,sizeof(alice)); + alice.id = "alice"; + alice.power_peak = 98095000; + alice.power_scale = 1.0; + alice.core_amount = 1; + alice.initial_state = A_surfxml_host_state_ON; + alice.power_trace = NULL; + alice.state_trace = NULL; + alice.coord = NULL; + alice.properties = NULL; + + sg_platf_new_host(&bob); + sg_platf_new_host(&alice); + + s_sg_platf_link_cbarg_t link; + memset(&link, 0, sizeof(link)); + link.id = "link1"; + link.state = A_surfxml_link_state_ON; + link.policy = A_surfxml_link_sharing_policy_SHARED; + link.latency = 0.000278066; + link.bandwidth = 27946250; + sg_platf_new_link(&link); + + s_sg_platf_route_cbarg_t route; + memset(&route,0,sizeof(route)); + route.src = "bob"; + route.dst = "alice"; + route.symmetrical = FALSE; + sg_platf_route_begin(&route); + sg_platf_route_add_link("link1", &route); + sg_platf_route_end(&route); + + route.src = "alice"; + route.dst = "bob"; + sg_platf_route_begin(&route); + sg_platf_route_add_link("link1", &route); + sg_platf_route_end(&route); + + sg_platf_new_AS_end(); + sg_platf_end(); + sg_platf_exit(); + return 0; +} + +int main(int argc, char **argv) +{ + int i; + msg_error_t res = MSG_OK; + + MSG_init(&argc, argv); + surf_parse = surf_parse_bypass_platform; + MSG_create_environment(NULL); + + MSG_function_register("host", host); + + xbt_dynar_t hosts = MSG_hosts_as_dynar(); + nb_hosts = xbt_dynar_length(hosts); + + XBT_INFO("Number of host '%d'",nb_hosts); + for(i = 0 ; ilink_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); +} +void sg_platf_ASroute_begin (sg_platf_ASroute_cbarg_t ASroute){ + ASroute->link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); +} + +void sg_platf_route_end (sg_platf_route_cbarg_t route){ + sg_platf_new_route(route); +} +void sg_platf_ASroute_end (sg_platf_ASroute_cbarg_t ASroute){ + sg_platf_new_ASroute(ASroute); +} + +void sg_platf_route_add_link (const char* link_id, sg_platf_route_cbarg_t route){ + char *link_name = xbt_strdup(link_id); + xbt_dynar_push(route->link_list, &link_name); +} +void sg_platf_ASroute_add_link (const char* link_id, sg_platf_ASroute_cbarg_t ASroute){ + char *link_name = xbt_strdup(link_id); + xbt_dynar_push(ASroute->link_list, &link_name); +} + void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ } void sg_platf_end() { diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 3992b09897..12e886b15d 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -362,6 +362,7 @@ static void routing_parse_trace_connect(sg_platf_trace_connect_cbarg_t trace_con */ void routing_AS_begin(const char *AS_id, int wanted_routing_type) { + XBT_DEBUG("routing_AS_begin"); AS_t new_as; routing_model_description_t model = NULL; @@ -379,6 +380,8 @@ void routing_AS_begin(const char *AS_id, int wanted_routing_type) case A_surfxml_AS_routing_None: model = &routing_models[SURF_MODEL_NONE];break; case A_surfxml_AS_routing_RuleBased: model = &routing_models[SURF_MODEL_RULEBASED];break; case A_surfxml_AS_routing_Vivaldi: model = &routing_models[SURF_MODEL_VIVALDI];break; + default: xbt_die("Not a valid model!!!"); + break; } /* make a new routing component */ diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 79b283538a..ad0276b143 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -543,7 +543,7 @@ void ETag_surfxml_ASroute(void){ ASroute.symmetrical = TRUE; break; case A_surfxml_ASroute_symmetrical_NO: - ASroute.symmetrical = FALSE;; + ASroute.symmetrical = FALSE; break; }