From 12addefb351a73d25c61a4722ee308a3311727c5 Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 6 May 2025 13:24:04 +0200 Subject: [PATCH 1/3] add benchmark --- lab07/gaus_seidel/gaus_seidel.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/lab07/gaus_seidel/gaus_seidel.cpp b/lab07/gaus_seidel/gaus_seidel.cpp index b7281bb..4de0978 100644 --- a/lab07/gaus_seidel/gaus_seidel.cpp +++ b/lab07/gaus_seidel/gaus_seidel.cpp @@ -1,4 +1,5 @@ #include "matrix.h" +#include #include #include @@ -25,7 +26,7 @@ void gauss_seidel_par(Matrix &phi, int maxNumIter) { const double osth = 1. / 4; for (int iter = 0; iter < maxNumIter; ++iter) { -#pragma omp parallel num_threads(3) +#pragma omp parallel num_threads(10) { int num_theads = omp_get_num_threads(); int chunk = (m - 2) / num_theads; @@ -95,23 +96,15 @@ void print_matrix(const Matrix &matrix) { } } -int main() { - Matrix first = Matrix(8, 8); - Matrix sec = Matrix(8, 8); +void benchmarkgaus_seidel(benchmark::State &state) { + Matrix matrix = Matrix(1000, 1000); + fill_matrix(matrix, 10); - fill_matrix(first, 10); - fill_matrix(sec, 10); - - print_matrix(first); - print_matrix(sec); - - gauss_seidel(first, 12); - gauss_seidel_par(sec, 12); - - check(first, sec); - - print_matrix(first); - print_matrix(sec); - - return 0; + for (auto _ : state) { + gauss_seidel(matrix, 10000); + benchmark::DoNotOptimize(matrix); + } } + +BENCHMARK(benchmarkgaus_seidel)->Unit(benchmark::kMillisecond); +BENCHMARK_MAIN(); From ee2efe938a9c171b776c950907de7db065010e73 Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 6 May 2025 13:27:42 +0200 Subject: [PATCH 2/3] add benchmark --- lab07/gaus_seidel/gaus_seidel.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lab07/gaus_seidel/gaus_seidel.cpp b/lab07/gaus_seidel/gaus_seidel.cpp index 4de0978..72b4f81 100644 --- a/lab07/gaus_seidel/gaus_seidel.cpp +++ b/lab07/gaus_seidel/gaus_seidel.cpp @@ -96,15 +96,28 @@ void print_matrix(const Matrix &matrix) { } } -void benchmarkgaus_seidel(benchmark::State &state) { +void benchmarkComputeResult(benchmark::State &state) { + int iterations = state.range(0); Matrix matrix = Matrix(1000, 1000); + fill_matrix(matrix, 10); for (auto _ : state) { - gauss_seidel(matrix, 10000); + gauss_seidel(sec, iterations); benchmark::DoNotOptimize(matrix); } } -BENCHMARK(benchmarkgaus_seidel)->Unit(benchmark::kMillisecond); -BENCHMARK_MAIN(); +int main(int argc, char** argv)) { + ::benchmark::Initialize(&argc, argv); + + for (int iterations = 0; iterations < 10000; iterations++) { + benchmark::RegisterBenchmark("bench_gaus_seidel", benchmarkComputeResult) + ->Arg(iterations) + ->Unit(benchmark::kMillisecond); + } + + ::benchmark::RunSpecifiedBenchmarks(); + + return 0; +} From 15e7705c45d8d0c86f7a99b549952ee3d4d7f1e0 Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 6 May 2025 13:28:17 +0200 Subject: [PATCH 3/3] fix --- lab07/gaus_seidel/gaus_seidel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lab07/gaus_seidel/gaus_seidel.cpp b/lab07/gaus_seidel/gaus_seidel.cpp index 72b4f81..ebfc817 100644 --- a/lab07/gaus_seidel/gaus_seidel.cpp +++ b/lab07/gaus_seidel/gaus_seidel.cpp @@ -103,12 +103,12 @@ void benchmarkComputeResult(benchmark::State &state) { fill_matrix(matrix, 10); for (auto _ : state) { - gauss_seidel(sec, iterations); + gauss_seidel(matrix, iterations); benchmark::DoNotOptimize(matrix); } } -int main(int argc, char** argv)) { +int main(int argc, char **argv) { ::benchmark::Initialize(&argc, argv); for (int iterations = 0; iterations < 10000; iterations++) {