Skip to content

Commit

Permalink
refactor(laplace): don't move matrix into compute
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 17, 2024
1 parent a2f37fc commit 44cf8af
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/demo/src/laplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const SIZE: usize = if cfg!(debug_assertions) { 16 } else { 64 };
pub fn laplace() {
eprintln!();

let matrix = matrix_setup(SIZE, SIZE);
let mut matrix = matrix_setup(SIZE, SIZE);

eprintln!("Laplace iterations");
let now = Instant::now();
let (i, residual) = compute(matrix, SIZE, SIZE);
let (i, residual) = compute(&mut matrix, SIZE, SIZE);
let elapsed = now.elapsed();
eprintln!("{i} iterations: {elapsed:?} (residual: {residual})");

Expand Down Expand Up @@ -89,9 +89,11 @@ fn iteration(cur: &[f64], next: &mut [f64], size_x: usize, size_y: usize) {
});
}

pub fn compute(matrix: vec::Vec<f64>, size_x: usize, size_y: usize) -> (usize, f64) {
pub fn compute(matrix: &mut [f64], size_x: usize, size_y: usize) -> (usize, f64) {
let mut clone = matrix.to_vec();

let mut current = matrix;
let mut next = current.clone();
let mut next = &mut clone[..];
let mut counter = 0;

while counter < 1000 {
Expand Down

0 comments on commit 44cf8af

Please sign in to comment.