From aae5eb6264f4499603d386976d5ebe9c760b4864 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 1 Feb 2024 16:23:02 +0100 Subject: [PATCH] still debugging --- members/tokryon/src/main.rs | 73 +++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/members/tokryon/src/main.rs b/members/tokryon/src/main.rs index 191dfe8..1528f5e 100644 --- a/members/tokryon/src/main.rs +++ b/members/tokryon/src/main.rs @@ -1,21 +1,20 @@ -use std::io::prelude::*; -use std::sync::{Arc, Mutex}; - use rayon::prelude::*; -use tokio::time::{interval, Instant}; +use std::io::prelude::*; +use tokio::time::Instant; // if we make these larger, our computer can be used as a heateršŸ”„ type Danum = u16; -const CAP: usize = 1 << 16; +const EXP: usize = 15; +const CAP: usize = 1 << EXP; const M: u128 = CAP as u128 * Danum::MAX as u128; -fn status(start: &Instant, range: &Vec) -> bool { - let sum: u128 = { range.par_iter().map(|n| *n as u128).sum::() }; - if sum < 1 { +fn status(start: &Instant, info: (u128, usize), separate: usize) -> bool { + if info.0 < 1 { return false; } - let progress = sum as f64 / M as f64; - let eq = sum == M; + let progress = info.0 as f64 / M as f64; + assert!(info.0 <= M); + let eq = info.0 == M; println!( r#" done: {} @@ -25,6 +24,7 @@ fn status(start: &Instant, range: &Vec) -> bool { log_2(sum): {} cap: {} sum: {} + sep: {}/{} M: {} took: {:?} "#, @@ -32,9 +32,11 @@ fn status(start: &Instant, range: &Vec) -> bool { rayon::current_num_threads(), progress * 100.0, CAP.ilog2(), - sum.ilog2(), + info.0.ilog2(), CAP, - sum, + info.0, + info.1, + separate, M, start.elapsed(), ); @@ -51,25 +53,42 @@ async fn main() { } let start = Instant::now(); - let lock = Arc::new(Mutex::new(range)); - let lock2 = lock.clone(); + let separate: usize = 1 as usize; + let (sender, recv) = std::sync::mpsc::channel(); rayon::spawn(move || { - const FOOF: usize = 16; - for i in 0..FOOF { - let mut range = lock.lock().unwrap(); - range.par_iter_mut().skip(i).step_by(FOOF).for_each(|num| { - for _ in 0..Danum::MAX { - *num += 1; - let _ = write!(std::io::Sink::default(), "{num}"); + for i in 0..separate + 1 { + match sender.send((range.par_iter().map(|n| *n as u128).sum(), i)) { + Ok(_) => (), + Err(err) => { + eprintln!("{err}"); + break; } - }); + } + range + .par_iter_mut() + .skip(i) + .step_by(separate) + .for_each(|num| { + for _ in 0..Danum::MAX { + *num += 1; + let _ = write!(std::io::Sink::default(), "{num}"); + } + }); } + println!("DONE!"); }); - let mut ticker = interval(tokio::time::Duration::from_millis(500)); loop { - ticker.tick().await; - if status(&start, &lock2.lock().unwrap()) { - break; - }; + match recv.recv() { + Ok(tup) => { + if status(&start, tup, separate) { + break; + } + } + Err(err) => { + eprintln!("{err}"); + break; + } + } } + drop(recv); }