6 #include "../utils/Bookkeeping.h"
18 template<
typename... Backends>
21 using B = std::tuple<Backends...>;
24 template<std::size_t N = 0, carl::EnableIfBool<N == std::tuple_size<B>::value> = carl::dummy>
26 const std::size_t NUM_THREADS, std::mutex& mtx,
27 std::vector<std::thread>& threads, std::vector<pthread_t>& nativeHandles,
28 size_t& counter, std::vector<std::optional<Explanation>>& explanations)
const {
34 std::optional<Explanation> explanation;
36 if(counter == NUM_THREADS){
SMTRAT_LOG_ERROR(
"smtrat.mcsat.explanation",
"No explanation left."); }
37 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.explanation",
"Look for resulting explanation");
38 for (
size_t i = 0; i < NUM_THREADS; i++) {
39 explanation = explanations[i];
40 if (explanation != std::nullopt) {
42 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.explanation",
"Found explanation: " << *explanation);
43 for(
size_t j = 0; j < NUM_THREADS; j++){
44 pthread_cancel(nativeHandles[j]);
46 s = pthread_join(nativeHandles[j], &res);
48 if (res != PTHREAD_CANCELED){
51 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.explanation",
"Thread cancelled successfully");
54 nativeHandles.clear();
64 template<std::size_t N = 0, carl::EnableIfBool<N < std::tuple_size<B>::value> = carl::dummy>
66 const std::size_t NUM_THREADS, std::mutex& mtx,
67 std::vector<std::thread>& threads, std::vector<pthread_t>& nativeHandles,
68 size_t& counter, std::vector<std::optional<Explanation>>& explanations)
const {
71 if(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)){
72 SMTRAT_LOG_ERROR(
"smtrat.mcsat.explanation",
"Pthread set cancel type error");
76 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.explanation",
"Concurrent strategy " << N+1 <<
" started");
77 explanations[N] = std::get<N>(
mBackends)(data,
var, reason);
78 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.explanation",
"Concurrent strategy " << N+1 <<
" done");
84 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.explanation",
"Concurrent strategy " << N+1 <<
" waiting");
92 threads.push_back(std::thread(F));
94 nativeHandles.push_back(threads[N].native_handle());
97 explain<N+1>(data,
var, reason, NUM_THREADS, mtx, threads, nativeHandles, counter, explanations);
101 std::optional<Explanation> operator()(
const mcsat::Bookkeeping& data, carl::Variable
var,
const FormulasT& reason)
const {
102 const std::size_t NUM_THREADS = std::tuple_size<B>::value;
103 if(NUM_THREADS <= 0){
109 std::vector<std::thread> threads;
110 std::vector<pthread_t> nativeHandles;
112 std::vector<std::optional<Explanation>> explanations(NUM_THREADS, std::nullopt);
116 std::optional<Explanation> explanation = explain<0>(data,
var, reason, NUM_THREADS, mtx, threads, nativeHandles, counter, explanations);
Represent the trail, i.e.
Class to create the formulas for axioms.
carl::Formulas< Poly > FormulasT
#define SMTRAT_LOG_TRACE(channel, msg)
#define SMTRAT_LOG_ERROR(channel, msg)
#define SMTRAT_LOG_DEBUG(channel, msg)
This explanation executes all given explanation parallel in multiple threads and waits until every si...
std::optional< Explanation > explain(const mcsat::Bookkeeping &, carl::Variable, const FormulasT &, const std::size_t NUM_THREADS, std::mutex &mtx, std::vector< std::thread > &threads, std::vector< pthread_t > &nativeHandles, size_t &counter, std::vector< std::optional< Explanation >> &explanations) const
std::tuple< Backends... > B