mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-04 13:29:11 +00:00 
			
		
		
		
	fix build
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
		
							parent
							
								
									5f89ead54b
								
							
						
					
					
						commit
						9fab72b3ef
					
				
					 3 changed files with 88 additions and 52 deletions
				
			
		| 
						 | 
					@ -112,7 +112,7 @@ namespace smt {
 | 
				
			||||||
        unsigned                    m_final_check_idx; // circular counter used for implementing fairness
 | 
					        unsigned                    m_final_check_idx; // circular counter used for implementing fairness
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bool                        m_is_auxiliary; // used to prevent unwanted information from being logged.
 | 
					        bool                        m_is_auxiliary; // used to prevent unwanted information from being logged.
 | 
				
			||||||
        parallel*                   m_par;
 | 
					        class parallel*             m_par;
 | 
				
			||||||
        unsigned                    m_par_index;
 | 
					        unsigned                    m_par_index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // -----------------------------------
 | 
					        // -----------------------------------
 | 
				
			||||||
| 
						 | 
					@ -413,26 +413,17 @@ namespace smt {
 | 
				
			||||||
            return js.get_kind() == b_justification::JUSTIFICATION && js.get_justification()->get_from_theory() == th_id;
 | 
					            return js.get_kind() == b_justification::JUSTIFICATION && js.get_justification()->get_from_theory() == th_id;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        void set_par(unsigned idx, parallel* p) { m_par = p; m_par_index = idx; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        void set_random_seed(unsigned s) { m_random.set_seed(s); }
 | 
					        void set_random_seed(unsigned s) { m_random.set_seed(s); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        int get_random_value() { return m_random(); }
 | 
					        int get_random_value() { return m_random(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bool is_searching() const { return m_searching; }
 | 
					        bool is_searching() const { return m_searching; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        svector<double> const & get_activity_vector() const {
 | 
					        svector<double> const & get_activity_vector() const { return m_activity; }
 | 
				
			||||||
            return m_activity;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        double get_activity(bool_var v) const {
 | 
					        double get_activity(bool_var v) const { return m_activity[v]; }
 | 
				
			||||||
            return m_activity[v];
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void set_activity(bool_var v, double act) {
 | 
					        void set_activity(bool_var v, double act) { m_activity[v] = act; }
 | 
				
			||||||
            m_activity[v] = act;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void activity_changed(bool_var v, bool increased) {
 | 
					        void activity_changed(bool_var v, bool increased) {
 | 
				
			||||||
            if (increased) {
 | 
					            if (increased) {
 | 
				
			||||||
| 
						 | 
					@ -1617,6 +1608,8 @@ namespace smt {
 | 
				
			||||||
            return m_unsat_core.get(idx);
 | 
					            return m_unsat_core.get(idx);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        expr_ref_vector const& unsat_core() const { return m_unsat_core; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void get_levels(ptr_vector<expr> const& vars, unsigned_vector& depth);
 | 
					        void get_levels(ptr_vector<expr> const& vars, unsigned_vector& depth);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        expr_ref_vector get_trail();
 | 
					        expr_ref_vector get_trail();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,30 +15,14 @@ Author:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
--*/
 | 
					--*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "smt/smt_parallel.h"
 | 
					 | 
				
			||||||
#include "util/scoped_ptr_vector.h"
 | 
					#include "util/scoped_ptr_vector.h"
 | 
				
			||||||
 | 
					#include "ast/ast_util.h"
 | 
				
			||||||
 | 
					#include "ast/ast_translation.h"
 | 
				
			||||||
 | 
					#include "smt/smt_parallel.h"
 | 
				
			||||||
 | 
					#include "smt/smt_lookahead.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace smt {
 | 
					namespace smt {
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    void parallel::add_unit(context& pctx, expr* e) {
 | 
					 | 
				
			||||||
        std::lock_guard<std::mutex> lock(m_mux);
 | 
					 | 
				
			||||||
        ast_translation tr(pctx.m, ctx.m);
 | 
					 | 
				
			||||||
        expr_ref u (tr(e), ctx.m);
 | 
					 | 
				
			||||||
        if (!m_unit_set.contains(u)) {
 | 
					 | 
				
			||||||
            m_unit_trail.push_back(u);
 | 
					 | 
				
			||||||
            m_unit_set.insert(u);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    void parallel::get_units(unsigned idx, context& pctx) {
 | 
					 | 
				
			||||||
        std::lock_guard<std::mutex> lock(m_mux);
 | 
					 | 
				
			||||||
        ast_translation tr(ctx.m, pctx.m);
 | 
					 | 
				
			||||||
        for (unsigned i = m_unit_lim[idx]; i < m_unit_trail.size(); ++i) {
 | 
					 | 
				
			||||||
            expr_ref u (tr(m_unit_trail.get(i)), pctx.m);
 | 
					 | 
				
			||||||
            pctx.assert_expr(u);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    lbool parallel::operator()(expr_ref_vector const& asms) {
 | 
					    lbool parallel::operator()(expr_ref_vector const& asms) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        enum par_exception_kind {
 | 
					        enum par_exception_kind {
 | 
				
			||||||
| 
						 | 
					@ -58,6 +42,9 @@ namespace smt {
 | 
				
			||||||
        std::string        ex_msg;
 | 
					        std::string        ex_msg;
 | 
				
			||||||
        par_exception_kind ex_kind = DEFAULT_EX;
 | 
					        par_exception_kind ex_kind = DEFAULT_EX;
 | 
				
			||||||
        unsigned error_code = 0;
 | 
					        unsigned error_code = 0;
 | 
				
			||||||
 | 
					        bool done = false;
 | 
				
			||||||
 | 
					        unsigned num_rounds = 0;
 | 
				
			||||||
 | 
					        unsigned max_conflicts = 400;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (unsigned i = 0; i < num_threads; ++i) {
 | 
					        for (unsigned i = 0; i < num_threads; ++i) {
 | 
				
			||||||
            ast_manager* new_m = alloc(ast_manager, m, true);
 | 
					            ast_manager* new_m = alloc(ast_manager, m, true);
 | 
				
			||||||
| 
						 | 
					@ -68,18 +55,74 @@ namespace smt {
 | 
				
			||||||
            new_ctx.set_random_seed(i + ctx.get_fparams().m_random_seed);
 | 
					            new_ctx.set_random_seed(i + ctx.get_fparams().m_random_seed);
 | 
				
			||||||
            ast_translation tr(*new_m, m);
 | 
					            ast_translation tr(*new_m, m);
 | 
				
			||||||
            pasms.push_back(tr(asms));
 | 
					            pasms.push_back(tr(asms));
 | 
				
			||||||
            m_unit_lim.push_back(0);
 | 
					 | 
				
			||||||
            new_ctx.set_par(i, this);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        std::function<void(context&,expr_ref_vector&,expr_ref&)> cube = [&](context& ctx, expr_ref_vector& lasms, expr_ref& c) {
 | 
				
			||||||
 | 
					            lookahead lh(ctx);
 | 
				
			||||||
 | 
					            c = lh.choose();
 | 
				
			||||||
 | 
					            if (c) lasms.push_back(c);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        obj_hashtable<expr> unit_set;
 | 
				
			||||||
 | 
					        expr_ref_vector unit_trail(ctx.m);
 | 
				
			||||||
 | 
					        unsigned_vector unit_lim;
 | 
				
			||||||
 | 
					        for (unsigned i = 0; i < num_threads; ++i) unit_lim.push_back(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        std::function<void(void)> collect_units = [&,this]() {
 | 
				
			||||||
 | 
					            for (unsigned i = 0; i < num_threads; ++i) {
 | 
				
			||||||
 | 
					                context& pctx = *pctxs[i];
 | 
				
			||||||
 | 
					                pctx.pop_to_base_lvl();
 | 
				
			||||||
 | 
					                ast_translation tr(pctx.m, ctx.m);
 | 
				
			||||||
 | 
					                unsigned sz = pctx.assigned_literals().size();
 | 
				
			||||||
 | 
					                for (unsigned j = unit_lim[i]; j < sz; ++j) {
 | 
				
			||||||
 | 
					                    literal lit = pctx.assigned_literals()[j];
 | 
				
			||||||
 | 
					                    expr_ref e(pctx.bool_var2expr(lit.var()), pctx.m);
 | 
				
			||||||
 | 
					                    if (lit.sign()) e = pctx.m.mk_not(e);
 | 
				
			||||||
 | 
					                    expr_ref ce(tr(e.get()), ctx.m);
 | 
				
			||||||
 | 
					                    if (!unit_set.contains(ce)) {
 | 
				
			||||||
 | 
					                        unit_set.insert(ce);
 | 
				
			||||||
 | 
					                        unit_trail.push_back(ce);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (unsigned i = 0; i < num_threads; ++i) {
 | 
				
			||||||
 | 
					                context& pctx = *pctxs[i];
 | 
				
			||||||
 | 
					                ast_translation tr(ctx.m, pctx.m);
 | 
				
			||||||
 | 
					                unsigned sz = unit_trail.size();
 | 
				
			||||||
 | 
					                for (unsigned j = unit_lim[i]; j < sz; ++j) {
 | 
				
			||||||
 | 
					                    expr_ref src(ctx.m), dst(pctx.m);
 | 
				
			||||||
 | 
					                    dst = tr(unit_trail.get(j));
 | 
				
			||||||
 | 
					                    pctx.assert_expr(dst);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                unit_lim[i] = sz;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::mutex mux;
 | 
					        std::mutex mux;
 | 
				
			||||||
        auto worker_thread = [&](int i) {
 | 
					        auto worker_thread = [&](int i) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                IF_VERBOSE(0, verbose_stream() << "thread " << i << "\n";);
 | 
					                IF_VERBOSE(0, verbose_stream() << "thread " << i << "\n";);
 | 
				
			||||||
                context& pctx = *pctxs[i];
 | 
					                context& pctx = *pctxs[i];
 | 
				
			||||||
                ast_manager& pm = *pms[i];
 | 
					                ast_manager& pm = *pms[i];
 | 
				
			||||||
 | 
					                expr_ref_vector lasms(pasms[i]);
 | 
				
			||||||
 | 
					                expr_ref c(pm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                pctx.get_fparams().m_max_conflicts = max_conflicts;
 | 
				
			||||||
 | 
					                if (num_iterations > 0) {
 | 
				
			||||||
 | 
					                    cube(pctx, lasms, c);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                lbool r = pctx.check(lasms.size(), lasms.c_ptr());
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                if (r == l_undef && pctx.m_num_conflicts >= max_conflicts) {
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }                
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (r == l_false && pctx.unsat_core().contains(c)) {
 | 
				
			||||||
 | 
					                    pctx.assert_expr(mk_not(mk_and(pctx.unsat_core())));
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                } 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                lbool r = pctx.check(pasms[i].size(), pasms[i].c_ptr());
 | 
					 | 
				
			||||||
                bool first = false;
 | 
					                bool first = false;
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    std::lock_guard<std::mutex> lock(mux);
 | 
					                    std::lock_guard<std::mutex> lock(mux);
 | 
				
			||||||
| 
						 | 
					@ -87,6 +130,7 @@ namespace smt {
 | 
				
			||||||
                        finished_id = i;
 | 
					                        finished_id = i;
 | 
				
			||||||
                        first = true;
 | 
					                        first = true;
 | 
				
			||||||
                        result = r;
 | 
					                        result = r;
 | 
				
			||||||
 | 
					                        done = true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (!first) return;
 | 
					                if (!first) return;
 | 
				
			||||||
| 
						 | 
					@ -106,6 +150,7 @@ namespace smt {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while (!done) {
 | 
				
			||||||
            vector<std::thread> threads(num_threads);
 | 
					            vector<std::thread> threads(num_threads);
 | 
				
			||||||
            for (unsigned i = 0; i < num_threads; ++i) {
 | 
					            for (unsigned i = 0; i < num_threads; ++i) {
 | 
				
			||||||
                threads[i] = std::thread([&, i]() { worker_thread(i); });
 | 
					                threads[i] = std::thread([&, i]() { worker_thread(i); });
 | 
				
			||||||
| 
						 | 
					@ -113,7 +158,12 @@ namespace smt {
 | 
				
			||||||
            for (auto & th : threads) {
 | 
					            for (auto & th : threads) {
 | 
				
			||||||
                th.join();
 | 
					                th.join();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            if (done) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            collect_units();
 | 
				
			||||||
 | 
					            ++num_rounds;
 | 
				
			||||||
 | 
					            max_conflicts *= 2;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (context* c : pctxs) {
 | 
					        for (context* c : pctxs) {
 | 
				
			||||||
            c->collect_statistics(ctx.m_aux_stats);
 | 
					            c->collect_statistics(ctx.m_aux_stats);
 | 
				
			||||||
| 
						 | 
					@ -137,7 +187,7 @@ namespace smt {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case l_false:
 | 
					        case l_false:
 | 
				
			||||||
            for (expr* e : pctx.m_unsat_core) 
 | 
					            for (expr* e : pctx.unsat_core()) 
 | 
				
			||||||
                ctx.m_unsat_core.push_back(tr(e));
 | 
					                ctx.m_unsat_core.push_back(tr(e));
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,18 +24,11 @@ namespace smt {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class parallel {
 | 
					    class parallel {
 | 
				
			||||||
        context& ctx;
 | 
					        context& ctx;
 | 
				
			||||||
        expr_ref_vector     m_unit_trail;
 | 
					 | 
				
			||||||
        obj_hashtable<expr> m_unit_set;
 | 
					 | 
				
			||||||
        unsigned_vector     m_unit_lim;
 | 
					 | 
				
			||||||
        std::mutex          m_mux;
 | 
					 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
        parallel(context& ctx): ctx(ctx), m_unit_trail(ctx.m) {}
 | 
					        parallel(context& ctx): ctx(ctx) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        lbool operator()(expr_ref_vector const& asms);
 | 
					        lbool operator()(expr_ref_vector const& asms);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void add_unit(context& ctx, expr* e);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        void get_units(unsigned idx, context& pctx);
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue