Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First example for bypass platform wit sg_platf_new* functions.
authornavarro <navarro@caraja.(none)>
Wed, 8 Aug 2012 12:08:58 +0000 (14:08 +0200)
committernavarro <navarro@caraja.(none)>
Wed, 8 Aug 2012 12:41:34 +0000 (14:41 +0200)
examples/msg/token_ring/CMakeLists.txt
examples/msg/token_ring/token_bypass.c [new file with mode: 0644]
include/simgrid/platf.h
src/surf/sg_platf.c
src/surf/surf_routing.c
src/surf/surfxml_parse.c

index eb4186b..c87894e 100644 (file)
@@ -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 (file)
index 0000000..bbd4d2c
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#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
+ * 
+ * - <b>token_ring/ring_call.c</b>: 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 ; i<nb_hosts; i++)
+  {
+    char* name_host = bprintf("%d",i);
+    MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) );
+    free(name_host);
+  }
+  xbt_dynar_free(&hosts);
+
+  res = MSG_main();
+  XBT_INFO("Simulation time %g", MSG_get_clock());
+  MSG_clean();
+  if (res == MSG_OK)
+    return 0;
+  else
+    return 1;
+
+}
index 99b92f5..3f6189a 100644 (file)
@@ -275,4 +275,14 @@ XBT_PUBLIC(void) sg_platf_new_mount(sg_platf_mount_cbarg_t mount);
 
 XBT_PUBLIC(void) sg_platf_new_process(sg_platf_process_cbarg_t process);
 
+// Add route and Asroute without xml file with those functions
+XBT_PUBLIC(void) sg_platf_route_begin (sg_platf_route_cbarg_t route); // Initialize route
+XBT_PUBLIC(void) sg_platf_route_end (sg_platf_route_cbarg_t route); // Finalize and add a route
+
+XBT_PUBLIC(void) sg_platf_ASroute_begin (sg_platf_ASroute_cbarg_t ASroute); // Initialize ASroute
+XBT_PUBLIC(void) sg_platf_ASroute_end (sg_platf_ASroute_cbarg_t ASroute); // Finalize and add a ASroute
+
+XBT_PUBLIC(void) sg_platf_route_add_link (const char* link_id, sg_platf_route_cbarg_t route); // Add a link to link list
+XBT_PUBLIC(void) sg_platf_ASroute_add_link (const char* link_id, sg_platf_ASroute_cbarg_t ASroute); // Add a link to link list
+
 #endif                          /* SG_PLATF_H */
index e9eaa19..190d6ba 100644 (file)
@@ -244,6 +244,29 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process){
   }
 }
 
+void sg_platf_route_begin (sg_platf_route_cbarg_t route){
+  route->link_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() {
index 3992b09..12e886b 100644 (file)
@@ -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 */
index 79b2835..ad0276b 100644 (file)
@@ -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;
   }