External control for the requested number of search workers. More...
#include <gecode/search.hh>
Public Member Functions | |
| WorkerControl (void) noexcept | |
| Construct an empty handle. | |
| WorkerControl (unsigned int requested) | |
| Construct an engaged handle with initial request requested (zero pauses). | |
| WorkerControl (const WorkerControl &control) | |
| Copy constructor. | |
| WorkerControl & | operator= (const WorkerControl &control) |
| Assignment operator. | |
| ~WorkerControl (void) | |
| Destructor. | |
| bool | engaged (void) const noexcept |
| Whether this handle is engaged. | |
| unsigned int | requested (void) const noexcept |
| Return the requested number of workers (zero also denotes an empty handle). | |
| void | request (unsigned int workers) |
| Request workers workers (zero pauses the engine). | |
| unsigned int | capacity (void) const noexcept |
| Return the fixed worker capacity, or zero before attachment. | |
Detailed Description
External control for the requested number of search workers.
A worker control is a copyable handle. Copies share the same request and can be used concurrently. An empty handle disables adjustment. DFS and BAB support worker control, as do experimental AStar and CABS. The resolved Options::threads value fixes the engine's worker capacity. Requests range from zero to that capacity; zero pauses search without discarding its state. This also applies to an engine with capacity one. Without thread support, use controls from one thread; attaching a zero request or calling request(0) raises InvalidWorkerRequest.
For example, the caller can keep a handle for an external scheduler:
Requests take effect cooperatively at scheduler boundaries. A decrease lets excess workers finish their current search action before parking. An increase wakes parked workers. Parked operating-system threads retain their stacks and search state, so capacity should cover the largest allocation the engine may receive. Adjustment preserves search correctness; parallel exploration order and search statistics remain nondeterministic.
A shared control identity can attach to one leaf engine only. Sharing it between engines, attaching it to an enclosing meta-engine, or reusing it after engine destruction raises WorkerControlInUse. Copies may outlive the engine; subsequent in-range requests are harmless. Engine destruction detaches its state but does not make the identity reusable.
Restart-based search retains its DFS or BAB leaf control across restarts. For portfolio search, give each asset a distinct control through its engine builder. Controlled assets require a parallel outer PBS; sequential PBS rejects them with WorkerControlInUse before consuming roots or builders. PBS completes each next() round after every active asset reports. A paused asset observes the internal round stop and reports without resuming search; if all active assets are paused, next() waits until one resumes.
The caller enforces any shared worker budget. Decrease one asset's request before increasing another's to keep the requested sum within that budget. Workers finishing their current actions can still cause temporary oversubscription. Gecode provides no acknowledgement that a decrease has taken effect and chooses no allocation policy.
Constructor & Destructor Documentation
◆ WorkerControl() [1/3]
|
noexcept |
Construct an empty handle.
◆ WorkerControl() [2/3]
|
explicit |
Construct an engaged handle with initial request requested (zero pauses).
◆ WorkerControl() [3/3]
| Gecode::Search::WorkerControl::WorkerControl | ( | const WorkerControl & | control | ) |
Copy constructor.
◆ ~WorkerControl()
| Gecode::Search::WorkerControl::~WorkerControl | ( | void | ) |
Destructor.
Member Function Documentation
◆ operator=()
| WorkerControl & Gecode::Search::WorkerControl::operator= | ( | const WorkerControl & | control | ) |
Assignment operator.
◆ engaged()
|
noexcept |
Whether this handle is engaged.
◆ requested()
|
noexcept |
Return the requested number of workers (zero also denotes an empty handle).
◆ request()
| void Gecode::Search::WorkerControl::request | ( | unsigned int | workers | ) |
Request workers workers (zero pauses the engine).
Returns without waiting for workers to reach the requested count. Throws UninitializedWorkerControl for an empty handle, or InvalidWorkerRequest if workers exceeds the fixed capacity or is zero in a build without thread support.
◆ capacity()
|
noexcept |
Return the fixed worker capacity, or zero before attachment.
The documentation for this class was generated from the following file:
- gecode/search.hh
