From 23e9dd1f26f1f7c1bfc672d2ce92f274aa6a00f8 Mon Sep 17 00:00:00 2001 From: pini Date: Tue, 1 Mar 2011 16:41:42 +0000 Subject: [PATCH] Tentatively use sampling with Fortran. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9745 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/smpi/smpi.h | 4 ++-- include/smpi/smpif.h.in | 21 +++++++++++++++++++++ src/smpi/smpi_bench.c | 26 ++++++++++++++------------ src/smpi/smpif2c.in | 10 ++++++++++ 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index dafc86da4c..aac82f0384 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -418,8 +418,8 @@ XBT_PUBLIC(void) smpi_exit(int); XBT_PUBLIC(unsigned int) smpi_sleep(unsigned int secs); XBT_PUBLIC(int) smpi_gettimeofday(struct timeval *tv, struct timezone *tz); -XBT_PUBLIC(void) smpi_sample_1(int global, const char *file, int line, - int iters, double threshold); +XBT_PUBLIC(int) smpi_sample_1(int global, const char *file, int line, + int iters, double threshold); XBT_PUBLIC(int) smpi_sample_2(int global, const char *file, int line); XBT_PUBLIC(void) smpi_sample_3(int global, const char *file, int line); XBT_PUBLIC(void) smpi_sample_flops(double flops); diff --git a/include/smpi/smpif.h.in b/include/smpi/smpif.h.in index 890712bff7..3e8ddf7b73 100644 --- a/include/smpi/smpif.h.in +++ b/include/smpi/smpif.h.in @@ -21,4 +21,25 @@ XBT_PUBLIC(int) smpi_process_argc(void); XBT_PUBLIC(int) smpi_process_getarg(integer* index, char* dst, ftnlen len); XBT_PUBLIC(int) smpi_global_size(void); +#define smpi_sample_local__(pi,pt) \ + { \ + if(smpi_sample_1(0, __FILE__, __LINE__, *pi, *pt)) { \ + smpi_sample_3(0, __FILE__, __LINE__); \ + } \ + if(!smpi_sample_2(0, __FILE__, __LINE__)) { \ + continue; \ + } \ + } + +#define smpi_sample_global__(pi,pt) \ + { \ + if(smpi_sample_1(1, __FILE__, __LINE__, *pi, *pt)) { \ + smpi_sample_3(1, __FILE__, __LINE__); \ + } \ + if(!smpi_sample_2(1, __FILE__, __LINE__)) { \ + continue; \ + } \ + } + + #endif diff --git a/src/smpi/smpi_bench.c b/src/smpi/smpi_bench.c index d5eb6b3e9f..e5e18b1191 100644 --- a/src/smpi/smpi_bench.c +++ b/src/smpi/smpi_bench.c @@ -104,7 +104,7 @@ static char *sample_location(int global, const char *file, int line) } } -void smpi_sample_1(int global, const char *file, int line, int iters, double threshold) +int smpi_sample_1(int global, const char *file, int line, int iters, double threshold) { char *loc = sample_location(global, file, line); local_data_t *data; @@ -123,8 +123,10 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr data->threshold = threshold; data->started = 0; xbt_dict_set(samples, loc, data, &free); + return 0; } free(loc); + return 1; } int smpi_sample_2(int global, const char *file, int line) @@ -163,18 +165,18 @@ void smpi_sample_3(int global, const char *file, int line) xbt_assert0(samples, "You did something very inconsistent, didn't you?"); data = xbt_dict_get_or_null(samples, loc); - if (!data || !data->started || data->count >= data->iters) { - xbt_assert0(data, "Please, do thing in order"); - } smpi_bench_end(); - sample = smpi_process_simulated_elapsed(); - data->sum += sample; - data->sum_pow2 += sample * sample; - n = (double)data->count; - data->mean = data->sum / n; - data->relstderr = sqrt((data->sum_pow2 / n - data->mean * data->mean) / n) / data->mean; - XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)", data->count, - data->mean, data->relstderr, sample); + if(data && data->started && data->count < data->iters) { + sample = smpi_process_simulated_elapsed(); + data->sum += sample; + data->sum_pow2 += sample * sample; + n = (double)data->count; + data->mean = data->sum / n; + data->relstderr = sqrt((data->sum_pow2 / n - data->mean * data->mean) / n) / data->mean; + XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)", data->count, + data->mean, data->relstderr, sample); + } + free(loc); } void smpi_sample_flops(double flops) diff --git a/src/smpi/smpif2c.in b/src/smpi/smpif2c.in index 1d6c4d0703..67ebfc3814 100755 --- a/src/smpi/smpif2c.in +++ b/src/smpi/smpif2c.in @@ -16,6 +16,7 @@ foreach my $fortran (@ARGV) { die "F2C failed\n" if $?; open F2C,"<$output"; my $started = 0; + my $cutext = 0; print $tmp "#ifndef INTEGER_STAR_8\n"; print $tmp "#define INTEGER_STAR_8\n"; print $tmp "#endif\n"; @@ -42,6 +43,15 @@ foreach my $fortran (@ARGV) { if(/\/\* Table of constant values \*\// || /MAIN__/) { $started = 0; } + if(/extern \/\* Subroutine \*\//) { + $cutext = 1; + } + if($cutext) { + if(/;$/) { + $cutext = 0; + } + next; + } if(/\/* Main program alias \*\/\s*int\s+.*\s*\(\s*\)\s*{(.*)}/) { $_ = "int smpi_simulated_main(int argc, char** argv) { smpi_process_init(&argc, &argv); $1 }\n"; } -- 2.20.1