Commit d054e1ab by FritzFlorian

Add fib benchmark.

parent 79ac0243
Pipeline #1373 failed with stages
in 39 seconds
......@@ -42,6 +42,7 @@ add_subdirectory(app/benchmark_unbalanced)
add_subdirectory(app/benchmark_matrix)
add_subdirectory(app/benchmark_prefix)
add_subdirectory(app/benchmark_pipeline)
add_subdirectory(app/benchmark_fib)
# Add optional tests
option(PACKAGE_TESTS "Build the tests" ON)
......
add_executable(benchmark_fib_pls_v2 main.cpp)
target_link_libraries(benchmark_fib_pls_v2 pls benchmark_runner benchmark_base)
if (EASY_PROFILER)
target_link_libraries(benchmark_fib_pls_v2 easy_profiler)
endif ()
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/parallel_result.h"
#include "pls/internal/scheduling/scheduler_memory.h"
#include "pls/internal/helpers/profiler.h"
using namespace pls::internal::scheduling;
#include <iostream>
#include <complex>
#include <vector>
#include "benchmark_runner.h"
#include "benchmark_base/fib.h"
using namespace comparison_benchmarks::base;
parallel_result<int> pls_fib(int n) {
if (n <= 1) {
return parallel_result<int>{1};
}
return scheduler::par([=]() {
return pls_fib(n - 1);
}, [=]() {
return pls_fib(n - 2);
}).then([=](int a, int b) {
return parallel_result<int>{a + b};
});
}
constexpr int MAX_NUM_THREADS = 8;
constexpr int MAX_NUM_TASKS = 64;
constexpr int MAX_NUM_CONTS = 64;
constexpr int MAX_CONT_SIZE = 256;
int main(int argc, char **argv) {
int num_threads;
string directory;
benchmark_runner::read_args(argc, argv, num_threads, directory);
string test_name = to_string(num_threads) + ".csv";
string full_directory = directory + "/PLS_v2/";
benchmark_runner runner{full_directory, test_name};
static_scheduler_memory<MAX_NUM_THREADS,
MAX_NUM_TASKS,
MAX_NUM_CONTS,
MAX_CONT_SIZE> static_scheduler_memory;
scheduler scheduler{static_scheduler_memory, (unsigned int) num_threads};
volatile int res;
for (int i = 0; i < fib::NUM_WARMUP_ITERATIONS; i++) {
scheduler.perform_work([&]() {
return scheduler::par([&]() {
return pls_fib(fib::INPUT_N);
}, []() {
return parallel_result<int>{0};
}).then([&](int result, int) {
res = result;
return parallel_result<int>{0};
});
});
}
for (int i = 0; i < fib::NUM_ITERATIONS; i++) {
scheduler.perform_work([&]() {
runner.start_iteration();
return scheduler::par([&]() {
return pls_fib(fib::INPUT_N);
}, []() {
return parallel_result<int>{0};
}).then([&](int result, int) {
res = result;
runner.end_iteration();
return parallel_result<int>{0};
});
});
}
runner.commit_results(true);
return 0;
}
......@@ -7,7 +7,8 @@ add_library(benchmark_base STATIC
include/benchmark_base/heat.h
include/benchmark_base/matrix.h
include/benchmark_base/unbalanced.h src/unbalanced.cpp
include/benchmark_base/range.h)
include/benchmark_base/range.h
include/benchmark_base/fib.h)
target_include_directories(benchmark_base
PUBLIC
......
#ifndef COMPARISON_BENCHMARKS_BASE_FIB_H_
#define COMPARISON_BENCHMARKS_BASE_FIB_H_
namespace comparison_benchmarks {
namespace base {
namespace fib {
const int INPUT_N = 18;
const int NUM_ITERATIONS = 1000;
const int NUM_WARMUP_ITERATIONS = 100;
}
}
}
#endif //COMPARISON_BENCHMARKS_BASE_FIB_H_
......@@ -40,9 +40,7 @@ class matrix {
}
for (int k = 0; k < SIZE; ++k) {
for (int j = 0; j < SIZE; ++j) {
T a_data = a.data[i][k];
T b_data = b.data[k][j];
data[i][j] += a_data * b_data;
data[i][j] += a.data[i][k] * b.data[k][j];
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment