From f4a82bfd30b679f67ad9c21b41fea99d420d6510 Mon Sep 17 00:00:00 2001 From: jw1912 Date: Wed, 7 Aug 2024 09:53:47 +0100 Subject: [PATCH 1/3] Bench: 1954267 --- src/mcts.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/mcts.rs b/src/mcts.rs index 44c1b65f..d42a4340 100644 --- a/src/mcts.rs +++ b/src/mcts.rs @@ -64,8 +64,8 @@ impl<'a> Searcher<'a> { best_move_changes: &mut i32, previous_score: &mut f32, #[cfg(not(feature = "uci-minimal"))] uci_output: bool, - ) { - if self.playout_until_full_internal(nodes, cumulative_depth, |n, cd| { + ) -> bool { + self.playout_until_full_internal(nodes, cumulative_depth, |n, cd| { self.check_limits( limits, timer, @@ -78,9 +78,7 @@ impl<'a> Searcher<'a> { #[cfg(not(feature = "uci-minimal"))] uci_output, ) - }) { - self.abort.store(true, Ordering::Relaxed); - } + }) } fn playout_until_full_worker(&self, nodes: &mut usize, cumulative_depth: &mut usize) { @@ -235,8 +233,8 @@ impl<'a> Searcher<'a> { // search loop while !self.abort.load(Ordering::Relaxed) { - thread::scope(|s| { - s.spawn(|| { + let abort = thread::scope(|s| { + let abort = s.spawn(|| { self.playout_until_full_main( &limits, &timer, @@ -248,19 +246,23 @@ impl<'a> Searcher<'a> { &mut previous_score, #[cfg(not(feature = "uci-minimal"))] uci_output, - ); + ) }); for _ in 0..threads - 1 { s.spawn(|| self.playout_until_full_worker(&mut 0, &mut 0)); } + + abort.join().unwrap() }); - self.tree.flip(true, threads); + if abort { + self.abort.store(true, Ordering::Relaxed); + } else { + self.tree.flip(true, threads); + } } - self.abort.store(true, Ordering::Relaxed); - *total_nodes += nodes; if uci_output { From fcbc33a9ec8b3f14e96fcf1181f3869c57f857e2 Mon Sep 17 00:00:00 2001 From: jw1912 Date: Wed, 7 Aug 2024 17:30:49 +0100 Subject: [PATCH 2/3] Simplify Code Bench: 1954267 --- src/mcts.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/mcts.rs b/src/mcts.rs index d42a4340..dd5fc5eb 100644 --- a/src/mcts.rs +++ b/src/mcts.rs @@ -64,8 +64,8 @@ impl<'a> Searcher<'a> { best_move_changes: &mut i32, previous_score: &mut f32, #[cfg(not(feature = "uci-minimal"))] uci_output: bool, - ) -> bool { - self.playout_until_full_internal(nodes, cumulative_depth, |n, cd| { + ) { + if self.playout_until_full_internal(nodes, cumulative_depth, |n, cd| { self.check_limits( limits, timer, @@ -78,7 +78,9 @@ impl<'a> Searcher<'a> { #[cfg(not(feature = "uci-minimal"))] uci_output, ) - }) + }) { + self.abort.store(true, Ordering::Relaxed); + } } fn playout_until_full_worker(&self, nodes: &mut usize, cumulative_depth: &mut usize) { @@ -233,8 +235,8 @@ impl<'a> Searcher<'a> { // search loop while !self.abort.load(Ordering::Relaxed) { - let abort = thread::scope(|s| { - let abort = s.spawn(|| { + thread::scope(|s| { + s.spawn(|| { self.playout_until_full_main( &limits, &timer, @@ -252,13 +254,9 @@ impl<'a> Searcher<'a> { for _ in 0..threads - 1 { s.spawn(|| self.playout_until_full_worker(&mut 0, &mut 0)); } - - abort.join().unwrap() }); - if abort { - self.abort.store(true, Ordering::Relaxed); - } else { + if !self.abort.load(Ordering::Relaxed) { self.tree.flip(true, threads); } } From ad63a05188eed23db1e0117d34adb4eabf4dd413 Mon Sep 17 00:00:00 2001 From: jw1912 Date: Wed, 7 Aug 2024 17:32:04 +0100 Subject: [PATCH 3/3] add back semi-colon --- src/mcts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mcts.rs b/src/mcts.rs index dd5fc5eb..56832a03 100644 --- a/src/mcts.rs +++ b/src/mcts.rs @@ -248,7 +248,7 @@ impl<'a> Searcher<'a> { &mut previous_score, #[cfg(not(feature = "uci-minimal"))] uci_output, - ) + ); }); for _ in 0..threads - 1 {