From: alegrand Date: Wed, 5 Jan 2005 23:18:46 +0000 (+0000) Subject: Now, any surf-based program can take --surf-path arguments to help locating platform... X-Git-Tag: v3.3~4613 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/05898e1bb90bb5120653b524b08f296edec37a0e Now, any surf-based program can take --surf-path arguments to help locating platform, trace or deployment files... 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 --- diff --git a/include/msg/msg.h b/include/msg/msg.h index 81e87a9655..2202096c08 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -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); diff --git a/src/msg/deployment.c b/src/msg/deployment.c index 9874ee1ea2..50f5bbab80 100644 --- a/src/msg/deployment.c +++ b/src/msg/deployment.c @@ -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); diff --git a/src/msg/global.c b/src/msg/global.c index 19b502f5d0..51297f4aea 100644 --- a/src/msg/global.c +++ b/src/msg/global.c @@ -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; } diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 84e72a6002..9c03c4018f 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -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(); } diff --git a/src/surf/network.c b/src/surf/network.c index f6fa9e450d..9e7dd9f053 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -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(); } diff --git a/src/surf/surf.c b/src/surf/surf.c index ce50a00284..171b66a48a 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -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) 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); diff --git a/testsuite/msg/msg_test.c b/testsuite/msg/msg_test.c index c5c9d18e8b..61d57fe048 100644 --- a/testsuite/msg/msg_test.c +++ b/testsuite/msg/msg_test.c @@ -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); } diff --git a/testsuite/run_tests.in b/testsuite/run_tests.in index aab584e482..188a6a6098 100755 --- a/testsuite/run_tests.in +++ b/testsuite/run_tests.in @@ -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 index 0000000000..2ab8c284fa --- /dev/null +++ b/testsuite/surf/platform.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/testsuite/surf/surf_usage2.c b/testsuite/surf/surf_usage2.c index 7c6c05d689..be028d260e 100644 --- a/testsuite/surf/surf_usage2.c +++ b/testsuite/surf/surf_usage2.c @@ -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"); diff --git a/testsuite/surf/trace_usage.c b/testsuite/surf/trace_usage.c index ece86561a7..0f2dcdee01 100644 --- a/testsuite/surf/trace_usage.c +++ b/testsuite/surf/trace_usage.c @@ -11,6 +11,7 @@ #include #include #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; }