From 12addefb351a73d25c61a4722ee308a3311727c5 Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 6 May 2025 13:24:04 +0200 Subject: [PATCH] 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();