X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6ee7e9c2e455536ab817ae0136acfbb53822eecd..6ebf62909fe0465d6180044f5fcc93e083c7e184:/src/smpi/smpi_bench.c diff --git a/src/smpi/smpi_bench.c b/src/smpi/smpi_bench.c index d5eb6b3e9f..9998aff42c 100644 --- a/src/smpi/smpi_bench.c +++ b/src/smpi/smpi_bench.c @@ -4,9 +4,11 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include // sqrt #include "private.h" #include "xbt/dict.h" #include "xbt/sysdep.h" +#include "xbt/ex.h" #include "surf/surf.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi, @@ -14,6 +16,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi, xbt_dict_t allocs = NULL; /* Allocated on first use */ xbt_dict_t samples = NULL; /* Allocated on first use */ +xbt_dict_t calls = NULL; /* Allocated on first use */ typedef struct { int count; @@ -33,12 +36,9 @@ typedef struct { void smpi_bench_destroy(void) { - if (allocs) { - xbt_dict_free(&allocs); - } - if (samples) { - xbt_dict_free(&samples); - } + xbt_dict_free(&allocs); + xbt_dict_free(&samples); + xbt_dict_free(&calls); } static void smpi_execute_flops(double flops) @@ -104,14 +104,14 @@ 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; smpi_bench_end(); /* Take time from previous MPI call into account */ if (!samples) { - samples = xbt_dict_new(); + samples = xbt_dict_new_homogeneous(free); } data = xbt_dict_get_or_null(samples, loc); if (!data) { @@ -122,9 +122,11 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr data->iters = iters; data->threshold = threshold; data->started = 0; - xbt_dict_set(samples, loc, data, &free); + xbt_dict_set(samples, loc, data, NULL); + return 0; } free(loc); + return 1; } int smpi_sample_2(int global, const char *file, int line) @@ -132,10 +134,10 @@ int smpi_sample_2(int global, const char *file, int line) char *loc = sample_location(global, file, line); local_data_t *data; - xbt_assert0(samples, "You did something very inconsistent, didn't you?"); + xbt_assert(samples, "You did something very inconsistent, didn't you?"); data = xbt_dict_get_or_null(samples, loc); if (!data) { - xbt_assert0(data, "Please, do thing in order"); + xbt_assert(data, "Please, do thing in order"); } if (!data->started) { if ((data->iters > 0 && data->count >= data->iters) @@ -161,20 +163,20 @@ void smpi_sample_3(int global, const char *file, int line) local_data_t *data; double sample, n; - xbt_assert0(samples, "You did something very inconsistent, didn't you?"); + xbt_assert(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) @@ -188,13 +190,13 @@ void *smpi_shared_malloc(size_t size, const char *file, int line) shared_data_t *data; if (!allocs) { - allocs = xbt_dict_new(); + allocs = xbt_dict_new_homogeneous(free); } data = xbt_dict_get_or_null(allocs, loc); if (!data) { data = (shared_data_t *) xbt_malloc0(sizeof(int) + size); data->count = 1; - xbt_dict_set(allocs, loc, data, &free); + xbt_dict_set(allocs, loc, data, NULL); } else { data->count++; } @@ -221,3 +223,50 @@ void smpi_shared_free(void *ptr) xbt_dict_remove(allocs, loc); } } + +int smpi_shared_known_call(const char* func, const char* input) { + char* loc = bprintf("%s:%s", func, input); + xbt_ex_t ex; + int known; + + if(!calls) { + calls = xbt_dict_new_homogeneous(NULL); + } + TRY { + xbt_dict_get(calls, loc); /* Succeed or throw */ + known = 1; + } + CATCH(ex) { + if(ex.category == not_found_error) { + known = 0; + xbt_ex_free(ex); + } else { + RETHROW; + } + } + free(loc); + return known; +} + +void* smpi_shared_get_call(const char* func, const char* input) { + char* loc = bprintf("%s:%s", func, input); + void* data; + + if(!calls) { + calls = xbt_dict_new_homogeneous(NULL); + } + data = xbt_dict_get(calls, loc); + free(loc); + return data; +} + +void* smpi_shared_set_call(const char* func, const char* input, void* data) { + char* loc = bprintf("%s:%s", func, input); + + if(!calls) { + calls = xbt_dict_new_homogeneous(NULL); + } + xbt_dict_set(calls, loc, data, NULL); + free(loc); + return data; +}