Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
HordeSatSharing.hpp
1#pragma once
2
3#include "sharing/Filters/BloomFilter.hpp"
4#include "sharing/SharingStrategy.hpp"
5
6#include <atomic>
7#include <unordered_map>
8#include <vector>
9
22{
23 public:
33 HordeSatSharing(const std::shared_ptr<ClauseDatabase>& clauseDB,
34 unsigned long literalsPerProducerPerRound,
35 unsigned int initialLbdLimit,
36 unsigned int roundsBeforeLbdIncrease,
37 const std::vector<std::shared_ptr<SharingEntity>>& producers = {},
38 const std::vector<std::shared_ptr<SharingEntity>>& consumers = {});
39
44
45 // SharingEntity Interface
46 // =======================
53 bool importClause(const ClauseExchangePtr& clause) override;
54
59 void importClauses(const std::vector<ClauseExchangePtr>& v_clauses) override
60 {
61 for (auto clause : v_clauses)
62 importClause(clause);
63 }
64
65 // SharingStrategy Interface
66 // =========================
67
73 bool doSharing() override;
74
75 protected:
81 void addProducer(std::shared_ptr<SharingEntity> producer) override
82 {
84 /* lock m_producerMutex is released */
85
86 this->lbdLimitPerProducer.emplace(producer->getSharingId(), initialLbdLimit);
87 this->literalsPerProducer.emplace(producer->getSharingId(), 0);
88 }
89
94 void removeProducer(std::shared_ptr<SharingEntity> producer) override
95 {
97 /* lock m_producer is released */
98 this->lbdLimitPerProducer.erase(producer->getSharingId());
99 this->literalsPerProducer.erase(producer->getSharingId());
100 }
101
102 protected:
104 unsigned long literalPerRound;
105
107 unsigned int initialLbdLimit;
108
111
113 int round;
114
116 std::vector<ClauseExchangePtr> selection;
117
118 // Static Constants
119 // ----------------
120
121 static constexpr int UNDER_UTILIZATION_THRESHOLD = 75;
122 static constexpr int OVER_UTILIZATION_THRESHOLD = 98;
123
124 // Data accessible from other threads via importClause
125 // ---------------------------------------------------
126
128 std::unordered_map<unsigned int, std::atomic<unsigned int>> lbdLimitPerProducer;
129
131 std::unordered_map<unsigned int, std::atomic<unsigned long>> literalsPerProducer;
132};
133
This strategy is a HordeSat-like sharing strategy.
Definition HordeSatSharing.hpp:22
~HordeSatSharing()
Destructor for HordeSatSharing.
int round
Round Number.
Definition HordeSatSharing.hpp:113
std::unordered_map< unsigned int, std::atomic< unsigned long > > literalsPerProducer
Metadata for clause database.
Definition HordeSatSharing.hpp:131
bool doSharing() override
Performs the sharing operation. It checks the literal production to decide if the lbd limit should be...
void addProducer(std::shared_ptr< SharingEntity > producer) override
Adds a producer to the sharing strategy. It initializes the lbd limit and the per round literal produ...
Definition HordeSatSharing.hpp:81
void importClauses(const std::vector< ClauseExchangePtr > &v_clauses) override
Imports multiple clauses.
Definition HordeSatSharing.hpp:59
std::unordered_map< unsigned int, std::atomic< unsigned int > > lbdLimitPerProducer
SharingEntity id to lbdLimit.
Definition HordeSatSharing.hpp:128
unsigned int initialLbdLimit
Initial lbd value for per producer filter.
Definition HordeSatSharing.hpp:107
unsigned long literalPerRound
Number of shared literals per round.
Definition HordeSatSharing.hpp:104
unsigned int roundBeforeIncrease
Number of rounds before forcing an increase in production.
Definition HordeSatSharing.hpp:110
std::vector< ClauseExchangePtr > selection
Used to manipulate clauses (as a member to reduce number of allocations).
Definition HordeSatSharing.hpp:116
HordeSatSharing(const std::shared_ptr< ClauseDatabase > &clauseDB, unsigned long literalsPerProducerPerRound, unsigned int initialLbdLimit, unsigned int roundsBeforeLbdIncrease, const std::vector< std::shared_ptr< SharingEntity > > &producers={}, const std::vector< std::shared_ptr< SharingEntity > > &consumers={})
Constructor for HordeSatSharing.
bool importClause(const ClauseExchangePtr &clause) override
Imports a single clause if the lbd limit is respected. And updates the amount of literals exprted by ...
void removeProducer(std::shared_ptr< SharingEntity > producer) override
Removes a producer from the sharing strategy.
Definition HordeSatSharing.hpp:94
SharingStrategy class, inheriting from SharingEntity.
Definition SharingStrategy.hpp:26
virtual void removeProducer(std::shared_ptr< SharingEntity > producer)
Removes a producer from this strategy.
Definition SharingStrategy.hpp:120
virtual void addProducer(std::shared_ptr< SharingEntity > producer)
Adds a producer to this strategy.
Definition SharingStrategy.hpp:98