From 8708a172ebe59d3189b8b9d756abd9da8dc509a3 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 12 Jan 2020 09:51:22 +0100 Subject: Allow to use teh iterator for results --- src/solvers/gpu/output.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/solvers/gpu/output.rs') diff --git a/src/solvers/gpu/output.rs b/src/solvers/gpu/output.rs index 43e0d98..6bf7bcb 100644 --- a/src/solvers/gpu/output.rs +++ b/src/solvers/gpu/output.rs @@ -1,4 +1,4 @@ -use super::{Message, ResultMessage}; +use super::{Message, ResultMessage, RowResult}; use std::collections::{HashMap, HashSet}; use std::sync::mpsc::{channel, Receiver, Sender}; use std::thread::JoinHandle; @@ -44,6 +44,9 @@ impl InBuffer { self.row_requests.insert(id, output); } } + Message::CpuDone => { + return None; + } Message::Terminate => { return None; } @@ -66,33 +69,19 @@ impl InBuffer { } } -#[derive(PartialEq, Eq, Hash)] -pub struct RowResult { - rows: Vec, -} - -impl RowResult { - fn new(mut rows: Vec) -> Self { - rows.push(0); - rows.sort(); - Self { rows } - } - fn output(&self) { - println!("{:?}", self.rows); - } -} - pub struct Output { input: InBuffer, permutations: Vec>, permutations_mask: Vec, results: HashSet, + result_sender: Sender, } impl Output { pub fn launch_sevice( permutations: &[Vec], permutations_mask: &[u64], + result_sender: Sender, ) -> (Sender, JoinHandle<()>) { let (sender, receiver) = channel(); let input = InBuffer::new(receiver); @@ -102,11 +91,12 @@ impl Output { permutations: permutations.into(), permutations_mask: permutations_mask.into(), results: HashSet::new(), + result_sender, }; ( sender, std::thread::Builder::new() - .name("GPU Manager Deamon".into()) + .name("GPU Output Deamon".into()) .spawn(move || { output.run(); }) @@ -118,12 +108,20 @@ impl Output { loop { if let Some(walls) = self.input.read() { for wall in walls { + if !self.results.contains(&wall) { + self.result_sender + .send(Message::RowResult(wall.clone())) + .or_else(|_| Err(println!("Failed to transmit result back"))); + } self.results.insert(wall); } } else { for wall in self.results { wall.output() } + self.result_sender.send(Message::GpuDone).unwrap(); + // wait for second exit signal + self.input.read(); return; } } -- cgit v1.2.3-70-g09d2