add benches for sparse matrix multiplication
This commit is contained in:
parent
0c8b02b466
commit
8d90d8106d
|
@ -45,6 +45,72 @@ fn performance_benchmark(c: &mut Criterion) {
|
|||
b.iter(|| operators::SBP8.diffeta(x.view(), res.view_mut()))
|
||||
});
|
||||
|
||||
#[cfg(feature = "sparse")]
|
||||
{
|
||||
use sbp::utils::kronecker_product;
|
||||
|
||||
fn make_operators(
|
||||
op: impl SbpOperator2d,
|
||||
nx: usize,
|
||||
ny: usize,
|
||||
) -> (sprs::CsMat<Float>, sprs::CsMat<Float>) {
|
||||
let dx = op.op_xi().diff_matrix(nx);
|
||||
let dx = kronecker_product(sprs::CsMat::eye(ny).view(), dx.view());
|
||||
|
||||
let dy = op.op_eta().diff_matrix(ny);
|
||||
let dy = kronecker_product(dy.view(), sprs::CsMat::eye(nx).view());
|
||||
|
||||
(dy, dx)
|
||||
}
|
||||
|
||||
{
|
||||
let (dy, dx) = make_operators(operators::Upwind4, w, h);
|
||||
group.bench_function("upwind4 diffxi matrix", |b| {
|
||||
let mut res = ndarray::Array2::zeros(x.raw_dim());
|
||||
b.iter(|| {
|
||||
sprs::prod::mul_acc_mat_vec_csr(
|
||||
dx.view(),
|
||||
x.as_slice().unwrap(),
|
||||
res.as_slice_mut().unwrap(),
|
||||
)
|
||||
})
|
||||
});
|
||||
group.bench_function("upwind4 diffeta matrix", |b| {
|
||||
let mut res = ndarray::Array2::zeros(x.raw_dim());
|
||||
b.iter(|| {
|
||||
sprs::prod::mul_acc_mat_vec_csr(
|
||||
dy.view(),
|
||||
x.as_slice().unwrap(),
|
||||
res.as_slice_mut().unwrap(),
|
||||
)
|
||||
})
|
||||
});
|
||||
}
|
||||
{
|
||||
let (dy, dx) = make_operators(operators::Upwind9, w, h);
|
||||
group.bench_function("upwind9 diffxi matrix", |b| {
|
||||
let mut res = ndarray::Array2::zeros(x.raw_dim());
|
||||
b.iter(|| {
|
||||
sprs::prod::mul_acc_mat_vec_csr(
|
||||
dx.view(),
|
||||
x.as_slice().unwrap(),
|
||||
res.as_slice_mut().unwrap(),
|
||||
)
|
||||
})
|
||||
});
|
||||
group.bench_function("upwind9 diffeta matrix", |b| {
|
||||
let mut res = ndarray::Array2::zeros(x.raw_dim());
|
||||
b.iter(|| {
|
||||
sprs::prod::mul_acc_mat_vec_csr(
|
||||
dy.view(),
|
||||
x.as_slice().unwrap(),
|
||||
res.as_slice_mut().unwrap(),
|
||||
)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue