#include <scheduler.hpp>
Public Member Functions | |
Scheduler (std::vector< Solv * > s) | |
Constructor. | |
~Scheduler () | |
Destructor. | |
template<class Cont> | |
size_t | get_solved_problems (Cont &c) |
Fetch solved problems. | |
bool | is_error (void) |
Return true on errors. | |
bool | is_running (void) |
Return true if scheduler is running. | |
template<class Cont1, class Cont2> | |
size_t | get_errors (Cont1 &e, Cont2 &p) |
Fetch errors and corresponding problems. | |
void | run (void) |
Run threads. | |
void | add_problem (Prob *p) |
Add problem to input queue. | |
void | add_problems (std::vector< Prob * > p) |
Add multiple problems to input queue. | |
bool | finish (void) |
Wait for all problems to be solved. | |
Friends | |
class | Consumer |
Classes | |
class | Consumer |
Scheduler uses a manager thread and a given number of working threads for solving problems. Scheduler is templated with Solver, Problem and Error classes. Solver class has to provide an operator
void operator()( Problem *p, Scheduler<Solver,Problem,Error> &s )
Error class has to have a default constructor. Scheduler catches the errors of this type from the working threads and saves caught errors in a container. If an error is caught, all the working threads are interrupted and problem solving is finished. The scheduler does indicate the error state by returning false from finish(). Error state can also be queried with is_error(). Errors can be fetched from the internal containers with get_errors().
The Scheduler can be used for static and dynamic problems. All threads can add problems using add_problems(). The functions are mutex protected. Scheduler provides functions to diagnose the ending and status of the process.
Scheduler< Solv, Prob, Err >::Scheduler | ( | std::vector< Solv * > | s | ) | [inline] |
Constructor.
s | Vector of solvers to be used by N problem consumers, where N is the size of the vector. |
Destructor.
void Scheduler< Solv, Prob, Err >::add_problem | ( | Prob * | p | ) | [inline] |
Add problem to input queue.
void Scheduler< Solv, Prob, Err >::add_problems | ( | std::vector< Prob * > | p | ) | [inline] |
Add multiple problems to input queue.
bool Scheduler< Solv, Prob, Err >::finish | ( | void | ) | [inline] |
Wait for all problems to be solved.
size_t Scheduler< Solv, Prob, Err >::get_errors | ( | Cont1 & | e, | |
Cont2 & | p | |||
) | [inline] |
Fetch errors and corresponding problems.
e | Container where errors are appended | |
p | Container where problems are appended |
size_t Scheduler< Solv, Prob, Err >::get_solved_problems | ( | Cont & | c | ) | [inline] |
Fetch solved problems.
c | Container object where pointers to solved problems are appended. |
bool Scheduler< Solv, Prob, Err >::is_error | ( | void | ) | [inline] |
Return true on errors.
bool Scheduler< Solv, Prob, Err >::is_running | ( | void | ) | [inline] |
Return true if scheduler is running.
void Scheduler< Solv, Prob, Err >::run | ( | void | ) | [inline] |
Run threads.
Returns immediately after creating working threads. Use finish() or destructor of class to wait for work to be completed.
friend class Consumer [friend] |