Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bench/direct benchmarks #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions kifmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ harness = false
name = "laplace_f64"
harness = false

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

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

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

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

[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
rustdoc-args = [ "--html-in-header", "./src/docs-header.html" ]
Expand Down
179 changes: 179 additions & 0 deletions kifmm/benches/helmholtz_direct_f32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use green_kernels::traits::Kernel;
use green_kernels::{helmholtz_3d::Helmholtz3dKernel, types::GreenKernelEvalType};
use kifmm::tree::helpers::points_fixture;
use num::{Complex, One};

Check warning on line 7 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs
use rlst::{c32, c64, rlst_dynamic_array2, RawAccess, RawAccessMut};

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, mpich, --features "strict")

unused import: `c64`

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "strict")

unused import: `c64`

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, mpich, --features "strict")

unused import: `c64`

Check failure on line 8 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "strict")

unused import: `c64`


fn multithreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Multi Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 100000;
let ntargets = 100000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];

Check warning on line 56 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber =1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 500000;
let ntargets = 500000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

fn singlethreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Single Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 5000;
let ntargets = 5000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f32>(nsources, None, None, Some(0));
let targets = points_fixture::<f32>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c32, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f32;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c32, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

criterion_group!(d_f64, multithreaded_direct_f64, singlethreaded_direct_f64);

Check warning on line 177 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f32.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f32.rs

criterion_main!(d_f64);
179 changes: 179 additions & 0 deletions kifmm/benches/helmholtz_direct_f64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use green_kernels::traits::Kernel;
use green_kernels::{helmholtz_3d::Helmholtz3dKernel, types::GreenKernelEvalType};
use kifmm::tree::helpers::points_fixture;
use num::{Complex, One};

Check warning on line 7 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 7 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs
use rlst::{c64, rlst_dynamic_array2, RawAccess, RawAccessMut};


fn multithreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Multi Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 100000;
let ntargets = 100000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];

Check warning on line 56 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 56 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber =1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 500000;
let ntargets = 500000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_mt(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

fn singlethreaded_direct_f64(c: &mut Criterion) {
let mut group = c.benchmark_group("Single Threaded Direct f64");

group
.sample_size(10)
.measurement_time(Duration::from_secs(15));

{
let nsources = 5000;
let ntargets = 5000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}

{
let nsources = 20000;
let ntargets = 20000;
let sources = points_fixture::<f64>(nsources, None, None, Some(0));
let targets = points_fixture::<f64>(ntargets, None, None, Some(1));

// FFT based M2L for a vector of charges
let nvecs = 1;
let tmp = vec![Complex::one(); nsources * nvecs];
let mut charges = rlst_dynamic_array2!(c64, [nsources, nvecs]);
charges.data_mut().copy_from_slice(&tmp);
let wavenumber = 1f64;

let kernel = Helmholtz3dKernel::new(wavenumber);

let mut result = rlst_dynamic_array2!(c64, [nsources, nvecs]);

group.bench_function(format!("N={nsources}"), |b| {
b.iter(|| {
kernel.evaluate_st(
GreenKernelEvalType::Value,
sources.data(),
targets.data(),
charges.data(),
result.data_mut(),
)
})
});
}
}

criterion_group!(d_f64, multithreaded_direct_f64, singlethreaded_direct_f64);

Check warning on line 177 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "strict")

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

Check warning on line 177 in kifmm/benches/helmholtz_direct_f64.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/kifmm/kifmm/kifmm/benches/helmholtz_direct_f64.rs

criterion_main!(d_f64);
Loading
Loading