From 0122fe3fb5f5610a68eacdaabc4dec96ca408516 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 6 Jul 2020 10:22:16 +0200 Subject: [PATCH] Suppress global variable. --- teshsuite/xbt/parmap_bench/parmap_bench.cpp | 22 +++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/teshsuite/xbt/parmap_bench/parmap_bench.cpp b/teshsuite/xbt/parmap_bench/parmap_bench.cpp index 1270071fde..c57a9b1877 100644 --- a/teshsuite/xbt/parmap_bench/parmap_bench.cpp +++ b/teshsuite/xbt/parmap_bench/parmap_bench.cpp @@ -19,8 +19,6 @@ constexpr unsigned MODES_DEFAULT = 0x7; constexpr unsigned ARRAY_SIZE = 10007; constexpr unsigned FIBO_MAX = 25; -void (*fun_to_apply)(unsigned*); - static std::string parmap_mode_name(e_xbt_parmap_mode_t mode) { std::string name; @@ -62,7 +60,8 @@ static void fun_big_comp(unsigned* arg) *arg = fibonacci(*arg % FIBO_MAX); } -static void bench_parmap(int nthreads, double timeout, e_xbt_parmap_mode_t mode, bool full_bench) +template +void bench_parmap(int nthreads, double timeout, e_xbt_parmap_mode_t mode, bool full_bench, F func_to_apply) { std::string mode_name = parmap_mode_name(mode); XBT_INFO("** mode = %s", mode_name.c_str()); @@ -86,7 +85,7 @@ static void bench_parmap(int nthreads, double timeout, e_xbt_parmap_mode_t mode, delete parmap; parmap = new simgrid::xbt::Parmap(nthreads, mode); } - parmap->apply(fun_to_apply, data); + parmap->apply(func_to_apply, data); elapsed_time = xbt_os_time() - start_time; i++; } while (elapsed_time < timeout); @@ -95,14 +94,14 @@ static void bench_parmap(int nthreads, double timeout, e_xbt_parmap_mode_t mode, XBT_INFO(" ran %d times in %g seconds (%g/s)", i, elapsed_time, i / elapsed_time); } -static void bench_all_modes(int nthreads, double timeout, unsigned modes, bool full_bench) +template void bench_all_modes(int nthreads, double timeout, unsigned modes, bool full_bench, F func_to_apply) { std::vector all_modes = {XBT_PARMAP_POSIX, XBT_PARMAP_FUTEX, XBT_PARMAP_BUSY_WAIT, XBT_PARMAP_DEFAULT}; for (unsigned i = 0; i < all_modes.size(); i++) { if (1U << i & modes) - bench_parmap(nthreads, timeout, all_modes[i], full_bench); + bench_parmap(nthreads, timeout, all_modes[i], full_bench, func_to_apply); } } @@ -135,24 +134,21 @@ int main(int argc, char* argv[]) XBT_INFO("%s", ""); SIMIX_context_set_nthreads(nthreads); - fun_to_apply = &fun_small_comp; XBT_INFO("Benchmark for parmap create+apply+destroy (small comp):"); - bench_all_modes(nthreads, timeout, modes, true); + bench_all_modes(nthreads, timeout, modes, true, &fun_small_comp); XBT_INFO("%s", ""); XBT_INFO("Benchmark for parmap apply only (small comp):"); - bench_all_modes(nthreads, timeout, modes, false); + bench_all_modes(nthreads, timeout, modes, false, &fun_small_comp); XBT_INFO("%s", ""); - fun_to_apply = &fun_big_comp; - XBT_INFO("Benchmark for parmap create+apply+destroy (big comp):"); - bench_all_modes(nthreads, timeout, modes, true); + bench_all_modes(nthreads, timeout, modes, true, &fun_big_comp); XBT_INFO("%s", ""); XBT_INFO("Benchmark for parmap apply only (big comp):"); - bench_all_modes(nthreads, timeout, modes, false); + bench_all_modes(nthreads, timeout, modes, false, &fun_big_comp); XBT_INFO("%s", ""); return EXIT_SUCCESS; -- 2.20.1