|
Antares Xpansion
Investment simulations for Antares studies
|
Strategy interface for communication operations in Benders decomposition. More...
#include <ICommunicationStrategy.h>
Public Member Functions | |
| virtual int | Rank () const =0 |
| Return the rank of this process (0 for sequential) | |
| virtual int | WorldSize () const =0 |
| Return the total number of processes (1 for sequential) | |
| bool | IsMaster () const |
| Whether this process is the master (rank 0) | |
| virtual void | Barrier () const =0 |
| Synchronization barrier across all processes (no-op for sequential) | |
| virtual bool | ShouldParallelize () const =0 |
Strategy interface for communication operations in Benders decomposition.
This interface abstracts the communication layer (MPI vs sequential) from the Benders algorithm. It follows the Strategy Pattern to decouple the parallelism dimension from the algorithmic logic:
By injecting this strategy into BendersBase, the same algorithmic code can run in different execution contexts without inheritance-based specialization.
Concrete subclasses choose their strategy internally and do not expose the injection in their own constructors:
// BendersMpi wraps an mpi::communicator and builds MpiCommunicationStrategy internally: auto benders = std::make_unique<BendersMpi>(options, logger, writer, world, mathLoggerDriver);
// BendersSequential builds SequentialCommunicationStrategy internally (no world needed): auto benders = std::make_unique<BendersSequential>(options, logger, writer, mathLoggerDriver);
Direct strategy injection is available through the BendersBase constructor for custom subclasses (e.g., test doubles or future execution backends):
auto strategy = std::make_shared<MyCustomStrategy>(); // Pass as the optional last argument to BendersBase: // BendersBase(options, logger, writer, mathLoggerDriver, strategy)
|
pure virtual |
Synchronization barrier across all processes (no-op for sequential)
Implemented in MpiCommunicationStrategy, and SequentialCommunicationStrategy.
|
nodiscardpure virtual |
Return the rank of this process (0 for sequential)
Implemented in MpiCommunicationStrategy, and SequentialCommunicationStrategy.
|
nodiscardpure virtual |
Whether subproblems should be parallelized locally using TBB. Returns true for sequential (local parallelism), false for MPI (distribution handles parallelism across ranks).
Implemented in MpiCommunicationStrategy, and SequentialCommunicationStrategy.
|
nodiscardpure virtual |
Return the total number of processes (1 for sequential)
Implemented in MpiCommunicationStrategy, and SequentialCommunicationStrategy.