-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmark for MatrixPowersKernel.
- Loading branch information
Showing
4 changed files
with
182 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
add_catch(test_matrix_powers_mv test.cpp) | ||
target_include_directories(test_matrix_powers_mv PRIVATE ${BASIC_LA_PATH}) | ||
target_link_libraries(test_matrix_powers_mv PRIVATE BASIC_LA) | ||
target_link_libraries(test_matrix_powers_mv PRIVATE BASIC_LA) | ||
|
||
add_catch(bench_matrix_powers_mv run.cpp) | ||
target_include_directories(bench_matrix_powers_mv PRIVATE ${BASIC_LA_PATH}) | ||
target_link_libraries(bench_matrix_powers_mv PRIVATE BASIC_LA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <matrix_powers_mv.h> | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/benchmark/catch_benchmark.hpp> | ||
|
||
void PrepareMatrix(SparseMatrix<double>& a, const size_t n) { | ||
std::stringstream file_name; | ||
file_name << std::filesystem::current_path().string() << "/../" << "matrix_examples/sparse_spd/" << n; | ||
std::ifstream fstream; | ||
fstream.open(file_name.str()); | ||
REQUIRE(fstream.is_open()); | ||
fstream >> a; | ||
fstream.close(); | ||
REQUIRE(a.data_); | ||
} | ||
|
||
TEST_CASE("Benchmark CG") { | ||
{ | ||
constexpr int64_t n = 1024; | ||
constexpr int64_t s = 512; | ||
SparseMatrix<double> a_sparse; | ||
PrepareMatrix(a_sparse, n); | ||
std::vector<Vector<double>> result(s); | ||
for (auto& single_res : result) { | ||
single_res = Vector<double>(n); | ||
} | ||
Vector<double> b; | ||
NHelpers::GenRandomVector(b, n, true); | ||
BENCHMARK("MatrixPowersMV with s=512, size=1024:") { | ||
MatrixPowersMV(a_sparse, b, result); | ||
}; | ||
|
||
BENCHMARK("Sequential MatVec's with s=512, size=1024:") { | ||
Vector<double> cur_vector = b; | ||
for (int64_t i = 1; i < s; ++i) { | ||
Vector<double> cur_result(n); | ||
a_sparse.VecMult(cur_vector, cur_result); | ||
cur_vector = std::move(cur_result); | ||
} | ||
}; | ||
} | ||
{ | ||
constexpr int64_t n = 8192; | ||
constexpr int64_t s = 4096; | ||
SparseMatrix<double> a_sparse; | ||
PrepareMatrix(a_sparse, n); | ||
std::vector<Vector<double>> result(s); | ||
for (auto& single_res : result) { | ||
single_res = Vector<double>(n); | ||
} | ||
Vector<double> b; | ||
NHelpers::GenRandomVector(b, n, true); | ||
BENCHMARK("MatrixPowersMV with s=4096, size=8192:") { | ||
MatrixPowersMV(a_sparse, b, result); | ||
}; | ||
|
||
BENCHMARK("Sequential MatVec's with s=4096, size=8192:") { | ||
Vector<double> cur_vector = b; | ||
for (int64_t i = 1; i < s; ++i) { | ||
Vector<double> cur_result(n); | ||
a_sparse.VecMult(cur_vector, cur_result); | ||
cur_vector = std::move(cur_result); | ||
} | ||
}; | ||
} | ||
{ | ||
constexpr int64_t n = 16384; | ||
constexpr int64_t s = 8192; | ||
SparseMatrix<double> a_sparse; | ||
PrepareMatrix(a_sparse, n); | ||
std::vector<Vector<double>> result(s); | ||
for (auto& single_res : result) { | ||
single_res = Vector<double>(n); | ||
} | ||
Vector<double> b; | ||
NHelpers::GenRandomVector(b, n, true); | ||
BENCHMARK("MatrixPowersMV with s=8192, size=16384:") { | ||
MatrixPowersMV(a_sparse, b, result); | ||
}; | ||
|
||
BENCHMARK("Sequential MatVec's with s=8192, size=16384:") { | ||
Vector<double> cur_vector = b; | ||
for (int64_t i = 1; i < s; ++i) { | ||
Vector<double> cur_result(n); | ||
a_sparse.VecMult(cur_vector, cur_result); | ||
cur_vector = std::move(cur_result); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters