39 namespace Gecode {
namespace Support {
42 template<
class RetType>
46 virtual RetType
run(
int i) = 0;
52 template<
class RetType>
61 RetType result(
void)
const;
64 template<
class Jobs,
class RetType>
96 virtual void run(
void);
122 void report(RetType
r);
124 void stop(RetType
r,
int i);
126 bool done(
void)
const;
128 Master(Jobs& j,
unsigned int m);
130 bool run(RetType&
r);
132 bool stopped(
void)
const;
134 int stoppedjob(RetType&
r)
const;
136 bool needthread(
void);
149 virtual void run(
void);
155 RunJobs(Jobs& j,
unsigned int m);
157 bool run(RetType&
r);
159 bool stopped(
int&
i, RetType&
r)
const;
166 template<
class RetType>
170 template<
class RetType>
178 template<
class Jobs,
class RetType>
183 :
Runnable(true), job(j), master(m), idx(i) {}
185 template<
class Jobs,
class RetType>
189 template<
class Jobs,
class RetType>
196 template<
class Jobs,
class RetType>
202 template<
class Jobs,
class RetType>
208 j = jobs.job(); i=
idx++;
218 template<
class Jobs,
class RetType>
227 template<
class Jobs,
class RetType>
239 template<
class Jobs,
class RetType>
251 }
while (
job != NULL);
254 template<
class Jobs,
class RetType>
257 return (n_threads == 0) && (!jobs() ||
stopped()) && rs.empty();
260 template<
class Jobs,
class RetType>
263 : n_threads(0), jobs(j),
idx(0), sidx(-1), rs(
heap) {
274 template<
class Jobs,
class RetType>
305 template<
class Jobs,
class RetType>
318 template<
class Jobs,
class RetType>
327 template<
class Jobs,
class RetType>
332 template<
class Jobs,
class RetType>
342 template<
class Jobs,
class RetType>
349 template<
class Jobs,
class RetType>
354 template<
class Jobs,
class RetType>
360 template<
class Jobs,
class RetType>
virtual void run(void)
Run jobs.
JobStop(RetType r0)
Constructor.
Job< RetType > * job
The job to run.
RetType r
The result stored.
An interface for objects that can be run by a thread.
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Job< RetType > * next(int &i)
Get next job witth index i, if possible.
static void run(Runnable *r)
Construct a new thread and run r.
void acquire(void)
Acquire the mutex and possibly block.
bool stopped(void) const
Whether a job has thrown a JobStop exception.
int idx
Index of next job to be created.
Event e
Event is triggered if a the first job is added to queue.
Master * master
The master to be deleted.
virtual RetType run(int i)=0
Run a job with iterator index i.
A mutex for mutual exclausion among several threads.
RunJobs(Jobs &j, unsigned int m)
Initialize with job iterator j and maximal number of threads m.
Baseclass for jobs with return type RetType.
void release(void)
Release the mutex.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
An event for synchronization.
bool run(RetType &r)
Run next job and return true if succesful and assign r to its result.
Parallel iterator that runs jobs with a given number of threads.
bool stopped(int &i, RetType &r) const
Whether a job has thrown a JobStop exception with index i and result r.
Master(Jobs &j, unsigned int m)
Initialize with job iterator j and maximal number of threads m.
Master * master
The master to communicate with.
int stoppedjob(RetType &r) const
Return index of first job that has thrown a JobStop exception (-1 if none) with its result...
bool run(RetType &r)
Run next job and return true if succesful and assign r to its result.
void report(RetType r)
Report result r by a worker.
~RunJobs(void)
Destructor.
Master * master
The actual master.
int sidx
Index of the first stop that has been stopped (-1 if none)
int idx
Original iterator index of job.
Class to throw an exception to stop new jobs from being started.
virtual ~Job(void)
Destructor.
Post propagator for SetVar SetOpType SetVar SetRelType r
DynamicQueue< RetType, Heap > rs
Queue of not yet requested results.
Queue with arbitrary number of elements.
The actual worker using a thread to run a job.
virtual ~Worker(void)
Nothing to delete (done in run)
bool done(void) const
Test whether all jobs are done.
Heap heap
The single global heap.
virtual void run(void)
Perform deletion.
unsigned int n_threads
Number of threads currently not in use.
Mutex m
Mutex for synchronizing access.
A class to delete the master (running in parallel)
void stop(RetType r, int i)
Report that a job with index i has been stopped.
Gecode toplevel namespace
Deleter(Master *m)
Initialize with master m.
bool needthread(void)
Whether a new thread is needed for deletion.
RetType result(void) const
Return the passed result.
#define GECODE_NEVER
Assert that this command is never executed.
Worker(Job< RetType > *j, Master *m, int i)
Initialize worker.
void wait(void)
Wait until the event becomes signalled.
RetType sres
Result from a the first stopped job (passed in exception)