/* 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 "src/internal_config.h" // HAVE_FUTEX_H
/* 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 "src/internal_config.h" // HAVE_FUTEX_H
-#define MODES_DEFAULT 0x7
-#define ARRAY_SIZE 10007
-#define FIBO_MAX 25
-
-void (*fun_to_apply)(unsigned*);
+constexpr unsigned MODES_DEFAULT = 0x7;
+constexpr unsigned ARRAY_SIZE = 10007;
+constexpr unsigned FIBO_MAX = 25;
-static void bench_parmap(int nthreads, double timeout, e_xbt_parmap_mode_t mode, bool full_bench)
+template <class F>
+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());
{
std::string mode_name = parmap_mode_name(mode);
XBT_INFO("** mode = %s", mode_name.c_str());
XBT_INFO(" ran %d times in %g seconds (%g/s)", i, elapsed_time, i / elapsed_time);
}
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 <class F> void bench_all_modes(int nthreads, double timeout, unsigned modes, bool full_bench, F func_to_apply)
{
std::vector<e_xbt_parmap_mode_t> 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)
{
std::vector<e_xbt_parmap_mode_t> 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);
if (argc != 3 && argc != 4) {
XBT_INFO("Usage: %s nthreads timeout [modes]", argv[0]);
if (argc != 3 && argc != 4) {
XBT_INFO("Usage: %s nthreads timeout [modes]", argv[0]);
- bench_all_modes(nthreads, timeout, modes, true);
+ bench_all_modes(nthreads, timeout, modes, true, &fun_small_comp);
- bench_all_modes(nthreads, timeout, modes, false);
+ bench_all_modes(nthreads, timeout, modes, false, &fun_small_comp);
- bench_all_modes(nthreads, timeout, modes, true);
+ bench_all_modes(nthreads, timeout, modes, true, &fun_big_comp);
- bench_all_modes(nthreads, timeout, modes, false);
+ bench_all_modes(nthreads, timeout, modes, false, &fun_big_comp);