Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
MallobSharing.hpp
1#pragma once
2
3#include "GlobalSharingStrategy.hpp"
4#include "containers/Bitset.hpp"
5#include "containers/ClauseUtils.hpp"
6#include <vector>
7
9{
10 int32_t productionEpoch; /* last epoch clause was produced */
11 int32_t sharedEpoch; /* last epoch where clause was shared and imported! */
12 uint64_t sources; /* acts like a bitset */
13};
14
25{
26 public:
38 MallobSharing(const std::shared_ptr<ClauseDatabase>& clauseDB,
39 unsigned long baseBufferSize,
40 unsigned long maxBufferSize,
41 unsigned int lbdLimitAtImport,
42 unsigned int sizeLimitAtImport,
43 unsigned int roundsPerSecond,
44 float maxCompensation,
45 /*Filter Options*/
46 unsigned int resharePeriodMicroSec);
47
52
57 bool initMpiVariables() override;
58
63 bool doSharing() override;
64
71 void joinProcess(int winnerRank, SatResult res, const std::vector<int>& model) override;
72
78 bool importClause(const ClauseExchangePtr& cls) override;
79
84 std::chrono::microseconds getSleepingTime() override;
85
86 protected:
93 bool exportClauseToClient(const ClauseExchangePtr& clause, std::shared_ptr<SharingEntity> client) override;
94
99 void deserializeClauses(const std::vector<int>& serialized_v_cls);
100
109 int mergeSerializedBuffersWithMine(std::vector<std::reference_wrapper<std::vector<int>>>& buffers,
110 std::vector<int>& result,
111 size_t& nonFreeLiteralsCount);
112
117 void computeBufferSize(unsigned int aggregationsCount);
118
124 bool getOneClauseWrapper(ClauseExchangePtr& cls)
125 {
126 if (this->m_clauseDB->getOneClause(cls)) {
127 return insertClause(cls);
128 }
129 return false;
130 }
131
136
137 unsigned int defaultBufferSize;
138 const unsigned int baseSize;
139 const unsigned int maxSize;
140
141 std::vector<std::reference_wrapper<std::vector<int>>> buffers;
142
143 std::vector<int> clausesToSendSerialized;
144 std::vector<int> receivedClausesLeft;
145 std::vector<int> receivedClausesRight;
146 std::vector<int> receivedClausesFather;
147
148 std::vector<ClauseExchangePtr> deserializedClauses;
149
151
152 int father;
156
157 size_t sleepTime;
158
160
163 unsigned m_freeSize;
164
173
174 // Filter (To be moved when Filter Interface is established)
175 // ======
176 public:
185 void initializeFilter(unsigned int resharingPeriod,
186 unsigned int sharingsPerSecond,
187 unsigned int maxProducerId = 63);
188
195 bool doesClauseExist(const ClauseExchangePtr& cls) const;
196
203 void updateClause(const ClauseExchangePtr& cls);
204
218 bool insertClause(const ClauseExchangePtr& cls);
219
229 bool isClauseShared(const ClauseExchangePtr& cls) const;
230
241 bool canConsumerImportClause(const ClauseExchangePtr& cls, unsigned consumerId);
242
247
255 void markClauseAsShared(ClauseExchangePtr& cls);
256
262 size_t shrinkFilter();
263
264 private:
265 unsigned m_sharingPerSecond;
266 unsigned m_maxProducerId;
267 int m_currentEpoch;
268 int m_resharingPeriodInEpochs;
276 std::unordered_map<ClauseExchangePtr,
280 m_clauseMetaMap;
281};
A class representing a bitset with dynamic size.
Definition Bitset.hpp:14
Base class for global clause sharing strategies across MPI processes.
Definition GlobalSharingStrategy.hpp:27
Implements a global sharing strategy based on the Mallob algorithm.
Definition MallobSharing.hpp:25
unsigned int defaultBufferSize
Default size of the sharing buffer.
Definition MallobSharing.hpp:137
std::vector< int > receivedClausesFather
Buffer for clauses received from parent.
Definition MallobSharing.hpp:146
bool exportClauseToClient(const ClauseExchangePtr &clause, std::shared_ptr< SharingEntity > client) override
Exports a clause to a specific client.
std::vector< ClauseExchangePtr > deserializedClauses
Buffer for deserialized clauses.
Definition MallobSharing.hpp:148
float accumulatedAdmittedLiterals
Accumulated number of literals shared to parent.
Definition MallobSharing.hpp:165
const int lbdLimitAtImport
LBD limit for clause import.
Definition MallobSharing.hpp:161
bool doSharing() override
Performs the clause sharing operation.
bool insertClause(const ClauseExchangePtr &cls)
Inserts a new clause or updates an existing one in the sharing map.
float compensationFactor
Factor for volume compensation.
Definition MallobSharing.hpp:169
MallobSharing(const std::shared_ptr< ClauseDatabase > &clauseDB, unsigned long baseBufferSize, unsigned long maxBufferSize, unsigned int lbdLimitAtImport, unsigned int sizeLimitAtImport, unsigned int roundsPerSecond, float maxCompensation, unsigned int resharePeriodMicroSec)
Constructor for MallobSharing.
bool initMpiVariables() override
Initializes MPI-related variables.
size_t lastEpochAdmittedLits
Number of literals in last epoch final buffer.
Definition MallobSharing.hpp:167
bool addChildClauses
Flag to determine if child clauses should be added.
Definition MallobSharing.hpp:159
const unsigned int maxSize
Maximum size for buffer calculations.
Definition MallobSharing.hpp:139
std::vector< int > receivedClausesRight
Buffer for clauses received from right child.
Definition MallobSharing.hpp:145
float estimatedIncomingLits
Estimated number of incoming literals.
Definition MallobSharing.hpp:171
bool doesClauseExist(const ClauseExchangePtr &cls) const
Checks if a clause exists in the sharing map.
int mergeSerializedBuffersWithMine(std::vector< std::reference_wrapper< std::vector< int > > > &buffers, std::vector< int > &result, size_t &nonFreeLiteralsCount)
Merges serialized buffers with local clauses from the m_clauseDB database.
bool isClauseShared(const ClauseExchangePtr &cls) const
Checks if a clause has been shared recently.
float estimatedSharedLits
Estimated number of shared literals.
Definition MallobSharing.hpp:172
void incrementEpoch()
Increments the current epoch.
const int sizeLimitAtImport
Size limit for clause import.
Definition MallobSharing.hpp:162
float maxCompensationFactor
Maximum Compensation factor.
Definition MallobSharing.hpp:170
Bitset myBitVector
Bitset for tracking shared clauses.
Definition MallobSharing.hpp:150
int left_child
MPI rank of the left child.
Definition MallobSharing.hpp:153
bool importClause(const ClauseExchangePtr &cls) override
Imports a clause into the clause database.
const unsigned int baseSize
Base size for buffer calculations.
Definition MallobSharing.hpp:138
size_t lastEpochReceivedLits
Number of literals received in last epoch.
Definition MallobSharing.hpp:168
int right_child
MPI rank of the right child.
Definition MallobSharing.hpp:154
unsigned m_freeSize
Clause size not counted in the buffer at serialization.
Definition MallobSharing.hpp:163
std::vector< std::reference_wrapper< std::vector< int > > > buffers
Buffers for clause sharing.
Definition MallobSharing.hpp:141
void initializeFilter(unsigned int resharingPeriod, unsigned int sharingsPerSecond, unsigned int maxProducerId=63)
Initializes the sharing filter with given parameters.
std::vector< int > clausesToSendSerialized
Buffer for serialized clauses to send.
Definition MallobSharing.hpp:143
void computeCompensation()
Computes the compensation factor for volume balancing.
std::chrono::microseconds getSleepingTime() override
Gets the sleeping time for the sharing strategy.
int father
MPI rank of the parent node.
Definition MallobSharing.hpp:152
float accumulatedDesiredLiterals
Accumulated number of literals received from children.
Definition MallobSharing.hpp:166
void updateClause(const ClauseExchangePtr &cls)
Updates the metadata for an existing clause.
~MallobSharing()
Destructor for MallobSharing.
void deserializeClauses(const std::vector< int > &serialized_v_cls)
Deserializes received clauses.
bool getOneClauseWrapper(ClauseExchangePtr &cls)
Wrapper for getting one clause from the database. This remove the need to make the filter thread-safe...
Definition MallobSharing.hpp:124
size_t shrinkFilter()
Shrinks the filter to remove entries of clauses that can be reshared. Once a clause was shared m_resh...
void joinProcess(int winnerRank, SatResult res, const std::vector< int > &model) override
Handles the process of joining when a solution is found.
std::vector< int > receivedClausesLeft
Buffer for clauses received from left child.
Definition MallobSharing.hpp:144
int nb_children
Number of children nodes.
Definition MallobSharing.hpp:155
void markClauseAsShared(ClauseExchangePtr &cls)
Marks a clause as shared, updating its metadata.
bool canConsumerImportClause(const ClauseExchangePtr &cls, unsigned consumerId)
Determines if a consumer can import a given clause.
void computeBufferSize(unsigned int aggregationsCount)
Computes the buffer size based on the number of aggregations.
size_t sleepTime
Sleep time between sharing operations.
Definition MallobSharing.hpp:157
std::shared_ptr< ClauseDatabase > m_clauseDB
Clause database where exported clauses are stored.
Definition SharingStrategy.hpp:147
SatResult
Enumeration for SAT solver results.
Definition SolverInterface.hpp:39
Definition MallobSharing.hpp:9
Equality functor for ClauseExchangePtr objects.
Definition ClauseUtils.hpp:151
Hash functor for ClauseExchangePtr objects.
Definition ClauseUtils.hpp:143