diff --git a/lab4/zad2/src/main.rs b/lab4/zad2/src/main.rs index c9394da..8774c1b 100644 --- a/lab4/zad2/src/main.rs +++ b/lab4/zad2/src/main.rs @@ -101,17 +101,17 @@ fn main() -> io::Result<()> { if rand_heights_clone.get(&n).is_some() { return; } - println!("{}: starting n: {n}", current_thread_index().unwrap()); + println!("{thread}: starting n: {n}", thread = current_thread_index().unwrap()); asc_results_clone.insert(n, vec![]); asc_heights_clone.insert(n, vec![]); rand_results_clone.insert(n, vec![]); rand_heights_clone.insert(n, vec![]); - let mut asc = BinarySearchTree::new(n as usize); - let mut rand = BinarySearchTree::new(n as usize); + (1..=m).into_par_iter().for_each(|k| { + println!("{thread}: starting iteration {k}/{m} for n: {n}", thread = current_thread_index().unwrap()); + let mut asc = BinarySearchTree::new(n as usize); - for _ in 0..m { for i in gen_asc(n) { asc.insert(i); asc_heights_clone.get_mut(&n).unwrap().push(asc.height()); @@ -123,6 +123,8 @@ fn main() -> io::Result<()> { asc_results_clone.get_mut(&n).unwrap().push(asc.stats.clone()); + let mut rand = BinarySearchTree::new(n as usize); + for i in gen_rand(n) { rand.insert(i); rand_heights_clone.get_mut(&n).unwrap().push(rand.height()); @@ -133,8 +135,9 @@ fn main() -> io::Result<()> { } rand_results_clone.get_mut(&n).unwrap().push(rand.stats.clone()); - } - println!("{}: finished n: {n}", current_thread_index().unwrap()); + println!("{thread}: finished iteration {k}/{m} for n: {n}", thread = current_thread_index().unwrap()); + }); + println!("{thread}: finished n: {n}", thread = current_thread_index().unwrap()); }); let asc_comp_averages = comp_avg(&asc_results);