still debugging
This commit is contained in:
parent
c2253ee5fe
commit
aae5eb6264
|
@ -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<Danum>) -> bool {
|
||||
let sum: u128 = { range.par_iter().map(|n| *n as u128).sum::<u128>() };
|
||||
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<Danum>) -> bool {
|
|||
log_2(sum): {}
|
||||
cap: {}
|
||||
sum: {}
|
||||
sep: {}/{}
|
||||
M: {}
|
||||
took: {:?}
|
||||
"#,
|
||||
|
@ -32,9 +32,11 @@ fn status(start: &Instant, range: &Vec<Danum>) -> 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 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()) {
|
||||
match recv.recv() {
|
||||
Ok(tup) => {
|
||||
if status(&start, tup, separate) {
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("{err}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
drop(recv);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue