summaryrefslogtreecommitdiff
path: root/src/solvers/single.rs
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2020-01-12 06:36:06 +0100
committerDennis Kobert <dennis@kobert.dev>2020-01-12 06:36:06 +0100
commitcf6c285d0960526843f849a9033ff1895fc8cab7 (patch)
treecaa08ac9f44284852e395c4d9e41bdf8ed16e763 /src/solvers/single.rs
parent29bffc6f6c794fee886904ad3960c4cb770deb11 (diff)
Fix borrow mustakesrefactoring
Diffstat (limited to 'src/solvers/single.rs')
-rw-r--r--src/solvers/single.rs43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/solvers/single.rs b/src/solvers/single.rs
index ad3e5b7..6bfdd5f 100644
--- a/src/solvers/single.rs
+++ b/src/solvers/single.rs
@@ -1,7 +1,6 @@
-use rayon::prelude::*;
+use super::gpu::*;
/// Solve for a given N and return the resulting wall
-#[derive(Clone)]
pub struct NormalSolver {
pub n: u32,
/// calculated height [might not be correct!]
@@ -13,12 +12,10 @@ pub struct NormalSolver {
/// Use to store already used blocks as a bitmask
permutations: Vec<Vec<u32>>,
masks: Vec<u64>,
- senders: Vec<std::sync::mpsc::Sender<super::opencl::Job>>,
+ gpu_sender: std::sync::mpsc::Sender<super::gpu::Message>,
+ gpu_handle: Option<std::thread::JoinHandle<()>>,
}
-static mut TRIES: u32 = 0;
-static mut SOLUTIONS: u32 = 0;
-
impl NormalSolver {
pub fn new(n: u32) -> Self {
let h = n / 2 + 1;
@@ -40,11 +37,8 @@ impl NormalSolver {
}
}
- let src =
- std::fs::read_to_string("src/solvers/check.cl").expect("failed to open kernel file");
-
- let senders =
- super::opencl::GpuSolver::launch_sevice(&masks, n, h, w, 0, src.as_ref()).unwrap();
+ let (gpu_sender, gpu_handle) =
+ super::gpu::OclManager::launch_sevice(&permutations, &masks, n, 0);
Self {
n,
h,
@@ -53,16 +47,17 @@ impl NormalSolver {
mask: (1 << w) - 2,
permutations,
masks,
- senders,
+ gpu_sender,
+ gpu_handle: Some(gpu_handle),
}
}
pub fn solve(&mut self) {
- for (n, i) in self.permutations.iter().enumerate() {
- let tmp: Vec<u32> = i.iter().map(|x| *x).collect();
- //println!("perm {}: {:?}", n, tmp);
- //println!("perm {}: {:b}", n, self.masks[n]);
- }
+ //for (n, i) in self.permutations.iter().enumerate() {
+ //let tmp: Vec<u32> = i.clone();
+ //println!("perm {}: {:?}", n, tmp);
+ //println!("perm {}: {:b}", n, self.masks[n]);
+ //}
println!("calculate results");
self.permute(
permutohedron::factorial(self.n as usize),
@@ -73,10 +68,10 @@ impl NormalSolver {
.collect::<Vec<u32>>())
.as_ref(),
);
- unsafe { println!("tries: {}\nsolutions: {}", TRIES, SOLUTIONS) }
- loop {
- std::thread::sleep(std::time::Duration::from_secs(5));
- }
+ self.gpu_sender
+ .send(super::gpu::Message::Terminate)
+ .unwrap();
+ self.gpu_handle.take().unwrap().join().unwrap();
}
fn permute(&self, up: usize, index: usize, curr_mask: u64, numbers: &[u32]) {
@@ -95,8 +90,10 @@ impl NormalSolver {
println!("mem wait {:?}", info);
}
let i = self.n - 2 - numbers[index] / self.chunk;
- self.senders[i as usize]
- .send(super::opencl::Job::new(new_num, curr_mask))
+ self.gpu_sender
+ .send(Message::CheckRequest(CheckRequest::new(
+ new_num, curr_mask, i,
+ )))
.unwrap();
return;
//}