From e329e8ab3f3ac7e98f727ac4cac0a41851e48096 Mon Sep 17 00:00:00 2001 From: Srinath Kailasa Date: Mon, 22 Jan 2024 18:54:38 +0000 Subject: [PATCH] Fix style checks --- fmm/Cargo.toml | 18 +++++++ fmm/examples/single_node/fft.rs | 47 ++++++++++++++++++ .../matrix_svd_ia.rs} | 24 +++++----- fmm/examples/single_node/svd.rs | 48 +++++++++++++++++++ .../{single_node.rs => single_node/svd_ia.rs} | 27 +++++------ 5 files changed, 135 insertions(+), 29 deletions(-) create mode 100644 fmm/examples/single_node/fft.rs rename fmm/examples/{single_node_matrix.rs => single_node/matrix_svd_ia.rs} (81%) create mode 100644 fmm/examples/single_node/svd.rs rename fmm/examples/{single_node.rs => single_node/svd_ia.rs} (72%) diff --git a/fmm/Cargo.toml b/fmm/Cargo.toml index a8042a54..bd9c1c1a 100644 --- a/fmm/Cargo.toml +++ b/fmm/Cargo.toml @@ -40,3 +40,21 @@ rlst-dense = { git = "https://github.com/linalg-rs/rlst.git" } rlst-blis = { git = "https://github.com/linalg-rs/rlst.git" } fftw = { git = "https://github.com/skailasa/fftw.git" } rayon = "1.7" + +[[example]] +name = "single_node_fft" +path = "examples/single_node/fft.rs" + +[[example]] +name = "single_node_svd" +path = "examples/single_node/svd.rs" + + +[[example]] +name = "single_node_svd_ia" +path = "examples/single_node/svd_ia.rs" + + +[[example]] +name = "single_node_svd_ia_matrix" +path = "examples/single_node/matrix_svd_ia.rs" diff --git a/fmm/examples/single_node/fft.rs b/fmm/examples/single_node/fft.rs new file mode 100644 index 00000000..52dfcafc --- /dev/null +++ b/fmm/examples/single_node/fft.rs @@ -0,0 +1,47 @@ +//! Single Node FMM using an FFT based M2L translation operator +use std::time::Instant; + +use itertools::Itertools; + +use rlst_dense::traits::RawAccess; + +use bempp_field::types::FftFieldTranslationKiFmm; +use bempp_fmm::{ + charge::build_charge_dict, + types::{FmmDataUniform, KiFmmLinear}, +}; +use bempp_kernel::laplace_3d::Laplace3dKernel; +use bempp_traits::{fmm::FmmLoop, tree::Tree}; +use bempp_tree::implementations::helpers::points_fixture; +use bempp_tree::types::single_node::SingleNodeTree; + +fn main() { + let npoints = 10000; + + let points = points_fixture::(npoints, None, None); + + let global_idxs = (0..npoints).collect_vec(); + let charges = vec![1.0; npoints]; + + let order = 6; + let alpha_inner = 1.05; + let alpha_outer = 2.95; + let depth = 3; + + let tree = SingleNodeTree::new(points.data(), false, None, Some(depth), &global_idxs, true); + + let kernel = Laplace3dKernel::default(); + let m2l_data: FftFieldTranslationKiFmm> = + FftFieldTranslationKiFmm::new(kernel.clone(), order, *tree.get_domain(), alpha_inner); + + let fmm = KiFmmLinear::new(order, alpha_inner, alpha_outer, kernel, tree, m2l_data); + + // Form charge dict, matching charges with their associated global indices + let charge_dict = build_charge_dict(&global_idxs, &charges); + + let datatree = FmmDataUniform::new(fmm, &charge_dict).unwrap(); + + let s = Instant::now(); + let times = datatree.run(true); + println!("runtime {:?} operators {:?}", s.elapsed(), times); +} diff --git a/fmm/examples/single_node_matrix.rs b/fmm/examples/single_node/matrix_svd_ia.rs similarity index 81% rename from fmm/examples/single_node_matrix.rs rename to fmm/examples/single_node/matrix_svd_ia.rs index 75220d40..f3754f5a 100644 --- a/fmm/examples/single_node_matrix.rs +++ b/fmm/examples/single_node/matrix_svd_ia.rs @@ -1,3 +1,6 @@ +//! Single Node FMM using an SVD based M2L operator with individual SVDs found +//! for each M2L operator for an FMM taking matrix input. + use std::time::Instant; use bempp_fmm::types::FmmDataUniformMatrix; @@ -5,7 +8,7 @@ use itertools::Itertools; use rlst_dense::traits::RawAccess; -use bempp_field::types::{SvdFieldTranslationKiFmm, SvdFieldTranslationKiFmmIA}; +use bempp_field::types::SvdFieldTranslationKiFmmIA; use bempp_fmm::charge::build_charge_dict; use bempp_kernel::laplace_3d::Laplace3dKernel; use bempp_traits::{fmm::FmmLoop, tree::Tree}; @@ -13,7 +16,7 @@ use bempp_tree::implementations::helpers::points_fixture; use bempp_tree::types::single_node::SingleNodeTree; fn main() { - let npoints = 1000000; + let npoints = 10000; let global_idxs = (0..npoints).collect_vec(); @@ -24,7 +27,11 @@ fn main() { // Test matrix input let points = points_fixture::(npoints, None, None); let ncharge_vecs = 5; - let depth = 4; + let depth = 3; + + // The fraction of the total energy of each M2L matrix as measured by the + // square sum of the singular values retained after compression. + let threshold = 0.9999; let mut charge_mat = vec![vec![0.0; npoints]; ncharge_vecs]; charge_mat @@ -38,18 +45,9 @@ fn main() { // Create a tree let tree = SingleNodeTree::new(points.data(), false, None, Some(depth), &global_idxs, true); - // Precompute the M2L data - // let m2l_data = SvdFieldTranslationKiFmm::new( - // kernel.clone(), - // Some(80), - // order, - // *tree.get_domain(), - // alpha_inner, - // ); - let m2l_data = SvdFieldTranslationKiFmmIA::new( kernel.clone(), - 0.9999, + threshold, order, *tree.get_domain(), alpha_inner, diff --git a/fmm/examples/single_node/svd.rs b/fmm/examples/single_node/svd.rs new file mode 100644 index 00000000..058c9403 --- /dev/null +++ b/fmm/examples/single_node/svd.rs @@ -0,0 +1,48 @@ +//! Single Node FMM using an SVD based M2L translation operator +use std::time::Instant; + +use itertools::Itertools; + +use rlst_dense::traits::RawAccess; + +use bempp_field::types::SvdFieldTranslationKiFmm; +use bempp_fmm::{ + charge::build_charge_dict, + types::{FmmDataUniform, KiFmmLinear}, +}; +use bempp_kernel::laplace_3d::Laplace3dKernel; +use bempp_traits::{fmm::FmmLoop, tree::Tree}; +use bempp_tree::implementations::helpers::points_fixture; +use bempp_tree::types::single_node::SingleNodeTree; + +fn main() { + let npoints = 10000; + + let points = points_fixture::(npoints, None, None); + + let global_idxs = (0..npoints).collect_vec(); + let charges = vec![1.0; npoints]; + + let order = 6; + let alpha_inner = 1.05; + let alpha_outer = 2.95; + let depth = 3; + + let tree = SingleNodeTree::new(points.data(), false, None, Some(depth), &global_idxs, true); + + let kernel = Laplace3dKernel::default(); + + let m2l_data = + SvdFieldTranslationKiFmm::new(kernel.clone(), None, order, *tree.get_domain(), alpha_inner); + + let fmm = KiFmmLinear::new(order, alpha_inner, alpha_outer, kernel, tree, m2l_data); + + // Form charge dict, matching charges with their associated global indices + let charge_dict = build_charge_dict(&global_idxs, &charges); + + let datatree = FmmDataUniform::new(fmm, &charge_dict).unwrap(); + + let s = Instant::now(); + let times = datatree.run(true); + println!("runtime {:?} operators {:?}", s.elapsed(), times); +} diff --git a/fmm/examples/single_node.rs b/fmm/examples/single_node/svd_ia.rs similarity index 72% rename from fmm/examples/single_node.rs rename to fmm/examples/single_node/svd_ia.rs index 042c2347..8adda991 100644 --- a/fmm/examples/single_node.rs +++ b/fmm/examples/single_node/svd_ia.rs @@ -1,12 +1,13 @@ +//! Single Node FMM using an SVD based M2L operator with individual SVDs found +//! for each M2L operator for an FMM taking vector input. + use std::time::Instant; use itertools::Itertools; use rlst_dense::traits::RawAccess; -use bempp_field::types::{ - FftFieldTranslationKiFmm, SvdFieldTranslationKiFmm, SvdFieldTranslationKiFmmIA, -}; +use bempp_field::types::SvdFieldTranslationKiFmmIA; use bempp_fmm::{ charge::build_charge_dict, types::{FmmDataUniform, KiFmmLinear}, @@ -17,7 +18,7 @@ use bempp_tree::implementations::helpers::points_fixture; use bempp_tree::types::single_node::SingleNodeTree; fn main() { - let npoints = 1000000; + let npoints = 10000; let points = points_fixture::(npoints, None, None); @@ -27,25 +28,19 @@ fn main() { let order = 6; let alpha_inner = 1.05; let alpha_outer = 2.95; - let depth = 4; + let depth = 3; + + // The fraction of the total energy of each M2L matrix as measured by the + // square sum of the singular values retained after compression. + let threshold = 0.9999; let tree = SingleNodeTree::new(points.data(), false, None, Some(depth), &global_idxs, true); let kernel = Laplace3dKernel::default(); - let m2l_data: FftFieldTranslationKiFmm> = - FftFieldTranslationKiFmm::new(kernel.clone(), order, *tree.get_domain(), alpha_inner); - - // let m2l_data = SvdFieldTranslationKiFmm::new( - // kernel.clone(), - // Some(80), - // order, - // *tree.get_domain(), - // alpha_inner, - // ); let m2l_data = SvdFieldTranslationKiFmmIA::new( kernel.clone(), - 0.9999, + threshold, order, *tree.get_domain(), alpha_inner,