Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
GlobalSharingStrategy.hpp
1#pragma once
2
3#include "sharing/Filters/BloomFilter.hpp"
4#include "sharing/SharingStatistics.hpp"
5#include "sharing/SharingStrategy.hpp"
6
7#include "solvers/SolverInterface.hpp"
8
9#include <mpi.h>
10
27{
28
29 public:
36 GlobalSharingStrategy(const std::shared_ptr<ClauseDatabase>& clauseDB,
37 const std::vector<std::shared_ptr<SharingEntity>>& producers = {},
38 const std::vector<std::shared_ptr<SharingEntity>>& consumers = {});
39
42
43 //===================================================================================
44 // SharingEntity interface (save in m_clauseDB)
45 //===================================================================================
51 bool importClause(const ClauseExchangePtr& cls) override
52 {
53 LOGDEBUG3("Global Strategy %d importing a cls %p", this->getSharingId(), cls.get());
54 return m_clauseDB->addClause(cls);
55 };
56
61 void importClauses(const std::vector<ClauseExchangePtr>& v_cls) override
62 {
63 for (auto& cls : v_cls)
64 importClause(cls);
65 }
66
73 bool exportClauseToClient(const ClauseExchangePtr& clause, std::shared_ptr<SharingEntity> client)
74 {
76 "Global Strategy %d exports a cls %p to %d", this->getSharingId(), clause.get(), client->getSharingId());
77 return client->importClause(clause);
78 }
79
80 //===================================================================================
81 // GlobalSharingStrategy interface
82 //===================================================================================
83
88 std::chrono::microseconds getSleepingTime() override;
89
96 virtual void joinProcess(int winnerRank, SatResult res, const std::vector<int>& model);
97
101 void printStats() override;
102
108 virtual bool initMpiVariables();
109
115 virtual bool doSharing() override;
116
117 protected:
120 std::vector<MPI_Request> recv_end_requests;
121 MPI_Request send_end_request;
122 std::vector<int> receivedFinalResultRoot;
123};
124
#define LOGDEBUG3(...)
Log a debug message with verbosity level 4 and magenta color.
Definition Logger.hpp:229
Base class for global clause sharing strategies across MPI processes.
Definition GlobalSharingStrategy.hpp:27
GlobalSharingStrategy(const std::shared_ptr< ClauseDatabase > &clauseDB, const std::vector< std::shared_ptr< SharingEntity > > &producers={}, const std::vector< std::shared_ptr< SharingEntity > > &consumers={})
Constructor for GlobalSharingStrategy.
GlobalSharingStatistics gstats
Statistics for global sharing.
Definition GlobalSharingStrategy.hpp:118
virtual bool doSharing() override
Performs the clause sharing operation.
bool requests_sent
Flag indicating if requests to end were sent to the root.
Definition GlobalSharingStrategy.hpp:119
MPI_Request send_end_request
MPI request for non-root Isend for final synchronization with root.
Definition GlobalSharingStrategy.hpp:121
std::vector< int > receivedFinalResultRoot
Buffer for storing results received from other mpi processes.
Definition GlobalSharingStrategy.hpp:122
void importClauses(const std::vector< ClauseExchangePtr > &v_cls) override
Imports multiple clauses into the clause database.
Definition GlobalSharingStrategy.hpp:61
virtual bool initMpiVariables()
Initializes MPI-related variables.
virtual ~GlobalSharingStrategy()
Destructor.
bool importClause(const ClauseExchangePtr &cls) override
Imports a clause into the clause database.
Definition GlobalSharingStrategy.hpp:51
std::chrono::microseconds getSleepingTime() override
Gets the sleeping time for the sharing strategy.
void printStats() override
Prints the statistics of the sharing strategy.
virtual void joinProcess(int winnerRank, SatResult res, const std::vector< int > &model)
Handles the process of joining when a solution is found.
std::vector< MPI_Request > recv_end_requests
MPI requests for non-blocking receive of end signals.
Definition GlobalSharingStrategy.hpp:120
bool exportClauseToClient(const ClauseExchangePtr &clause, std::shared_ptr< SharingEntity > client)
Exports a clause to a specific client.
Definition GlobalSharingStrategy.hpp:73
int getSharingId() const
Get the sharing ID of this entity.
Definition SharingEntity.hpp:89
SharingStrategy class, inheriting from SharingEntity.
Definition SharingStrategy.hpp:26
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
Statistics of a global sharing strategy.
Definition SharingStatistics.hpp:23