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 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🔥
|
// if we make these larger, our computer can be used as a heater🔥
|
||||||
type Danum = u16;
|
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;
|
const M: u128 = CAP as u128 * Danum::MAX as u128;
|
||||||
|
|
||||||
fn status(start: &Instant, range: &Vec<Danum>) -> bool {
|
fn status(start: &Instant, info: (u128, usize), separate: usize) -> bool {
|
||||||
let sum: u128 = { range.par_iter().map(|n| *n as u128).sum::<u128>() };
|
if info.0 < 1 {
|
||||||
if sum < 1 {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let progress = sum as f64 / M as f64;
|
let progress = info.0 as f64 / M as f64;
|
||||||
let eq = sum == M;
|
assert!(info.0 <= M);
|
||||||
|
let eq = info.0 == M;
|
||||||
println!(
|
println!(
|
||||||
r#"
|
r#"
|
||||||
done: {}
|
done: {}
|
||||||
|
@ -25,6 +24,7 @@ fn status(start: &Instant, range: &Vec<Danum>) -> bool {
|
||||||
log_2(sum): {}
|
log_2(sum): {}
|
||||||
cap: {}
|
cap: {}
|
||||||
sum: {}
|
sum: {}
|
||||||
|
sep: {}/{}
|
||||||
M: {}
|
M: {}
|
||||||
took: {:?}
|
took: {:?}
|
||||||
"#,
|
"#,
|
||||||
|
@ -32,9 +32,11 @@ fn status(start: &Instant, range: &Vec<Danum>) -> bool {
|
||||||
rayon::current_num_threads(),
|
rayon::current_num_threads(),
|
||||||
progress * 100.0,
|
progress * 100.0,
|
||||||
CAP.ilog2(),
|
CAP.ilog2(),
|
||||||
sum.ilog2(),
|
info.0.ilog2(),
|
||||||
CAP,
|
CAP,
|
||||||
sum,
|
info.0,
|
||||||
|
info.1,
|
||||||
|
separate,
|
||||||
M,
|
M,
|
||||||
start.elapsed(),
|
start.elapsed(),
|
||||||
);
|
);
|
||||||
|
@ -51,25 +53,42 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let lock = Arc::new(Mutex::new(range));
|
let separate: usize = 1 as usize;
|
||||||
let lock2 = lock.clone();
|
let (sender, recv) = std::sync::mpsc::channel();
|
||||||
rayon::spawn(move || {
|
rayon::spawn(move || {
|
||||||
const FOOF: usize = 16;
|
for i in 0..separate + 1 {
|
||||||
for i in 0..FOOF {
|
match sender.send((range.par_iter().map(|n| *n as u128).sum(), i)) {
|
||||||
let mut range = lock.lock().unwrap();
|
Ok(_) => (),
|
||||||
range.par_iter_mut().skip(i).step_by(FOOF).for_each(|num| {
|
Err(err) => {
|
||||||
for _ in 0..Danum::MAX {
|
eprintln!("{err}");
|
||||||
*num += 1;
|
break;
|
||||||
let _ = write!(std::io::Sink::default(), "{num}");
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
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 {
|
loop {
|
||||||
ticker.tick().await;
|
match recv.recv() {
|
||||||
if status(&start, &lock2.lock().unwrap()) {
|
Ok(tup) => {
|
||||||
break;
|
if status(&start, tup, separate) {
|
||||||
};
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{err}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
drop(recv);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue