From: Martin Quinson Date: Wed, 17 Jun 2015 16:12:34 +0000 (+0200) Subject: some sorting in the [smpi/xbt]_replay stuff X-Git-Tag: v3_12~577 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7e592d780fc9b1a47ccb3b2513eee18881861c31 some sorting in the [smpi/xbt]_replay stuff - prefix public symbols with xbt_ as any other public symbols - kill smpi_action_trace_run() as it is now a complicated no-OP - Much cruft remains to be sorted in this area unfortunately --- diff --git a/examples/smpi/replay/replay.c b/examples/smpi/replay/replay.c index 06b9f9b869..24c1a0e592 100644 --- a/examples/smpi/replay/replay.c +++ b/examples/smpi/replay/replay.c @@ -7,13 +7,8 @@ #include #include "smpi/smpi.h" -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { smpi_replay_init(&argc, &argv); - - /* Actually do the simulation using smpi_action_trace_run */ - smpi_action_trace_run(NULL); smpi_replay_finalize(); - return 0; } diff --git a/examples/smpi/replay_multiple/replay_multiple.c b/examples/smpi/replay_multiple/replay_multiple.c index e45ac6fae7..dcc0ad4803 100644 --- a/examples/smpi/replay_multiple/replay_multiple.c +++ b/examples/smpi/replay_multiple/replay_multiple.c @@ -13,80 +13,74 @@ #include "xbt/asserts.h" #include "smpi/smpi.h" XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, - "Messages specific for this msg example"); - + "Messages specific for this msg example"); + int smpi_replay(int argc, char *argv[]); int smpi_replay(int argc, char *argv[]) { - smpi_replay_init(&argc, &argv); - - /* Actually do the simulation using smpi_action_trace_run */ - smpi_action_trace_run(NULL); - smpi_replay_finalize(); - - return 0; + smpi_replay_init(&argc, &argv); + smpi_replay_finalize(); + return 0; } int main(int argc, char *argv[]){ - msg_error_t res; - const char *platform_file; - const char *application_file; - const char *description_file; - - MSG_init(&argc, argv); - - if (argc < 4) { - printf("Usage: %s description_file platform_file deployment_file\n", argv[0]); - printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]); - exit(1); - } - description_file = argv[1]; - platform_file = argv[2]; - application_file = argv[3]; - - - { /* Simulation setting */ - MSG_create_environment(platform_file); - } - { /* Application deployment */ - //read the description file in order to identify instances to launch - FILE* fp = fopen(description_file, "r"); - if (fp == NULL) - xbt_die("Cannot open %s", description_file); - ssize_t read; - char *line = NULL; - size_t n = 0; - int instance_size = 0; - const char* instance_id = NULL; - while ((read = xbt_getline(&line, &n, fp)) != -1 ){ - xbt_dynar_t elems = xbt_str_split_quoted_in_place(line); - if(xbt_dynar_length(elems)<3){ - xbt_die ("Not enough elements in the line"); - } - - const char** line_char= xbt_dynar_to_array(elems); - instance_id = line_char[0]; - instance_size = atoi(line_char[2]); - - XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size); - SMPI_app_instance_register(instance_id, smpi_replay,instance_size); - - xbt_free(line_char); - } - - MSG_launch_application(application_file); - SMPI_init(); - } - res = MSG_main(); - - XBT_INFO("Simulation time %g", MSG_get_clock()); - - - SMPI_finalize(); - if (res == MSG_OK) - return 0; - else - return 1; + msg_error_t res; + const char *platform_file; + const char *application_file; + const char *description_file; + + MSG_init(&argc, argv); + + if (argc < 4) { + printf("Usage: %s description_file platform_file deployment_file\n", argv[0]); + printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); + } + description_file = argv[1]; + platform_file = argv[2]; + application_file = argv[3]; + + + /* Simulation setting */ + MSG_create_environment(platform_file); + + /* Application deployment: read the description file in order to identify instances to launch */ + FILE* fp = fopen(description_file, "r"); + if (fp == NULL) + xbt_die("Cannot open %s", description_file); + ssize_t read; + char *line = NULL; + size_t n = 0; + int instance_size = 0; + const char* instance_id = NULL; + while ((read = xbt_getline(&line, &n, fp)) != -1 ){ + xbt_dynar_t elems = xbt_str_split_quoted_in_place(line); + if(xbt_dynar_length(elems)<3){ + xbt_die ("Not enough elements in the line"); + } + + const char** line_char= xbt_dynar_to_array(elems); + instance_id = line_char[0]; + instance_size = atoi(line_char[2]); + + XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size); + SMPI_app_instance_register(instance_id, smpi_replay,instance_size); + + xbt_free(line_char); + } + + MSG_launch_application(application_file); + SMPI_init(); + + res = MSG_main(); + + XBT_INFO("Simulation time %g", MSG_get_clock()); + + SMPI_finalize(); + if (res == MSG_OK) + return 0; + else + return 1; } diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 5eaf7acc17..f7ac21dd3f 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -885,7 +885,6 @@ XBT_PUBLIC(void) smpi_process_init(int *argc, char ***argv); /* Trace replay specific stuff */ XBT_PUBLIC(void) smpi_replay_init(int *argc, char***argv); -XBT_PUBLIC(void) smpi_action_trace_run(char *); XBT_PUBLIC(int) smpi_replay_finalize(void); XBT_PUBLIC(void) SMPI_app_instance_register(const char *name, xbt_main_func_t code, int num_processes); diff --git a/include/xbt/replay.h b/include/xbt/replay.h index 74434bc014..28ba751a83 100644 --- a/include/xbt/replay.h +++ b/include/xbt/replay.h @@ -15,11 +15,11 @@ SG_BEGIN_DECL() typedef struct s_replay_reader *xbt_replay_reader_t; typedef void (*action_fun) (const char *const *args); -XBT_PUBLIC_DATA(xbt_dict_t) action_funs; -XBT_PUBLIC_DATA(xbt_dict_t) action_queues; +XBT_PUBLIC_DATA(xbt_dict_t) xbt_action_funs; +XBT_PUBLIC_DATA(xbt_dict_t) xbt_action_queues; /* To split the file if a unique one is given (specific variable for the other case live in runner()) */ -XBT_PUBLIC_DATA(FILE *) action_fp; +XBT_PUBLIC_DATA(FILE *) xbt_action_fp; XBT_PUBLIC(xbt_replay_reader_t) xbt_replay_reader_new(const char*filename); XBT_PUBLIC(const char **) xbt_replay_reader_get(xbt_replay_reader_t reader); diff --git a/src/msg/msg_actions.c b/src/msg/msg_actions.c index 434b254cdb..5988740398 100644 --- a/src/msg/msg_actions.c +++ b/src/msg/msg_actions.c @@ -41,28 +41,28 @@ msg_error_t MSG_action_trace_run(char *path) xbt_dynar_t todo; xbt_dict_cursor_t cursor; - action_fp=NULL; + xbt_action_fp=NULL; if (path) { - action_fp = fopen(path, "r"); - if (action_fp == NULL) + xbt_action_fp = fopen(path, "r"); + if (xbt_action_fp == NULL) xbt_die("Cannot open %s: %s", path, strerror(errno)); } res = MSG_main(); - if (!xbt_dict_is_empty(action_queues)) { + if (!xbt_dict_is_empty(xbt_action_queues)) { XBT_WARN ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file."); - xbt_dict_foreach(action_queues, cursor, name, todo) { + xbt_dict_foreach(xbt_action_queues, cursor, name, todo) { XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name); } } if (path) - fclose(action_fp); - xbt_dict_free(&action_queues); - action_queues = xbt_dict_new_homogeneous(NULL); + fclose(xbt_action_fp); + xbt_dict_free(&xbt_action_queues); + xbt_action_queues = xbt_dict_new_homogeneous(NULL); return res; } diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index a31b752314..a5d2d7337d 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -296,35 +296,6 @@ void smpi_empty_status(MPI_Status * status) } } -void smpi_action_trace_run(char *path) -{ - char *name; - xbt_dynar_t todo; - xbt_dict_cursor_t cursor; - - action_fp=NULL; - if (path) { - action_fp = fopen(path, "r"); - if (action_fp == NULL) - xbt_die("Cannot open %s: %s", path, strerror(errno)); - } - - if (!xbt_dict_is_empty(action_queues)) { - XBT_WARN - ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file."); - - - xbt_dict_foreach(action_queues, cursor, name, todo) { - XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name); - } - } - - if (path) - fclose(action_fp); - xbt_dict_free(&action_queues); - action_queues = xbt_dict_new_homogeneous(NULL); -} - static void smpi_mpi_request_free_voidp(void* request) { MPI_Request req = request; diff --git a/src/smpi/smpi_replay.c b/src/smpi/smpi_replay.c index 33f1462300..9ccdce00c0 100644 --- a/src/smpi/smpi_replay.c +++ b/src/smpi/smpi_replay.c @@ -1086,7 +1086,7 @@ void smpi_replay_init(int *argc, char***argv){ XBT_VERB("Delayed start for instance - Sleeping for %f flops ",value ); smpi_execute_flops(value); } else { - //UGLY done to force context switch to be sure that all MSG_processes begin initialization + //UGLY: force a context switch to be sure that all MSG_processes begin initialization XBT_DEBUG("Force context switch by smpi_execute_flops - Sleeping for 0.0 flops "); smpi_execute_flops(0.0); } diff --git a/src/xbt/xbt_replay.c b/src/xbt/xbt_replay.c index 7f907db301..52e93b14e4 100644 --- a/src/xbt/xbt_replay.c +++ b/src/xbt/xbt_replay.c @@ -24,10 +24,10 @@ typedef struct s_replay_reader { int linenum; } s_xbt_replay_reader_t; -FILE *action_fp; +FILE *xbt_action_fp; -xbt_dict_t action_funs = NULL; -xbt_dict_t action_queues = NULL; +xbt_dict_t xbt_action_funs = NULL; +xbt_dict_t xbt_action_queues = NULL; static char *action_line = NULL; static size_t action_len = 0; @@ -115,7 +115,7 @@ void xbt_replay_reader_free(xbt_replay_reader_t *reader) void xbt_replay_action_register(const char *action_name, action_fun function) { char* lowername = str_tolower (action_name); - xbt_dict_set(action_funs, lowername, function, NULL); + xbt_dict_set(xbt_action_funs, lowername, function, NULL); xbt_free(lowername); } @@ -127,7 +127,7 @@ void xbt_replay_action_register(const char *action_name, action_fun function) void xbt_replay_action_unregister(const char *action_name) { char* lowername = str_tolower (action_name); - xbt_dict_remove(action_funs, lowername); + xbt_dict_remove(xbt_action_funs, lowername); xbt_free(lowername); } @@ -137,21 +137,21 @@ void xbt_replay_action_unregister(const char *action_name) */ int _xbt_replay_action_init(void) { - if (action_funs) + if (xbt_action_funs) return 0; is_replay_active = 1; - action_funs = xbt_dict_new_homogeneous(NULL); - action_queues = xbt_dict_new_homogeneous(NULL); + xbt_action_funs = xbt_dict_new_homogeneous(NULL); + xbt_action_queues = xbt_dict_new_homogeneous(NULL); return 1; } void _xbt_replay_action_exit(void) { - xbt_dict_free(&action_queues); - xbt_dict_free(&action_funs); + xbt_dict_free(&xbt_action_queues); + xbt_dict_free(&xbt_action_funs); free(action_line); - action_queues = NULL; - action_funs = NULL; + xbt_action_queues = NULL; + xbt_action_funs = NULL; action_line = NULL; } @@ -166,12 +166,12 @@ int xbt_replay_action_runner(int argc, char *argv[]) { int i; xbt_ex_t e; - if (action_fp) { // A unique trace file + if (xbt_action_fp) { // A unique trace file char **evt; while ((evt = action_get_action(argv[0]))) { char* lowername = str_tolower (evt[1]); action_fun function = - (action_fun)xbt_dict_get(action_funs, lowername); + (action_fun)xbt_dict_get(xbt_action_funs, lowername); xbt_free(lowername); TRY{ function((const char **)evt); @@ -196,7 +196,7 @@ int xbt_replay_action_runner(int argc, char *argv[]) while ((evt=xbt_replay_reader_get(reader))) { if (!strcmp(argv[0],evt[0])) { char* lowername = str_tolower (evt[1]); - action_fun function = (action_fun)xbt_dict_get(action_funs, lowername); + action_fun function = (action_fun)xbt_dict_get(xbt_action_funs, lowername); xbt_free(lowername); TRY{ function(evt); @@ -223,15 +223,15 @@ static char **action_get_action(char *name) xbt_dynar_t evt = NULL; char *evtname = NULL; - xbt_dynar_t myqueue = xbt_dict_get_or_null(action_queues, name); + xbt_dynar_t myqueue = xbt_dict_get_or_null(xbt_action_queues, name); if (myqueue == NULL || xbt_dynar_is_empty(myqueue)) { // nothing stored for me. Read the file further - if (action_fp == NULL) { // File closed now. There's nothing more to read. I'm out of here + if (xbt_action_fp == NULL) { // File closed now. There's nothing more to read. I'm out of here goto todo_done; } // Read lines until I reach something for me (which breaks in loop body) // or end of file reached - while (xbt_getline(&action_line, &action_len, action_fp) != -1) { + while (xbt_getline(&action_line, &action_len, xbt_action_fp) != -1) { // cleanup and split the string I just read char *comment = strchr(action_line, '#'); if (comment != NULL) @@ -250,11 +250,11 @@ static char **action_get_action(char *name) } else { // Else, I have to store it for the relevant colleague xbt_dynar_t otherqueue = - xbt_dict_get_or_null(action_queues, evtname); + xbt_dict_get_or_null(xbt_action_queues, evtname); if (otherqueue == NULL) { // Damn. Create the queue of that guy otherqueue = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp); - xbt_dict_set(action_queues, evtname, otherqueue, NULL); + xbt_dict_set(xbt_action_queues, evtname, otherqueue, NULL); } xbt_dynar_push(otherqueue, &evt); } @@ -272,7 +272,7 @@ static char **action_get_action(char *name) todo_done: if (myqueue != NULL) { xbt_dynar_free(&myqueue); - xbt_dict_remove(action_queues, name); + xbt_dict_remove(xbt_action_queues, name); } return NULL; }