Skip to content

Commit

Permalink
Merge pull request #190 from InteractiveComputerGraphics/dense_subdom…
Browse files Browse the repository at this point in the history
…ains

Optimizations for grid-based dense subdomains
  • Loading branch information
w1th0utnam3 committed Jul 11, 2023
2 parents 8a7750b + e1c75d3 commit d44e7ca
Show file tree
Hide file tree
Showing 10 changed files with 948 additions and 69 deletions.
82 changes: 41 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions splashsurf/src/reconstruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Switch {

/// Executes the `reconstruct` subcommand
pub fn reconstruct_subcommand(cmd_args: &ReconstructSubcommandArgs) -> Result<(), anyhow::Error> {
profile!("reconstruct CLI");
profile!("reconstruct subcommand");

let paths = ReconstructionRunnerPathCollection::try_from(cmd_args)
.context("Failed parsing input file path(s) from command line")?
Expand Down Expand Up @@ -816,7 +816,7 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
io_params: &io::FormatParameters,
check_mesh: bool,
) -> Result<(), anyhow::Error> {
profile!("surface reconstruction cli");
profile!("surface reconstruction");

// Load particle positions and attributes to interpolate
let (particle_positions, attributes) = io::read_particle_positions_with_attributes(
Expand Down
117 changes: 117 additions & 0 deletions splashsurf_lib/benches/benches/bench_subdomain_grid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use criterion::{criterion_group, Criterion, SamplingMode};
use nalgebra::Vector3;
use splashsurf_lib::io::particles_from_file;
use splashsurf_lib::{reconstruct_surface, Parameters, SurfaceReconstruction};
use std::time::Duration;

fn parameters_canyon() -> Parameters<f32> {
let particle_radius = 0.011;
let compact_support_radius = 4.0 * particle_radius;
let cube_size = 1.5 * particle_radius;

let parameters = Parameters {
particle_radius,
rest_density: 1000.0,
compact_support_radius,
cube_size,
iso_surface_threshold: 0.6,
domain_aabb: None,
enable_multi_threading: true,
subdomain_num_cubes_per_dim: Some(32),
spatial_decomposition: None,
};

parameters
}

pub fn grid_canyon(c: &mut Criterion) {
let particle_positions: &Vec<Vector3<f32>> = &particles_from_file("C:\\canyon.xyz").unwrap();
let parameters = parameters_canyon();

let mut group = c.benchmark_group("grid_canyon");
group.sample_size(10);
group.sampling_mode(SamplingMode::Flat);
group.warm_up_time(Duration::from_secs(10));
group.measurement_time(Duration::from_secs(120));

let mut reconstruction = SurfaceReconstruction::default();

group.bench_function("canyon_c_1_50_nc_32", |b| {
b.iter(|| {
let mut parameters = parameters.clone();
parameters.cube_size = 1.5 * parameters.particle_radius;
parameters.subdomain_num_cubes_per_dim = Some(32);
reconstruction =
reconstruct_surface::<i64, _>(particle_positions.as_slice(), &parameters).unwrap()
})
});

group.bench_function("canyon_c_1_00_nc_48", |b| {
b.iter(|| {
let mut parameters = parameters.clone();
parameters.cube_size = 1.0 * parameters.particle_radius;
parameters.subdomain_num_cubes_per_dim = Some(48);
reconstruction =
reconstruct_surface::<i64, _>(particle_positions.as_slice(), &parameters).unwrap()
})
});

group.bench_function("canyon_c_0_75_nc_64", |b| {
b.iter(|| {
let mut parameters = parameters.clone();
parameters.cube_size = 0.75 * parameters.particle_radius;
parameters.subdomain_num_cubes_per_dim = Some(48);
reconstruction =
reconstruct_surface::<i64, _>(particle_positions.as_slice(), &parameters).unwrap()
})
});
}

pub fn grid_optimal_num_cubes_canyon(c: &mut Criterion) {
let particle_positions: &Vec<Vector3<f32>> = &particles_from_file("C:\\canyon.xyz").unwrap();
let mut parameters = parameters_canyon();

let mut with_cube_factor = |cube_factor: f32, num_cubes: &[u32]| {
parameters.cube_size = cube_factor * parameters.particle_radius;

let mut group = c.benchmark_group(format!(
"grid_optimal_num_cubes_canyon_c_{}",
format!("{:.2}", cube_factor).replace('.', "_")
));
group.sample_size(10);
group.sampling_mode(SamplingMode::Flat);
group.warm_up_time(Duration::from_secs(10));
group.measurement_time(Duration::from_secs(120));

let mut reconstruction = SurfaceReconstruction::default();

let mut gen_test = |num_cubes: u32| {
group.bench_function(format!("subdomain_num_cubes_{}", num_cubes), |b| {
b.iter(|| {
let mut parameters = parameters.clone();
parameters.subdomain_num_cubes_per_dim = Some(num_cubes);
reconstruction =
reconstruct_surface::<i64, _>(particle_positions.as_slice(), &parameters)
.unwrap()
})
});
};

for &n in num_cubes {
gen_test(n);
}

group.finish();
};

with_cube_factor(1.5, &[18, 24, 28, 32, 40, 48, 56, 64, 68, 72]); // Ideal: 32
with_cube_factor(1.0, &[24, 28, 32, 40, 48, 56, 64, 68, 72]); // Ideal: 48
with_cube_factor(0.75, &[32, 40, 48, 56, 64, 68, 72]); // Ideal: 64
with_cube_factor(0.5, &[40, 48, 56, 64, 68, 72, 78, 82, 96]); // Ideal: 82
}

criterion_group!(
bench_subdomain_grid,
grid_canyon,
grid_optimal_num_cubes_canyon
);
1 change: 1 addition & 0 deletions splashsurf_lib/benches/benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod bench_full;
pub mod bench_mesh;
pub mod bench_neighborhood;
pub mod bench_octree;
pub mod bench_subdomain_grid;
Loading

0 comments on commit d44e7ca

Please sign in to comment.