-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_eigen_fmm.cpp
72 lines (53 loc) · 2.14 KB
/
bench_eigen_fmm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (C) 2023 Adam Lugowski. All rights reserved.
// Use of this source code is governed by the BSD 2-clause license found in the LICENSE.txt file.
// SPDX-License-Identifier: BSD-2-Clause
#include "common.hpp"
#include <Eigen/Sparse>
#include <fast_matrix_market/app/Eigen.hpp>
typedef Eigen::SparseMatrix<VALUE_TYPE> SpMat;
/**
* Read MatrixMarket with Eigen.
*/
void eigen_read_FMM(benchmark::State& state) {
problem& prob = get_problem((int)state.range(0));
std::size_t num_bytes = 0;
for ([[maybe_unused]] auto _ : state) {
SpMat A;
std::ifstream f(prob.mm_path);
fast_matrix_market::read_matrix_market_eigen(f, A);
num_bytes += std::filesystem::file_size(prob.mm_path);
benchmark::ClobberMemory();
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
BENCHMARK(eigen_read_FMM)->Name("op:read/impl:Eigen_FMM/format:MatrixMarket")->UseRealTime()->Iterations(num_iterations)->Apply(BenchmarkArgument);
/**
* Write MatrixMarket with Eigen.
*/
void eigen_write_FMM(benchmark::State& state) {
std::size_t num_bytes = 0;
problem& prob = get_problem((int)state.range(0));
fast_matrix_market::write_options options;
options.parallel_ok = true;
options.num_threads = (int)state.range(1);
// load the problem to be written later
SpMat A;
{
std::ifstream f(prob.mm_path);
fast_matrix_market::read_matrix_market_eigen(f, A);
}
auto out_path = temporary_write_dir / ("write_" + prob.name + ".mtx");
for ([[maybe_unused]] auto _ : state) {
std::ofstream f{out_path, std::ios_base::binary};
fast_matrix_market::write_matrix_market_eigen(f, A);
num_bytes += std::filesystem::file_size(out_path);
benchmark::ClobberMemory();
}
if (delete_written_files_on_finish) {
std::filesystem::remove(out_path);
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
BENCHMARK(eigen_write_FMM)->Name("op:write/impl:Eigen_FMM/format:MatrixMarket")->UseRealTime()->Iterations(num_iterations)->Apply(BenchmarkArgument);