Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Now, any surf-based program can take --surf-path arguments to help locating platform...
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 5 Jan 2005 23:18:46 +0000 (23:18 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 5 Jan 2005 23:18:46 +0000 (23:18 +0000)
Martin had a dream, I made it come true. ;-)

However, now the gras_stub_generator is completely broken...

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@737 48e7efb5-ca39-0410-a469-dd3cf9ba447f

13 files changed:
include/msg/msg.h
src/msg/deployment.c
src/msg/global.c
src/surf/cpu.c
src/surf/network.c
src/surf/surf.c
src/surf/surf_private.h
src/surf/trace_mgr.c
testsuite/msg/msg_test.c
testsuite/run_tests.in
testsuite/surf/platform.xml [new file with mode: 0644]
testsuite/surf/surf_usage2.c
testsuite/surf/trace_usage.c

index 81e87a9..2202096 100644 (file)
@@ -12,6 +12,7 @@
 
 /************************** Global ******************************************/
 void MSG_global_init(void);
+void MSG_global_init_args(int *argc, char **argv);
 void MSG_set_verbosity(MSG_outputmode_t mode);
 MSG_error_t MSG_set_channel_number(int number);
 MSG_error_t MSG_set_sharing_policy(MSG_sharing_t mode, long double param);
index 9874ee1..50f5bba 100644 (file)
@@ -54,13 +54,12 @@ static void parse_process_finalize(void)
  */
 void MSG_launch_application(const char *file) 
 {
-  MSG_global_init();
-  surf_parse_reset_parser();
+  xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
   STag_process_fun = parse_process_init;
   ETag_argument_fun = parse_argument;
   ETag_process_fun = parse_process_finalize;
   surf_parse_open(file);
-  surf_parse_lex();
+  xbt_assert1((!surf_parse_lex()),"Parse error in %s",file);
   surf_parse_close();
 }
 
@@ -74,7 +73,7 @@ void MSG_launch_application(const char *file)
  */
 void MSG_function_register(const char *name,m_process_code_t code)
 {
-  MSG_global_init();
+  xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
 
   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
 }
@@ -90,7 +89,7 @@ m_process_code_t MSG_get_registered_function(const char *name)
 {
   m_process_code_t code = NULL;
 
-  MSG_global_init();
+  xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
  
   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
 
index 19b502f..51297f4 100644 (file)
@@ -23,13 +23,20 @@ MSG_Global_t msg_global = NULL;
  */
 void MSG_global_init(void)
 {
-  if (!msg_global) {
-    int argc=0;
-    char **argv=NULL;
+  int argc=0;
+  char **argv=NULL;
+
+  CRITICAL0("Please stop using this function. Use MSG_global_init_args instead.");
+  DIE_IMPOSSIBLE;
+  MSG_global_init_args(&argc,argv);
+}
 
+void MSG_global_init_args(int *argc, char **argv)
+{
+  if (!msg_global) {
     msg_global = xbt_new0(s_MSG_Global_t,1);
 
-    surf_init(&argc, argv);    /* Initialize some common structures */
+    surf_init(argc, argv);     /* Initialize some common structures */
     xbt_context_init();
     msg_global->host = xbt_fifo_new();
     msg_global->process_to_run = xbt_fifo_new();
@@ -60,9 +67,7 @@ void MSG_set_verbosity(MSG_outputmode_t mode)
  */
 MSG_error_t MSG_set_channel_number(int number)
 {
-  MSG_global_init();
-
-  xbt_assert0((msg_global->max_channel == 0), "Channel number already set!");
+  xbt_assert0((msg_global) && (msg_global->max_channel == 0), "Channel number already set!");
 
   msg_global->max_channel = number;
 
@@ -98,9 +103,7 @@ MSG_error_t MSG_set_sharing_policy(MSG_sharing_t mode, long double param)
  */
 int MSG_get_channel_number(void)
 {
-  MSG_global_init();
-
-  xbt_assert0((msg_global->max_channel != 0), "Channel number not set yet!");
+  xbt_assert0((msg_global)&&(msg_global->max_channel != 0), "Channel number not set yet!");
 
   return msg_global->max_channel;
 }
index 84e72a6..9c03c40 100644 (file)
@@ -95,7 +95,7 @@ static void parse_file(const char *file)
   surf_parse_reset_parser();
   ETag_cpu_fun=parse_cpu;
   surf_parse_open(file);
-  surf_parse_lex();
+  xbt_assert1((!surf_parse_lex()),"Parse error in %s",file);
   surf_parse_close();
 }
 
index f6fa9e4..9e7dd9f 100644 (file)
@@ -166,14 +166,14 @@ static void parse_file(const char *file)
   surf_parse_reset_parser();
   ETag_network_link_fun=parse_network_link;
   surf_parse_open(file);
-  surf_parse_lex();
+  xbt_assert1((!surf_parse_lex()),"Parse error in %s",file);
   surf_parse_close();
 
   /* Figuring out the network cards used */
   surf_parse_reset_parser();
   STag_route_fun=parse_route_set_endpoints;
   surf_parse_open(file);
-  surf_parse_lex();
+  xbt_assert1((!surf_parse_lex()),"Parse error in %s",file);
   surf_parse_close();
 
   create_routing_table();
@@ -184,7 +184,7 @@ static void parse_file(const char *file)
   ETag_route_element_fun=parse_route_elem;
   ETag_route_fun=parse_route_set_route;
   surf_parse_open(file);
-  surf_parse_lex();
+  xbt_assert1((!surf_parse_lex()),"Parse error in %s",file);
   surf_parse_close();
 }
 
index ce50a00..171b66a 100644 (file)
@@ -8,11 +8,16 @@
 #include "surf_private.h"
 #include "xbt/module.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_global, surf,
+                               "Logging specific to the SURF global module");
+
+
 static double NOW = 0;
 
 xbt_dynar_t resource_list = NULL;
 tmgr_history_t history = NULL;
 lmm_system_t maxmin_system = NULL;
+xbt_dynar_t surf_path = NULL;
 
 double generic_maxmin_share_resources(xbt_swag_t running_actions,
                                      size_t offset)
@@ -111,7 +116,30 @@ void surf_action_set_data(surf_action_t action,
 
 void surf_init(int *argc, char **argv)
 {
+  int i,j;
+  char *opt;
+
   xbt_init(argc, argv);
+  if (!surf_path) {
+    const char *initial_path = "./";
+    surf_path = xbt_dynar_new(sizeof(char*), NULL);
+    xbt_dynar_push(surf_path,&initial_path);
+
+    for (i=1; i<*argc; i++) {
+      if (!strncmp(argv[i],"--surf-path=",strlen("--surf-path="))) {
+       opt=strchr(argv[i],'=');
+       opt++;
+       xbt_dynar_push(surf_path,&opt);
+       /*remove this from argv*/
+       for (j=i+1; j<*argc; j++) {
+         argv[j-1] = argv[j];
+       } 
+       argv[j-1] = NULL;
+       (*argc)--;
+       i--; /* compensate effect of next loop incrementation */
+      }
+    }
+  }
   if (!resource_list)
     resource_list = xbt_dynar_new(sizeof(surf_resource_private_t), NULL);
   if (!history)
@@ -120,6 +148,28 @@ void surf_init(int *argc, char **argv)
     maxmin_system = lmm_system_new();
 }
 
+FILE *surf_fopen(const char *name, const char *mode)
+{
+  int i; 
+  char* path = NULL;
+  FILE *file = NULL;
+  static char* path_name = NULL;
+
+  xbt_assert0(surf_path,"surf_init has to be called before using surf_fopen");
+  if(!path_name) path_name=xbt_new0(char,strlen(name)+1);
+
+  xbt_dynar_foreach(surf_path,i,path) {
+    if(strlen(path_name)<strlen(path)+strlen(name)+2) 
+      path_name=xbt_realloc(path_name,strlen(path)+strlen(name)+2);
+    strcpy(path_name, path);
+    strcat(path_name,"/");
+    strcat(path_name,name);
+    file = fopen(path_name,mode);
+    if(file) return file;
+  }
+  return file;
+}
+
 void surf_finalize(void)
 {
   int i;
index 6452c47..968c380 100644 (file)
@@ -40,8 +40,10 @@ void surf_action_change_state(surf_action_t action,
                              e_surf_action_state_t state);
 void surf_action_set_data(surf_action_t action,
                          void *data);
+FILE *surf_fopen(const char *name, const char *mode);
 
 extern lmm_system_t maxmin_system;
 extern tmgr_history_t history;
+extern xbt_dynar_t surf_path;
 
 #endif                         /* _SURF_SURF_PRIVATE_H */
index 80db05d..403465a 100644 (file)
@@ -9,6 +9,7 @@
 #include "xbt/error.h"
 #include "xbt/dict.h"
 #include "trace_mgr_private.h"
+#include "surf_private.h"
 #include <stdlib.h>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(trace, surf,
@@ -22,19 +23,19 @@ static void _tmgr_trace_free(void *trace)
 
 tmgr_history_t tmgr_history_new(void)
 {
-  tmgr_history_t history;
+  tmgr_history_t h;
 
-  history = xbt_new0(s_tmgr_history_t, 1);
+  h = xbt_new0(s_tmgr_history_t, 1);
 
-  history->heap = xbt_heap_new(8, xbt_free);   /* Why 8 ? Well, why not... */
+  h->heap = xbt_heap_new(8, xbt_free); /* Why 8 ? Well, why not... */
 
-  return history;
+  return h;
 }
 
-void tmgr_history_free(tmgr_history_t history)
+void tmgr_history_free(tmgr_history_t h)
 {
-  xbt_heap_free(history->heap);
-  xbt_free(history);
+  xbt_heap_free(h->heap);
+  xbt_free(h);
 }
 
 tmgr_trace_t tmgr_trace_new(const char *filename)
@@ -53,7 +54,7 @@ tmgr_trace_t tmgr_trace_new(const char *filename)
       return trace;
   }
 
-  if ((f = fopen(filename, "r")) == NULL) {
+  if ((f = surf_fopen(filename, "r")) == NULL) {
     xbt_assert1(0, "Cannot open file '%s'", filename);
   }
 
@@ -117,7 +118,7 @@ void tmgr_trace_free(tmgr_trace_t trace)
   xbt_free(trace);
 }
 
-tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history,
+tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t h,
                                          tmgr_trace_t trace,
                                          double start_time, int offset,
                                          void *resource)
@@ -133,25 +134,25 @@ tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history,
   xbt_assert0((trace_event->idx < xbt_dynar_length(trace->event_list)),
              "You're refering to an event that does not exist!");
 
-  xbt_heap_push(history->heap, trace_event, start_time);
+  xbt_heap_push(h->heap, trace_event, start_time);
 
   return trace_event;
 }
 
-double tmgr_history_next_date(tmgr_history_t history)
+double tmgr_history_next_date(tmgr_history_t h)
 {
-  if (xbt_heap_size(history->heap))
-    return (xbt_heap_maxkey(history->heap));
+  if (xbt_heap_size(h->heap))
+    return (xbt_heap_maxkey(h->heap));
   else
     return -1.0;
 }
 
-tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history,
+tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t h,
                                                   double date,
                                                   double *value,
                                                   void **resource)
 {
-  double event_date = xbt_heap_maxkey(history->heap);
+  double event_date = xbt_heap_maxkey(h->heap);
   tmgr_trace_event_t trace_event = NULL;
   tmgr_event_t event = NULL;
   tmgr_trace_t trace = NULL;
@@ -159,7 +160,7 @@ tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history,
   if (event_date > date)
     return NULL;
 
-  if (!(trace_event = xbt_heap_pop(history->heap)))
+  if (!(trace_event = xbt_heap_pop(h->heap)))
     return NULL;
 
   trace = trace_event->trace;
@@ -170,10 +171,10 @@ tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history,
   *resource = trace_event->resource;
 
   if (trace_event->idx < xbt_dynar_length(trace->event_list) - 1) {
-    xbt_heap_push(history->heap, trace_event, event_date + event->delta);
+    xbt_heap_push(h->heap, trace_event, event_date + event->delta);
     trace_event->idx++;
   } else if (event->delta > 0) {       /* Last element, checking for periodicity */
-    xbt_heap_push(history->heap, trace_event, event_date + event->delta);
+    xbt_heap_push(h->heap, trace_event, event_date + event->delta);
     trace_event->idx = 0;
   } else {                     /* We don't need this trace_event anymore */
     xbt_free(trace_event);
index c5c9d18..61d57fe 100644 (file)
@@ -18,7 +18,7 @@
 int unix_emitter(int argc, char *argv[]);
 int unix_receiver(int argc, char *argv[]);
 int unix_forwarder(int argc, char *argv[]);
-void test_all(const char *platform_file, const char *application_file, double sharing);
+void test_all(const char *platform_file, const char *application_file);
 
 
 /** The names of the channels we will use in this simulation. There is
@@ -49,7 +49,7 @@ int unix_emitter(int argc, char *argv[])
   m_task_t *todo = NULL;
 
   int i;
-  PRINT_MESSAGE("Hello !");
+
   print_args(argc,argv);
 
   {                  /* Process organisation */
@@ -107,7 +107,6 @@ int unix_receiver(int argc, char *argv[])
   m_task_t *todo = (m_task_t *) calloc(NB_TASK, sizeof(m_task_t));
   int i;
 
-  PRINT_MESSAGE("Hello !");
   print_args(argc,argv);
 
   for (i = 0; i < NB_TASK;) {
@@ -139,7 +138,6 @@ int unix_forwarder(int argc, char *argv[])
   m_task_t *todo = (m_task_t *) calloc(NB_TASK, sizeof(m_task_t));
   int i;
 
-  PRINT_MESSAGE("Hello !");
   print_args(argc,argv);
 
   for (i = 0; i < NB_TASK;) {
@@ -165,17 +163,10 @@ int unix_forwarder(int argc, char *argv[])
 }
 
 
-void test_all(const char *platform_file,const char *application_file, double sharing)
+void test_all(const char *platform_file,const char *application_file)
 {
   {                            /*  Simulation setting */
-    MSG_global_init();
-    MSG_set_verbosity(MSG_SILENT);
     MSG_set_channel_number(MAX_CHANNEL);
-    if(sharing<=0) {
-      MSG_set_sharing_policy(MSG_TCP,.1);
-    } else {
-      MSG_set_sharing_policy(MSG_STORE_AND_FORWARD,sharing);
-    }
     MSG_create_environment(platform_file);
   }
   {                            /*   Application deployment */
@@ -185,12 +176,12 @@ void test_all(const char *platform_file,const char *application_file, double sha
   }
   MSG_main();
   printf("Simulation time %Lg\n",MSG_getClock());
-  MSG_clean();
 }
 
 int main(int argc, char *argv[])
 {
-  test_all("msg_platform.xml","msg_deployment.xml",-.1);
-/*   test_all("msg_platform.txt","msg_deployment.txt",.1); */
+  MSG_global_init_args(&argc,argv);
+  test_all("msg_platform.xml","msg_deployment.xml");
+  MSG_clean();
   return (0);
 }
index aab584e..188a6a6 100755 (executable)
@@ -28,9 +28,9 @@ for test in xbt/log_usage@EXEEXT@                                 \
            "gras/datadesc_usage@EXEEXT@ --read @top_srcdir@/testsuite/gras/datadesc.g5" \
            \
            surf/maxmin_usage@EXEEXT@       surf/maxmin_bench@EXEEXT@               \
-           surf/trace_usage@EXEEXT@                                        \
-           "surf/surf_usage@EXEEXT@  @top_srcdir@/testsuite/surf/platform.txt" \
-           "surf/surf_usage2@EXEEXT@ @top_srcdir@/testsuite/surf/platform.txt"
+           "surf/trace_usage@EXEEXT@ --surf-path=surf/"                            \
+           "surf/surf_usage@EXEEXT@  --surf-path=surf/ platform.xml" \
+           "surf/surf_usage2@EXEEXT@ --surf-path=surf/ platform.xml"
 do                 
   tests_nb=`expr $tests_nb + 1`
   echo "#### Test $test"
diff --git a/testsuite/surf/platform.xml b/testsuite/surf/platform.xml
new file mode 100644 (file)
index 0000000..2ab8c28
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform_description SYSTEM "surfxml.dtd">
+<platform_description>
+  <cpu name="Cpu A" power="100.00" availability_file="trace_A.txt" state_file="trace_A_failure.txt"/>
+  <cpu name="Cpu B" power="100.00" availability_file="trace_B.txt"/>
+  <network_link name="LinkA" bandwidth="10.0" latency="0.2"/>
+  <route src="Cpu A" dst="Cpu B"><route_element name="LinkA"/></route>
+</platform_description>
index 7c6c05d..be028d2 100644 (file)
@@ -99,7 +99,7 @@ void test(char *platform)
        resource->common_public->action_free(action);
       }
     }
-  } while (surf_solve());
+  } while (surf_solve()>=0.0);
 
   printf("Simulation Terminated\n");
 
index ece8656..0f2dcde 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "surf/trace_mgr.h"
+#include "surf/surf.h"
 
 void test(void);
 void test(void)
@@ -47,6 +48,7 @@ void test(void)
 
 int main(int argc, char **argv)
 {
+  surf_init(&argc,argv);
   test();
   return 0;
 }