From 624064042aa82cbdb6d83b0f73bba7ba61048bbc Mon Sep 17 00:00:00 2001 From: mquinson Date: Thu, 15 May 2008 14:24:16 +0000 Subject: [PATCH] Remove a crude hack where first call to surf_solve() finalize the initialization, and introduce a surf_presolve() function to do so. That a tiny little cleanup, but well, I had to git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5429 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/gras/Virtu/sg_process.c | 1 + src/gras_config.h.in | 3 +++ src/include/simix/simix.h | 1 + src/include/surf/surf.h | 7 +++++++ src/msg/global.c | 1 + src/simdag/sd_global.c | 2 +- src/simix/smx_global.c | 15 ++++++++++----- src/smpi/smpi_global.c | 1 + src/surf/surf.c | 27 +++++++++++++++------------ 9 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/gras/Virtu/sg_process.c b/src/gras/Virtu/sg_process.c index b37d2baf75..392d11e8f1 100644 --- a/src/gras/Virtu/sg_process.c +++ b/src/gras/Virtu/sg_process.c @@ -217,6 +217,7 @@ void gras_main() { /* Clean IO before the run */ fflush(stdout); fflush(stderr); + SIMIX_init(); while (SIMIX_solve(actions_done, actions_failed) != -1.0) { while ( (action = xbt_fifo_pop(actions_failed)) ) { diff --git a/src/gras_config.h.in b/src/gras_config.h.in index 32c5e80f68..dd0c895a07 100644 --- a/src/gras_config.h.in +++ b/src/gras_config.h.in @@ -1,5 +1,8 @@ /* src/gras_config.h.in. Generated from configure.ac by autoheader. */ +/* Arguments passed to the configure script */ +#undef AC_CONFIGURE_ARGS + /* Path to the addr2line tool */ #undef ADDR2LINE diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index a3d6ec04b4..3bc9eb9836 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -29,6 +29,7 @@ XBT_PUBLIC(xbt_main_func_t) SIMIX_get_registered_function(const char *name); XBT_PUBLIC(void) SIMIX_launch_application(const char *file); XBT_PUBLIC(double) SIMIX_get_clock(void); +XBT_PUBLIC(void) SIMIX_init(void); XBT_PUBLIC(double) SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed); /* Timer functions */ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 8b83c0adac..16dd1640d4 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -537,6 +537,13 @@ XBT_PUBLIC_DATA(xbt_dynar_t) model_list; */ XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */ +/** \brief Finish simulation initialization + * \ingroup SURF_simulation + * + * This function must be called before the first call to surf_solve() + */ +XBT_PUBLIC(void) surf_presolve(void); + /** \brief Performs a part of the simulation * \ingroup SURF_simulation * \return the elapsed time, or -1.0 if no event could be executed diff --git a/src/msg/global.c b/src/msg/global.c index 42dba8bfa2..1b5325f27e 100644 --- a/src/msg/global.c +++ b/src/msg/global.c @@ -168,6 +168,7 @@ MSG_error_t MSG_main(void) /* Clean IO before the run */ fflush(stdout); fflush(stderr); + SIMIX_init(); //surf_solve(); /* Takes traces into account. Returns 0.0 */ /* xbt_fifo_size(msg_global->process_to_run) */ diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index ce7651537f..c849609eab 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -419,7 +419,7 @@ SD_task_t* SD_simulate(double how_long) changed_tasks[0] = NULL; if (first_time) { - surf_solve(); /* Takes traces into account. Returns 0.0 */ + surf_presolve(); /* Takes traces into account */ first_time = 0; } diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 5742d2bf78..c797d5651c 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -313,6 +313,15 @@ double SIMIX_get_clock(void) return surf_get_clock(); } +/** + * \brief Finish the simulation initialization + * + * Must be called before the first call to SIMIX_solve() + */ +void SIMIX_init(void) { + surf_presolve(); +} + /** * \brief Does a turn of the simulation * @@ -328,16 +337,12 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) unsigned int iter; double elapsed_time = 0.0; static int state_modifications = 1; - static int first = 1; xbt_context_empty_trash(); if (xbt_swag_size(simix_global->process_to_run) && (elapsed_time > 0)) { DEBUG0("**************************************************"); } - if (first) { - surf_solve(); /* Takes traces into account. Returns 0.0 */ - first = 0; - } + while ((process = xbt_swag_extract(simix_global->process_to_run))) { DEBUG2("Scheduling %s on %s", process->name, process->simdata->smx_host->name); diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index 822f0cadec..1221b7ce8d 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -301,6 +301,7 @@ int smpi_run_simulation(int *argc, char **argv) /* Clean IO before the run */ fflush(stdout); fflush(stderr); + SIMIX_init(); while (SIMIX_solve(actions_done, actions_failed) != -1.0) { while ((action = xbt_fifo_pop(actions_failed))) { diff --git a/src/surf/surf.c b/src/surf/surf.c index 166c13403d..ac8040c73a 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -454,20 +454,14 @@ void surf_exit(void) xbt_exit(); } -double surf_solve(void) -{ - static int first_run = 1; - - double min = -1.0; +void surf_presolve(void) { double next_event_date = -1.0; - double model_next_action_end = -1.0; + tmgr_trace_event_t event = NULL; double value = -1.0; surf_model_object_t model_obj = NULL; surf_model_t model = NULL; - tmgr_trace_event_t event = NULL; unsigned int iter; - - if (first_run) { + DEBUG0 ("First Run! Let's \"purge\" events and put models in the right state"); while ((next_event_date = tmgr_history_next_date(history)) != -1.0) { @@ -484,9 +478,18 @@ double surf_solve(void) xbt_dynar_foreach(model_list, iter, model) { model->common_private->update_actions_state(NOW, 0.0); } - first_run = 0; - return 0.0; - } +} + +double surf_solve(void) +{ + double min = -1.0; + double next_event_date = -1.0; + double model_next_action_end = -1.0; + double value = -1.0; + surf_model_object_t model_obj = NULL; + surf_model_t model = NULL; + tmgr_trace_event_t event = NULL; + unsigned int iter; min = -1.0; -- 2.20.1