summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs2
-rw-r--r--src/solvers/gpu/mod.rs12
-rw-r--r--src/solvers/gpusolver.rs24
3 files changed, 27 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs
index ee7082d..cfc4cb0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,6 +10,6 @@ fn main() {
let solver = solvers::gpusolver::GpuSolver::new(N);
//println!("solver: {:?}", solver);
for (i, solution) in solver.solve().enumerate() {
- println!("{}: {:?}", i, solution);
+ //println!("{}: {:?}", i, solution);
}
}
diff --git a/src/solvers/gpu/mod.rs b/src/solvers/gpu/mod.rs
index e89f033..379416a 100644
--- a/src/solvers/gpu/mod.rs
+++ b/src/solvers/gpu/mod.rs
@@ -77,11 +77,19 @@ pub struct RowResult {
impl RowResult {
fn new(mut rows: Vec<u32>) -> Self {
- rows.push(0);
+ //rows.push(0);
rows.sort();
Self { rows }
}
fn output(&self) {
- println!("{:?}", self.rows);
+ /*let s = self
+ .rows
+ .iter()
+ .fold(String::new(), |s, d| s + &d.to_string() + " ");
+ println!("{}", s);*/
+ let i = self.rows[0];
+ for r in self.rows.iter() {
+ println!("{}\t{}", i, r);
+ }
}
}
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 {