Scheduler< Solv, Prob, Err > Class Template Reference

Scheduler class for implementing consumer-producer threading. More...

#include <scheduler.hpp>

List of all members.

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


Detailed Description

template<class Solv, class Prob, class Err>
class Scheduler< Solv, Prob, Err >

Scheduler class for implementing consumer-producer threading.

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 ) 
to solve problem p. Handle to scheduler itself in this function is provided to solver so that solver can access add_problems() for hierarchial construction of problems. Problem is only used by user defined solver class and Scheduler does not pose any requirements to it.

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.


Constructor & Destructor Documentation

template<class Solv, class Prob, class Err>
Scheduler< Solv, Prob, Err >::Scheduler ( std::vector< Solv * >  s  )  [inline]

Constructor.

Parameters:
s Vector of solvers to be used by N problem consumers, where N is the size of the vector.

template<class Solv, class Prob, class Err>
Scheduler< Solv, Prob, Err >::~Scheduler (  )  [inline]

Destructor.


Member Function Documentation

template<class Solv, class Prob, class Err>
void Scheduler< Solv, Prob, Err >::add_problem ( Prob *  p  )  [inline]

Add problem to input queue.

template<class Solv, class Prob, class Err>
void Scheduler< Solv, Prob, Err >::add_problems ( std::vector< Prob * >  p  )  [inline]

Add multiple problems to input queue.

template<class Solv, class Prob, class Err>
bool Scheduler< Solv, Prob, Err >::finish ( void   )  [inline]

Wait for all problems to be solved.

Returns:
True if finished already or finish() already called. False if any error occured during run or scheduler not running.

template<class Solv, class Prob, class Err>
template<class Cont1, class Cont2>
size_t Scheduler< Solv, Prob, Err >::get_errors ( Cont1 &  e,
Cont2 &  p 
) [inline]

Fetch errors and corresponding problems.

Parameters:
e Container where errors are appended
p Container where problems are appended
Returns:
Number of error problems

template<class Solv, class Prob, class Err>
template<class Cont>
size_t Scheduler< Solv, Prob, Err >::get_solved_problems ( Cont &  c  )  [inline]

Fetch solved problems.

Parameters:
c Container object where pointers to solved problems are appended.

template<class Solv, class Prob, class Err>
bool Scheduler< Solv, Prob, Err >::is_error ( void   )  [inline]

Return true on errors.

template<class Solv, class Prob, class Err>
bool Scheduler< Solv, Prob, Err >::is_running ( void   )  [inline]

Return true if scheduler is running.

template<class Solv, class Prob, class Err>
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.


Friends And Related Function Documentation

template<class Solv, class Prob, class Err>
friend class Consumer [friend]


The documentation for this class was generated from the following file:
Generated on Thu Apr 21 13:39:22 2011 for IBSimu by  doxygen 1.4.7