Skip to content

Commit

Permalink
Add assembly benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Oct 10, 2023
1 parent 1669d8f commit 14b1f82
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
8 changes: 8 additions & 0 deletions bem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ itertools = "0.10"
mpi = { version = "0.6.*", optional = true }
num = "0.4"
rayon = "1.7"

[dev-dependencies]
criterion = "0.3"

[[bench]]
name = "assembly_benchmark"
harness = false

52 changes: 52 additions & 0 deletions bem/benches/assembly_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use bempp_bem::assembly::{assemble_batched, BoundaryOperator, PDEType};
use bempp_bem::function_space::SerialFunctionSpace;
use bempp_element::element::create_element;
use bempp_grid::shapes::regular_sphere;
use bempp_tools::arrays::Array2D;
use bempp_traits::bem::DofMap;
use bempp_traits::bem::FunctionSpace;
use bempp_traits::cell::ReferenceCellType;
use bempp_traits::element::{Continuity, ElementFamily};
use criterion::{criterion_group, criterion_main, Criterion};

pub fn assembly_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("assembly");
group.sample_size(10);

for i in 3..5 {
let grid = regular_sphere(i);
let element = create_element(
ElementFamily::Lagrange,
ReferenceCellType::Triangle,
0,
Continuity::Discontinuous,
);

let space = SerialFunctionSpace::new(&grid, &element);
let mut matrix =
Array2D::<f64>::new((space.dofmap().global_size(), space.dofmap().global_size()));

group.bench_function(
&format!(
"Assembly of {}x{} matrix",
space.dofmap().global_size(),
space.dofmap().global_size()
),
|b| {
b.iter(|| {
assemble_batched(
&mut matrix,
BoundaryOperator::SingleLayer,
PDEType::Laplace,
&space,
&space,
)
})
},
);
}
group.finish();
}

criterion_group!(benches, assembly_benchmark);
criterion_main!(benches);
2 changes: 0 additions & 2 deletions bem/examples/assembly_timing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: use Criterion to benchmark properly

use bempp_bem::assembly::{assemble_batched, BoundaryOperator, PDEType};
use bempp_bem::function_space::SerialFunctionSpace;
use bempp_element::element::create_element;
Expand Down
10 changes: 5 additions & 5 deletions bem/src/assembly/batched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bempp_traits::element::FiniteElement;
use bempp_traits::grid::{Geometry, Grid, Topology};
use bempp_traits::types::Scalar;
use rayon::prelude::*;
use std::time::Instant;
//use std::time::Instant;

fn get_quadrature_rule(
test_celltype: ReferenceCellType,
Expand Down Expand Up @@ -334,7 +334,7 @@ pub fn assemble<'a>(
trial_space: &SerialFunctionSpace<'a>,
test_space: &SerialFunctionSpace<'a>,
) {
let now = Instant::now();
// let now = Instant::now();
// Note: currently assumes that the two grids are the same
// TODO: implement == and != for grids, then add:
// if *trial_space.grid() != *test_space.grid() {
Expand Down Expand Up @@ -440,8 +440,8 @@ pub fn assemble<'a>(
}
}

println!("Non-adjacent terms: {}ms", now.elapsed().as_millis());
let now = Instant::now();
// println!("Non-adjacent terms: {}ms", now.elapsed().as_millis());
// let now = Instant::now();

if test_space.grid() != trial_space.grid() {
// If the test and trial grids are different, there are no neighbouring triangles
Expand Down Expand Up @@ -572,7 +572,7 @@ pub fn assemble<'a>(
}
}
}
println!("Singular terms: {}ms", now.elapsed().as_millis());
// println!("Singular terms: {}ms", now.elapsed().as_millis());
}
#[cfg(test)]
mod test {
Expand Down

0 comments on commit 14b1f82

Please sign in to comment.