Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
SharingStrategy Class Referenceabstract

SharingStrategy class, inheriting from SharingEntity. More...

#include <SharingStrategy.hpp>

Inheritance diagram for SharingStrategy:
Collaboration diagram for SharingStrategy:

Public Member Functions

 SharingStrategy (const std::vector< std::shared_ptr< SharingEntity > > &producers, const std::vector< std::shared_ptr< SharingEntity > > &consumers, const std::shared_ptr< ClauseDatabase > &clauseDB)
 Constructor for SharingStrategy. Be sure to call connectConstructorProducers after construction, this is due to the base class shared_from_this.
 
virtual ~SharingStrategy ()
 Virtual destructor.
 
virtual bool doSharing ()=0
 Executes the sharing process from producers to consumers.
 
virtual std::chrono::microseconds getSleepingTime ()
 Determines the sleeping time for the sharer.
 
virtual void printStats ()
 Prints the statistics of the strategy.
 
void connectConstructorProducers ()
 Add this to the producers' clients list.
 
virtual void addProducer (std::shared_ptr< SharingEntity > producer)
 Adds a producer to this strategy.
 
virtual void connectProducer (std::shared_ptr< SharingEntity > producer)
 Connect a producer to this strategy. Add (this) to clients of (producer)
 
virtual void removeProducer (std::shared_ptr< SharingEntity > producer)
 Removes a producer from this strategy.
 
- Public Member Functions inherited from SharingEntity
 SharingEntity ()
 Construct a new SharingEntity object.
 
 SharingEntity (const std::vector< std::shared_ptr< SharingEntity > > &clients)
 Construct a new SharingEntity object.
 
virtual ~SharingEntity ()
 Destroy the SharingEntity object.
 
virtual bool importClause (const ClauseExchangePtr &clause)=0
 Import a single clause to this sharing entity.
 
virtual void importClauses (const std::vector< ClauseExchangePtr > &v_clauses)=0
 Import multiple clauses to this sharing entity.
 
int getSharingId () const
 Get the sharing ID of this entity.
 
void setSharingId (int _id)
 Set the sharing ID of this entity.
 
virtual void addClient (std::shared_ptr< SharingEntity > client)
 Add a client to this entity.
 
virtual void removeClient (std::shared_ptr< SharingEntity > client)
 Remove a specific client from this entity.
 
size_t getClientCount () const
 Get the current number of clients.
 
void clearClients ()
 Remove all clients.
 

Protected Member Functions

bool exportClauseToClient (const ClauseExchangePtr &clause, std::shared_ptr< SharingEntity > client) override
 A SharingStrategy doesn't send a clause to the source client (->from must store the sharingId of its producer)
 
- Protected Member Functions inherited from SharingEntity
bool exportClause (const ClauseExchangePtr &clause)
 Export a clause to all registered clients.
 
void exportClauses (const std::vector< ClauseExchangePtr > &clauses)
 Export multiple clauses to all registered clients.
 

Protected Attributes

std::shared_ptr< ClauseDatabasem_clauseDB
 Clause database where exported clauses are stored.
 
SharingStatistics stats
 Sharing statistics.
 
std::vector< std::weak_ptr< SharingEntity > > m_producers
 The set holding the references to the producers.
 
std::shared_mutex m_producersMutex
 Shared mutex for producers list (to become RCU ?)
 
- Protected Attributes inherited from SharingEntity
std::vector< std::weak_ptr< SharingEntity > > m_clients
 List of weak pointers to client SharingEntities.
 
std::shared_mutex m_clientsMutex
 Mutex to protect access to m_clients.
 

Detailed Description

SharingStrategy class, inheriting from SharingEntity.

SharingStrategy serves as a central manager that receives clauses from producers and distributes them to consumers. It orchestrates the exchange of clauses between different entities in a solver.

Todo

Private constructors (+ move and copy constructors), wrappers for constructors that calls connectProducers and returns a smart pointer

Test userspace RCU for m_producers

Constructor & Destructor Documentation

◆ SharingStrategy()

SharingStrategy::SharingStrategy ( const std::vector< std::shared_ptr< SharingEntity > > & producers,
const std::vector< std::shared_ptr< SharingEntity > > & consumers,
const std::shared_ptr< ClauseDatabase > & clauseDB )
inline

Constructor for SharingStrategy. Be sure to call connectConstructorProducers after construction, this is due to the base class shared_from_this.

Parameters
producersA vector of shared pointers to SharingEntity objects that produce clauses.
consumersA vector of shared pointers to SharingEntity objects that consume clauses.
clauseDBA shared pointer to the ClauseDatabase where exported clauses are stored.

This constructor initializes the SharingStrategy with the given producers, consumers, and clause database. It stores weak pointers to the producers and consumers internally since it doesn't own the object but just communicate with it if possible.

Warning
Be sure to call connectConstructorProducers after construction, this is due to the base class shared_from_this

Member Function Documentation

◆ addProducer()

virtual void SharingStrategy::addProducer ( std::shared_ptr< SharingEntity > producer)
inlinevirtual

Adds a producer to this strategy.

Parameters
producerThe producer SharingEntity to add.

Reimplemented in HordeSatSharing.

◆ connectConstructorProducers()

void SharingStrategy::connectConstructorProducers ( )
inline

Add this to the producers' clients list.

Warning
Be Careful! connect only constructor lists, (otherwise this strategy can be added twice)

◆ connectProducer()

virtual void SharingStrategy::connectProducer ( std::shared_ptr< SharingEntity > producer)
inlinevirtual

Connect a producer to this strategy. Add (this) to clients of (producer)

Parameters
producerThe producer SharingEntity to connect to.
Warning
A producer should be connect only if it was added beforehand (necessary initialization done)

◆ doSharing()

virtual bool SharingStrategy::doSharing ( )
pure virtual

Executes the sharing process from producers to consumers.

Returns
true if the sharer should end, false otherwise.

Implemented in AllGatherSharing, GenericGlobalSharing, GlobalSharingStrategy, HordeSatSharing, MallobSharing, and SimpleSharing.

◆ exportClauseToClient()

bool SharingStrategy::exportClauseToClient ( const ClauseExchangePtr & clause,
std::shared_ptr< SharingEntity > client )
inlineoverrideprotectedvirtual

A SharingStrategy doesn't send a clause to the source client (->from must store the sharingId of its producer)

Reimplemented from SharingEntity.

◆ getSleepingTime()

virtual std::chrono::microseconds SharingStrategy::getSleepingTime ( )
inlinevirtual

Determines the sleeping time for the sharer.

Returns
Number of microseconds to sleep.

Reimplemented in GlobalSharingStrategy, and MallobSharing.

◆ printStats()

virtual void SharingStrategy::printStats ( )
inlinevirtual

Prints the statistics of the strategy.

Reimplemented in GlobalSharingStrategy.

◆ removeProducer()

virtual void SharingStrategy::removeProducer ( std::shared_ptr< SharingEntity > producer)
inlinevirtual

Removes a producer from this strategy.

Parameters
producerThe producer SharingEntity to remove.

Reimplemented in HordeSatSharing.


The documentation for this class was generated from the following file: