summaryrefslogtreecommitdiff
path: root/src/solvers/gpusolver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers/gpusolver.rs')
-rw-r--r--src/solvers/gpusolver.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/solvers/gpusolver.rs b/src/solvers/gpusolver.rs
index 371f116..d1454b9 100644
--- a/src/solvers/gpusolver.rs
+++ b/src/solvers/gpusolver.rs
@@ -3,6 +3,7 @@ use crate::solvers::gpu::*;
use crate::solvers::{wall_stats, IteratorSolver, Solver};
use rayon::prelude::*;
use std::sync::mpsc::Sender;
+use std::sync::{Arc, Mutex};
#[derive(Debug)]
pub struct GpuSolver {
@@ -12,6 +13,7 @@ pub struct GpuSolver {
chunk: u32,
permutations: Vec<Vec<u32>>,
masks: Vec<u64>,
+ progress: Arc<Mutex<u32>>,
}
impl GpuSolver {
@@ -23,7 +25,7 @@ impl GpuSolver {
self.permute(
0,
0,
- ((0..(self.h - 1)).map(|x| x * chunk).collect::<Vec<u32>>()).as_ref(),
+ ((0..(self.h - 2)).map(|x| x * chunk).collect::<Vec<u32>>()).as_ref(),
sender.clone(),
);
sender.send(Message::CpuDone).unwrap();
@@ -31,7 +33,7 @@ impl GpuSolver {
while let Ok(Message::RowResult(wall)) = receiver.recv() {
walls.push(wall);
}
- println!("{:?}", walls);
+ //println!("{:?}", walls);
handle.join().unwrap();
walls
}
@@ -41,15 +43,14 @@ impl GpuSolver {
return;
}
let mut new_num = Vec::from(numbers);
- let start = numbers[index as usize] / self.chunk;
- if index as usize == numbers.len() - 1 {
+ if index as usize == numbers.len() {
let mut info = sys_info::mem_info().unwrap();
while info.avail < info.total / 8 {
std::thread::sleep(std::time::Duration::from_millis(5));
info = sys_info::mem_info().unwrap();
println!("mem wait {:?}", info);
}
- let i = self.n - 2 - numbers[index] / self.chunk;
+ let i = self.n - 3 - numbers[index - 1] / self.chunk;
sender
.send(Message::CheckRequest(CheckRequest::new(
new_num, curr_mask, i,
@@ -57,6 +58,7 @@ impl GpuSolver {
.unwrap();
return;
}
+ let start = numbers[index as usize] / self.chunk;
for i in start..self.n - (self.h - 1 - index as u32) {
for n in 1..(numbers.len() - index) {
new_num[n + index] = (n as u32 + i) * self.chunk;
@@ -78,11 +80,16 @@ impl GpuSolver {
);
});
} else {
+ {
+ let mut data = self.progress.lock().unwrap();
+ *data += 1;
+ println!(
+ "progress: {}%",
+ *data as f64 / self.chunk as f64 * 100.0 / self.n as f64
+ );
+ }
for j in 0..self.chunk {
new_num[index] = i * self.chunk + j;
- if index == 0 {
- println!("progress: {}%", j as f64 / self.chunk as f64);
- }
self.permute(
index + 1,
curr_mask | self.masks[new_num[index] as usize],
@@ -128,6 +135,7 @@ impl Solver for GpuSolver {
chunk,
permutations,
masks,
+ progress: Arc::new(Mutex::new(0)),
}
}
fn n(&self) -> u32 {