From d3546624f31ddb7580a5d7e7e4f66e00e05041d6 Mon Sep 17 00:00:00 2001 From: alegrand Date: Thu, 17 Feb 2005 05:49:26 +0000 Subject: [PATCH 1/1] Functionnal benchmarking macros : It seems to be working fine. surf:~/Work/GRAS/gras/examples/gras/chrono $ time ./test_sg ; time ./test_rl xbt/module.c:44: [module/INFO] Initialize XBT gras/gras.c:27: [gras/INFO] Initialize GRAS chrono.c:32: [Chrono/INFO] Before computation: 0 chrono.c:52: [Chrono/INFO] After computation: 15.7531; Duration: 15.7531 MSG: Congratulations ! Simulation terminated : all process are over real 0m4.002s user 0m3.940s sys 0m0.030s gras/gras.c:27: [gras/INFO] Initialize GRAS xbt/module.c:44: [module/INFO] Initialize XBT chrono.c:32: [Chrono/INFO] Before computation: 1.10862e+09 chrono.c:52: [Chrono/INFO] After computation: 1.10862e+09; Duration: 15.6633 real 0m15.729s user 0m15.550s sys 0m0.060s git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1032 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- examples/gras/chrono/chrono.c | 42 ++++++++----- include/gras/chrono.h | 23 +++++-- src/gras/chrono.c | 109 +++++++++++++++++++++++++++++++++- src/gras/gras.c | 3 +- 4 files changed, 152 insertions(+), 25 deletions(-) diff --git a/examples/gras/chrono/chrono.c b/examples/gras/chrono/chrono.c index c0c888834e..eb31f9a882 100644 --- a/examples/gras/chrono/chrono.c +++ b/examples/gras/chrono/chrono.c @@ -8,6 +8,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "gras.h" +#include "xbt/log.h" XBT_LOG_NEW_DEFAULT_CATEGORY(Chrono,"Messages specific to this example"); @@ -17,29 +18,38 @@ int multiplier (int argc,char *argv[]); int multiplier (int argc,char *argv[]) { - int i,j,k; + int i,j,k,l; double *A,*B,*C; int n = 500; + double start = 0.0; + gras_init(&argc, argv, NULL); - + A = malloc(n*n*sizeof(double)); B = malloc(n*n*sizeof(double)); C = malloc(n*n*sizeof(double)); - INFO1("Before computation : %lg", gras_os_time()); - for(i=0; i %lg <--- \n", sys_time()-timer); */ + MSG_task_destroy(task); + return 0; +} + +int gras_bench_once_begin(const char *location, int line) +{ + double *ir = NULL; + xbt_assert0(!benchmarking,"Already benchmarking"); + benchmarking = 1; + + __location__=location; + xbt_dict_get(benchmark_set, __location__, (void *) &ir); + if(!ir) { +/* printf("%s:%d\n",location,line); */ + duration = sys_time(); + return 1; + } else { + duration = -1.0; + return 0; + } +} + +int gras_bench_once_end(void) +{ + m_task_t task = NULL; + + xbt_assert0(benchmarking,"Not benchmarking yet"); + benchmarking = 0; + if(duration>0) { + duration = sys_time()-duration; + store_in_dict(benchmark_set, __location__, duration); + } else { + duration = get_from_dict(benchmark_set,__location__); + } + task = MSG_task_create("task", (duration)/reference, 0 , NULL); + MSG_task_execute(task); + MSG_task_destroy(task); + return 0; } -void gras_bench_always_end(void) +void gras_chrono_init(void) { + if(!benchmark_set) + benchmark_set = xbt_dict_new(); } diff --git a/src/gras/gras.c b/src/gras/gras.c index d3b228847a..03af67b124 100644 --- a/src/gras/gras.c +++ b/src/gras/gras.c @@ -17,6 +17,7 @@ #include "gras/core.h" #include "gras/cond.h" /* gras_if_RL() => FIXME: killme when gras/sg works */ #include "gras/process.h" /* FIXME: killme and put process_init in modinter */ +#include "gras/chrono.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras,XBT_LOG_ROOT_CAT,"All GRAS categories (cf. section \ref GRAS_API)"); static int gras_running_process = 0; @@ -28,7 +29,7 @@ void gras_init(int *argc,char **argv, const char *defaultlog) { /* First initialize the XBT */ xbt_init_defaultlog(argc,argv,defaultlog); - + gras_chrono_init(); /* module registrations: * - declare process specific data we need (without creating them) */ -- 2.20.1