Skip to content

Commit

Permalink
Respond to clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
skailasa committed Dec 2, 2023
1 parent 39a2254 commit ab14f76
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 216 deletions.
1 change: 0 additions & 1 deletion field/src/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use num::Complex;
use rayon::prelude::*;

use crate::types::{FftMatrixc32, FftMatrixc64, FftMatrixf32, FftMatrixf64};
use rlst::dense::RawAccessMut;

pub trait Fft<DtypeReal, DtypeCplx>
where
Expand Down
4 changes: 2 additions & 2 deletions fmm/src/field_translation/hashmap/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
/// Point to multipole evaluations, multithreaded over each leaf box.
fn p2m<'a>(&self) {
if let Some(leaves) = self.fmm.tree().get_all_leaves() {
leaves.par_iter().enumerate().for_each(move |(i, &leaf)| {
leaves.par_iter().for_each(move |&leaf| {

let leaf_multipole_arc = Arc::clone(self.multipoles.get(&leaf).unwrap());

Expand Down Expand Up @@ -199,7 +199,7 @@ mod test {
EvalType::Value,
&surface,
&test_point,
&multipole.lock().unwrap().data(),
multipole.lock().unwrap().data(),
&mut found,
);

Expand Down
9 changes: 1 addition & 8 deletions fmm/src/field_translation/hashmap/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ where
rlst_pointer_mat!['a, V, source_coordinates.as_ptr(), (nsources, self.fmm.kernel.space_dimension()), (self.fmm.kernel.space_dimension(), 1)]
}.eval();

// if target.morton == 3 {
// println!("SOURCES {:?}", source_coordinates.data());
// }

let source_charges_arc =
Arc::clone(self.charges.get(source).unwrap());

Expand All @@ -263,15 +259,12 @@ where
let mut target_potential_lock =
target_potential_arc.lock().unwrap();

// if target.morton == 3 {
// println!("TARGETS {:?}", target_coordinates.data());
// }
*target_potential_lock.deref_mut() = (target_potential_lock.deref() + target_potential).eval();
}
}


let mut target_potential_lock =
let target_potential_lock =
target_potential_arc.lock().unwrap();

if target.morton == 3 {
Expand Down
17 changes: 9 additions & 8 deletions fmm/src/field_translation/linear/source.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! kiFMM based on simple linear data structures that minimises memory allocations, maximises cache re-use.
use itertools::Itertools;
use num::Float;
use rayon::prelude::*;

Expand Down Expand Up @@ -63,11 +62,11 @@ where
check_potentials
.data_mut()
.par_chunks_exact_mut(ncoeffs)
.enumerate()
// .enumerate()
.zip(self.leaf_upward_surfaces.par_chunks_exact(surface_size))
.zip(&self.charge_index_pointer)
.for_each(
|(((i, check_potential), upward_check_surface), charge_index_pointer)| {
|((check_potential, upward_check_surface), charge_index_pointer)| {
let charges = &self.charges[charge_index_pointer.0..charge_index_pointer.1];
let coordinates = &coordinates
[charge_index_pointer.0 * dim..charge_index_pointer.1 * dim];
Expand Down Expand Up @@ -106,8 +105,8 @@ where
let tmp = (self.fmm.uc2e_inv_1.dot(&self.fmm.uc2e_inv_2.dot(&check_potential.cmp_wise_product(&scale)))).eval();

unsafe {
for i in 0..chunk_size {
let mut ptr = multipole_ptrs[i].raw;
for (i, multipole_ptr) in multipole_ptrs.iter().enumerate().take(chunk_size) {
let mut ptr = multipole_ptr.raw;
for j in 0..ncoeffs {
*ptr += tmp.data()[i*ncoeffs+j];
ptr = ptr.add(1);
Expand Down Expand Up @@ -148,8 +147,8 @@ where
let tmp = rlst_pointer_mat!['a, V, multipole_chunk.as_ptr(), (ncoeffs*nsiblings, chunk_size), (1, ncoeffs*nsiblings)];
let tmp = self.fmm.m2m.dot(&tmp).eval();

for i in 0..chunk_size {
let mut ptr = parent[i].raw;
for (i, par) in parent.iter().enumerate().take(chunk_size) {
let mut ptr = par.raw;
for j in 0..ncoeffs {
*ptr += tmp.data()[(i*ncoeffs)+j];
ptr = ptr.add(1)
Expand All @@ -166,6 +165,8 @@ mod test {

use super::*;

use itertools::Itertools;

use crate::charge::build_charge_dict;
use bempp_field::types::SvdFieldTranslationKiFmm;
use bempp_kernel::laplace_3d::Laplace3dKernel;
Expand Down Expand Up @@ -246,7 +247,7 @@ mod test {
EvalType::Value,
&surface,
&test_point,
&multipole,
multipole,
&mut found,
);

Expand Down
82 changes: 14 additions & 68 deletions fmm/src/field_translation/linear/source_to_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub unsafe fn matmul8x8x2_cplx_simple_local<U>(
.for_each(|(sav, &ker)| *sav += scale * ker * sig)
} // inner loop
}

#[allow(clippy::too_many_arguments)]
#[inline(always)]
pub fn m2l_cplx_chunked<U>(
order: usize,
Expand Down Expand Up @@ -271,57 +271,6 @@ pub fn m2l_cplx_chunked<U>(
});
}

pub fn m2l_cplx<U>(
order: usize,
level: usize,
signal_freq_order: &[Vec<Complex<U>>],
check_potential_freq_order: &[Vec<SendPtrMut<Complex<U>>>],
kernel_data_halo: &[Vec<Complex<U>>],
all_displacements: &[Vec<Vec<usize>>],
scale: Complex<U>,
) where
U: Scalar + Sync,
{
let nparents = nparents(level);
let size_real = size_real(order);
// let scale = m2l_scale(level as u64);
let zero = U::from(0.).unwrap();

(0..size_real).into_par_iter().for_each(|freq| {
// Extract frequency components of siblings
let signal_freq = &signal_freq_order[freq];
let check_potential_freq = &check_potential_freq_order[freq];

(0..nparents).for_each(|sibling_idx| {
let save_locations = &check_potential_freq[(sibling_idx * 8)..(sibling_idx + 1) * 8];
let mut local_save_locations = vec![Complex::new(zero, zero); 8];

for (i, kernel_data) in kernel_data_halo.iter().enumerate() {
let frequency_offset = 64 * freq;
let kernel_data_freq = &kernel_data[frequency_offset..(frequency_offset + 64)];
let displacements = &all_displacements[sibling_idx][i];
let signal = &signal_freq[(displacements[0])..=(displacements[7])];
unsafe {
matmul8x8x2_cplx_simple_local(
kernel_data_freq,
signal,
&mut local_save_locations,
scale,
)
}
}
unsafe {
save_locations
.iter()
.zip(local_save_locations.iter())
.for_each(|(&glob, &loc)| {
(*glob.raw) += loc;
});
}
})
})
}

/// Implement the multipole to local translation operator for an FFT accelerated KiFMM on a single node.
impl<T, U> FieldTranslation<U>
for FmmDataLinear<KiFmmLinear<SingleNodeTree<U>, T, FftFieldTranslationKiFmm<U, T>, U>, U>
Expand Down Expand Up @@ -352,6 +301,7 @@ where
let Some(targets) = self.fmm.tree().get_keys(level) else {
return;
};
// let s = Instant::now();
// Form signals to use for convolution first
let n = 2 * self.fmm.order - 1;
let ntargets = targets.len();
Expand Down Expand Up @@ -391,6 +341,7 @@ where
});

let mut padded_signals_hat = vec![Complex::<U>::default(); size_real * ntargets];

U::rfft3_fftw_par_vec(&mut padded_signals, &mut padded_signals_hat, &[p, q, r]);

let ntargets = targets.len();
Expand Down Expand Up @@ -425,7 +376,7 @@ where
} else if level == 3 {
chunksize = 64
} else {
chunksize = 256
chunksize = 128
}

let all_displacements = displacements(&self.fmm.tree, level, &target_map);
Expand All @@ -436,35 +387,29 @@ where
let scale = Complex::from(self.m2l_scale(level));

let kernel_data_halo = &self.fmm.m2l.operator_data.kernel_data_rearranged;
// println!("level {:?} pre processing time {:?} ", level, s.elapsed());

// let s = Instant::now();
m2l_cplx_chunked(
self.fmm.order,
level as usize,
&padded_signals_hat_freq,
&global_check_potentials_hat_freq,
&kernel_data_halo,
kernel_data_halo,
&chunked_displacements,
&chunked_save_locations,
chunksize,
scale,
);

// m2l_cplx(
// self.fmm.order,
// level as usize,
// &padded_signals_hat_freq,
// &global_check_potentials_hat_freq,
// &kernel_data_halo,
// &all_displacements,
// scale
// );
// println!("level {:?} kernel time {:?} ", level, s.elapsed());

U::irfft_fftw_par_vec(
&mut global_check_potentials_hat,
&mut global_check_potentials,
&[p, q, r],
);

// let s = Instant::now();
// Compute local expansion coefficients and save to data tree
let (_, multi_indices) = MortonKey::surface_grid::<U>(self.fmm.order);

Expand Down Expand Up @@ -514,11 +459,12 @@ where
.zip(self.level_locals[level as usize].into_par_iter())
.for_each(|(result, local)| unsafe {
let mut ptr = local.raw;
for i in 0..ncoeffs {
*ptr += result[i];
ptr = ptr.add(1);
for &r in result.iter().take(ncoeffs) {
*ptr += r;
ptr = ptr.add(1)
}
});
// println!("level {:?} post processing time {:?} ", level, s.elapsed());
}

fn m2l_scale(&self, level: u64) -> U {
Expand Down Expand Up @@ -560,7 +506,7 @@ where
U: std::marker::Send + std::marker::Sync + Default,
{
fn m2l<'a>(&self, level: u64) {
let Some(targets) = self.fmm.tree().get_keys(level) else {
let Some(_targets) = self.fmm.tree().get_keys(level) else {
return;
};
}
Expand Down
30 changes: 10 additions & 20 deletions fmm/src/field_translation/linear/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use itertools::Itertools;
use num::Float;
use rayon::prelude::*;
use std::collections::HashMap;

use bempp_traits::{
field::FieldTranslationData,
Expand All @@ -16,7 +15,6 @@ use bempp_tree::types::single_node::SingleNodeTree;

use crate::{
constants::P2M_MAX_CHUNK_SIZE,
field_translation::hashmap::target,
types::{FmmDataLinear, KiFmmLinear},
};

Expand Down Expand Up @@ -54,7 +52,7 @@ where
{
fn l2l<'a>(&self, level: u64) {
if let Some(parent_sources) = self.fmm.tree().get_keys(level - 1) {
if let Some(child_targets) = self.fmm.tree().get_keys(level) {
if let Some(_child_targets) = self.fmm.tree().get_keys(level) {
let ncoeffs = self.fmm.m2l.ncoeffs(self.fmm.order);

let nsources = parent_sources.len();
Expand All @@ -77,8 +75,6 @@ where
let chunk_size = find_chunk_size(nsources, max_chunk_size);
let nsiblings = 8;

// let chunk_size = 1;

parent_locals
.par_chunks_exact(ncoeffs*chunk_size)
.zip(child_locals.par_chunks_exact(chunk_size*nsiblings))
Expand Down Expand Up @@ -113,7 +109,7 @@ where
fn m2p<'a>(&self) {}

fn l2p<'a>(&self) {
if let Some(leaves) = self.fmm.tree().get_all_leaves() {
if let Some(_leaves) = self.fmm.tree().get_all_leaves() {
let ncoeffs = self.fmm.m2l.ncoeffs(self.fmm.order);

let coordinates = self.fmm.tree().get_all_coordinates().unwrap();
Expand All @@ -122,13 +118,12 @@ where

self.leaf_upward_surfaces
.par_chunks_exact(surface_size)
.zip(leaves.into_par_iter())
.zip(self.leaf_locals.into_par_iter())
.zip(&self.charge_index_pointer)
.zip(&self.potentials_send_pointers)
.for_each(
|(
(((leaf_downward_equivalent_surface, leaf), local_ptr), charge_index_pointer),
((leaf_downward_equivalent_surface, local_ptr), charge_index_pointer),
potential_send_ptr,
)| {
let target_coordinates = &coordinates
Expand All @@ -144,14 +139,14 @@ where

// Compute direct
if ntargets > 0 {
let mut result = unsafe { std::slice::from_raw_parts_mut(potential_send_ptr.raw, ntargets)};
let result = unsafe { std::slice::from_raw_parts_mut(potential_send_ptr.raw, ntargets)};

self.fmm.kernel.evaluate_st(
EvalType::Value,
leaf_downward_equivalent_surface,
target_coordinates.data(),
local_expansion.data(),
&mut result,
result,
);

}
Expand Down Expand Up @@ -190,21 +185,17 @@ where

let charges = u_list_indices
.clone()
.into_iter()
.map(|&idx| {
let index_pointer = &self.charge_index_pointer[idx];
let charges = &self.charges[index_pointer.0..index_pointer.1];
charges
&self.charges[index_pointer.0..index_pointer.1]
})
.collect_vec();

let sources_coordinates = u_list_indices
.into_iter()
.map(|&idx| {
let index_pointer = &self.charge_index_pointer[idx];
let coords =
&coordinates[index_pointer.0 * dim..index_pointer.1 * dim];
coords
&coordinates[index_pointer.0 * dim..index_pointer.1 * dim]
})
.collect_vec();

Expand All @@ -216,16 +207,15 @@ where


if nsources > 0 {
let mut result = unsafe { std::slice::from_raw_parts_mut(potential_send_pointer.raw, ntargets)};
let result = unsafe { std::slice::from_raw_parts_mut(potential_send_pointer.raw, ntargets)};
self.fmm.kernel.evaluate_st(
EvalType::Value,
sources.data(),
// sources,
targets.data(),
charges,
&mut result,
);

result,
);
}
}
}
Expand Down
Loading

0 comments on commit ab14f76

Please sign in to comment.