-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_lagraph.cpp
105 lines (80 loc) · 2.92 KB
/
bench_lagraph.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// 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 <fast_matrix_market/app/GraphBLAS.hpp>
extern "C" {
#include <LAGraph.h>
}
/**
* Initialize and finalize LAGraph using a global so the rest of the code doesn't have to worry about it.
*/
struct LAGraphInitializer {
LAGraphInitializer() {
LAGraph_Init(msg);
}
~LAGraphInitializer() {
LAGraph_Finalize(msg);
}
char msg[LAGRAPH_MSG_LEN];
};
[[maybe_unused]] LAGraphInitializer lagraph_init_and_finalizer{};
/**
* Read MatrixMarket with fast_matrix_market.
*/
void GraphBLAS_read_FMM(benchmark::State& state) {
problem& prob = get_problem((int)state.range(0));
std::size_t num_bytes = 0;
for ([[maybe_unused]] auto _ : state) {
char msg[LAGRAPH_MSG_LEN];
FILE *in_file = fopen(prob.mm_path.c_str(), "r");
if (!in_file) {
std::cerr << "Could not open " << prob.mm_path << std::endl;
break;
}
GrB_Matrix mat;
LAGraph_MMRead (&mat, in_file, msg) ;
fclose(in_file);
GrB_Matrix_free(&mat);
num_bytes += std::filesystem::file_size(prob.mm_path);
benchmark::ClobberMemory();
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
BENCHMARK(GraphBLAS_read_FMM)->Name("op:read/impl:LAGraph/format:MatrixMarket")->UseRealTime()->Iterations(num_iterations)->Apply(BenchmarkArgument);
/**
* Write MatrixMarket with fast_matrix_market.
*/
void GraphBLAS_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
GrB_Matrix mat;
{
std::ifstream f(prob.mm_path);
fast_matrix_market::read_matrix_market_graphblas(f, &mat);
}
auto out_path = temporary_write_dir / ("write_" + prob.name + ".mtx");
for ([[maybe_unused]] auto _ : state) {
char msg[LAGRAPH_MSG_LEN];
FILE *out_file = fopen(out_path.c_str(), "wb");
if (!out_file) {
std::cerr << "Could not open " << out_path << std::endl;
break;
}
LAGraph_MMWrite(mat, out_file, nullptr, msg);
num_bytes += std::filesystem::file_size(out_path);
benchmark::ClobberMemory();
}
GrB_Matrix_free(&mat);
if (delete_written_files_on_finish) {
std::filesystem::remove(out_path);
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
BENCHMARK(GraphBLAS_write_FMM)->Name("op:write/impl:LAGraph/format:MatrixMarket")->UseRealTime()->Iterations(num_iterations)->Apply(BenchmarkArgument);