Skip to content

Commit 8c26311

Browse files
committed
Unified stopping of solvers
Used dedicated functions at global and local scope to notify the stop. Used the flags in okContinue() function (not used in ScatterSplitter though)
1 parent 6722f3b commit 8c26311

File tree

11 files changed

+66
-23
lines changed

11 files changed

+66
-23
lines changed

.clang-files

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
./src/api/GlobalStop.cc
2+
./src/api/GlobalStop.h
13
./src/api/MainSolver.cc
24
./src/api/MainSolver.h
35
./src/api/Opensmt.cc

src/api/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ $<TARGET_OBJECTS:unsatcores>
2020
add_library(api OBJECT)
2121

2222
set(PRIVATE_SOURCES_TO_ADD
23+
"${CMAKE_CURRENT_SOURCE_DIR}/GlobalStop.cc"
2324
"${CMAKE_CURRENT_SOURCE_DIR}/MainSolver.cc"
2425
"${CMAKE_CURRENT_SOURCE_DIR}/PartitionManager.cc"
2526
"${CMAKE_CURRENT_SOURCE_DIR}/Interpret.cc"
2627
)
2728

2829
set(PUBLIC_SOURCES_TO_ADD
30+
"${CMAKE_CURRENT_SOURCE_DIR}/GlobalStop.h"
2931
"${CMAKE_CURRENT_SOURCE_DIR}/MainSolver.h"
3032
"${CMAKE_CURRENT_SOURCE_DIR}/PartitionManager.h"
3133
"${CMAKE_CURRENT_SOURCE_DIR}/smt2tokens.h"
@@ -99,6 +101,7 @@ endif()
99101
install(FILES
100102
Opensmt.h
101103
smt2tokens.h
104+
GlobalStop.h
102105
MainSolver.h
103106
PartitionManager.h
104107
Interpret.h

src/api/GlobalStop.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025, Tomas Kolarik <tomaqa@gmail.com>
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
namespace opensmt {
9+
10+
namespace {
11+
bool globalStopFlag{false};
12+
}
13+
14+
void notifyGlobalStop() {
15+
globalStopFlag = true;
16+
}
17+
18+
bool globallyStopped() {
19+
return globalStopFlag;
20+
}
21+
22+
} // namespace opensmt

src/api/GlobalStop.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025, Tomas Kolarik <tomaqa@gmail.com>
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
namespace opensmt {
9+
10+
// Notify all solvers in the application to stop
11+
void notifyGlobalStop();
12+
// Check if a global stop flag for all solvers has been triggered
13+
bool globallyStopped();
14+
15+
} // namespace opensmt

src/api/MainSolver.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
namespace opensmt {
2727

28-
bool stop;
29-
3028
MainSolver::MainSolver(Logic & logic, SMTConfig & conf, std::string name)
3129
: theory(createTheory(logic, conf)),
3230
term_mapper(new TermMapper(logic)),

src/api/MainSolver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef MAINSOLVER_H
1010
#define MAINSOLVER_H
1111

12+
#include "GlobalStop.h"
1213
#include "PartitionManager.h"
1314

1415
#include <cnfizers/Tseitin.h>
@@ -145,7 +146,9 @@ class MainSolver {
145146
}
146147
TermNames const & getTermNames() const { return termNames; }
147148

148-
void stop() { smt_solver->stop = true; }
149+
// Notify this particular solver to stop the computation
150+
// For stopping at the global scope, refer to GlobalStop.h
151+
void notifyStop() { smt_solver->notifyStop(); }
149152

150153
static std::unique_ptr<Theory> createTheory(Logic & logic, SMTConfig & config);
151154

src/parallel/ScatterSplitter.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ bool ScatterSplitter::excludeAssumptions(vec<Lit> && neg_constrs) {
133133

134134
bool ScatterSplitter::okContinue() const {
135135

136+
// ignores SimpSMTSolver::okContinue and hence ignores stopped() and globallyStopped()
137+
136138
if (splitContext.solverLimit() and splitContext.solverLimit() == search_counter and not config.sat_split_mode()) {
137139
return false;
138140
} else if (getChannel().shouldStop()) {

src/smtsolvers/CoreSMTSolver.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
4646

4747
#include "CoreSMTSolver.h"
4848

49+
#include <api/GlobalStop.h>
4950
#include <common/InternalException.h>
5051
#include <common/Random.h>
5152
#include <common/ReportUtils.h>
@@ -60,16 +61,13 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
6061

6162
namespace opensmt {
6263

63-
extern bool stop;
64-
6564
//=================================================================================================
6665
// Constructor/Destructor:
6766

6867
CoreSMTSolver::CoreSMTSolver(SMTConfig & c, THandler& t )
6968
: config (c)
7069
, theory_handler (t)
7170
, verbosity (c.verbosity())
72-
, stop (false)
7371
// Parameters: (formerly in 'SearchParams')
7472
, var_decay (c.sat_var_decay())
7573
, clause_decay (c.sat_clause_decay())
@@ -115,7 +113,6 @@ CoreSMTSolver::CoreSMTSolver(SMTConfig & c, THandler& t )
115113
#endif
116114
, conflict_budget (-1)
117115
, propagation_budget (-1)
118-
, asynch_interrupt (false)
119116
, learnt_t_lemmata (0)
120117
, perm_learnt_t_lemmata (0)
121118
, luby_i (0)
@@ -1346,7 +1343,7 @@ void CoreSMTSolver::popBacktrackPoint()
13461343

13471344
bool CoreSMTSolver::okContinue() const
13481345
{
1349-
return not opensmt::stop;
1346+
return not stopped() and not globallyStopped();
13501347
}
13511348

13521349
void CoreSMTSolver::learntSizeAdjust() {
@@ -1705,9 +1702,11 @@ lbool CoreSMTSolver::solve_()
17051702

17061703
// Search:
17071704

1708-
if (config.dryrun())
1709-
stop = true;
1710-
while (status == l_Undef && okContinue() && !this->stop) {
1705+
if (config.dryrun()) {
1706+
notifyStop();
1707+
}
1708+
1709+
while (status == l_Undef && okContinue()) {
17111710
// Print some information. At every restart for
17121711
// standard mode or any 2^n intervarls for luby
17131712
// restarts
@@ -1737,7 +1736,7 @@ lbool CoreSMTSolver::solve_()
17371736
model[i] = value(i);
17381737
}
17391738
} else {
1740-
assert(not okContinue() || status == l_False || this->stop);
1739+
assert(not okContinue() || status == l_False);
17411740
}
17421741

17431742
// We terminate

src/smtsolvers/CoreSMTSolver.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class CoreSMTSolver
8282
bool verbosity;
8383
enum class ConsistencyAction { BacktrackToZero, ReturnUndef, SkipToSearchBegin, NoOp };
8484
int search_counter;
85+
bool stopFlag{false};
8586
public:
86-
bool stop = false;
8787

8888
// Constructor/Destructor:
8989
//
@@ -92,9 +92,13 @@ class CoreSMTSolver
9292
void initialize ();
9393
void clearSearch (); // Backtrack SAT solver and theories to decision level 0
9494

95+
void notifyStop() { stopFlag = true; }
96+
9597
// Problem specification:
9698
//
9799
protected:
100+
bool stopped() const { return stopFlag; }
101+
98102
void addVar_ (Var v); // Ensure that var v exists in the solver
99103
virtual Var newVar(bool dvar); // Add a new variable with parameters specifying variable mode.
100104
public:
@@ -150,8 +154,6 @@ class CoreSMTSolver
150154
void setConfBudget(int64_t x);
151155
void setPropBudget(int64_t x);
152156
void budgetOff();
153-
void interrupt(); // Trigger a (potentially asynchronous) interruption of the solver.
154-
void clearInterrupt(); // Clear interrupt indicator flag.
155157

156158
// Memory management:
157159
//
@@ -350,7 +352,6 @@ class CoreSMTSolver
350352
//
351353
int64_t conflict_budget; // -1 means no budget.
352354
int64_t propagation_budget; // -1 means no budget.
353-
bool asynch_interrupt;
354355

355356
// Main internal methods:
356357
//
@@ -706,12 +707,10 @@ inline void CoreSMTSolver::setDecisionVar(Var v, bool b)
706707
}
707708
inline void CoreSMTSolver::setConfBudget(int64_t x) { conflict_budget = conflicts + x; }
708709
inline void CoreSMTSolver::setPropBudget(int64_t x) { propagation_budget = propagations + x; }
709-
inline void CoreSMTSolver::interrupt() { asynch_interrupt = true; }
710-
inline void CoreSMTSolver::clearInterrupt() { asynch_interrupt = false; }
711710
inline void CoreSMTSolver::budgetOff() { conflict_budget = propagation_budget = -1; }
712711
inline bool CoreSMTSolver::withinBudget() const
713712
{
714-
return !asynch_interrupt &&
713+
return !stopped() &&
715714
(conflict_budget < 0 || conflicts < (uint64_t)conflict_budget) &&
716715
(propagation_budget < 0 || propagations < (uint64_t)propagation_budget);
717716
}

src/smtsolvers/LookaheadSMTSolver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ lbool LookaheadSMTSolver::solve_() {
4444
model[i] = value(i);
4545
}
4646
} else {
47-
assert(not okContinue() || res == LALoopRes::unsat || this->stop);
47+
assert(not okContinue() || res == LALoopRes::unsat);
4848
}
4949
switch (res) {
5050
case LALoopRes::unknown_final:

0 commit comments

Comments
 (0)