39 namespace Gecode {
namespace Support {
42 template<
class RetType>
46 virtual RetType
run(
int i) = 0;
50 template<
class RetType>
59 RetType
result(
void)
const;
62 template<
class Jobs,
class RetType>
94 virtual void run(
void);
122 void stop(RetType
r,
int i);
124 bool done(
void)
const;
126 Master(Jobs& j,
unsigned int m);
128 bool run(RetType&
r);
147 virtual void run(
void);
153 RunJobs(Jobs& j,
unsigned int m);
155 bool run(RetType&
r);
164 template<
class RetType>
168 template<
class RetType>
176 template<
class Jobs,
class RetType>
181 :
Runnable(true), job(j), master(m), idx(
i) {}
183 template<
class Jobs,
class RetType>
187 template<
class Jobs,
class RetType>
194 template<
class Jobs,
class RetType>
200 template<
class Jobs,
class RetType>
206 j = jobs.job();
i=idx++;
216 template<
class Jobs,
class RetType>
225 template<
class Jobs,
class RetType>
237 template<
class Jobs,
class RetType>
242 RetType
r = job->run(idx);
249 }
while (job != NULL);
252 template<
class Jobs,
class RetType>
255 return (n_threads == 0) && (!jobs() ||
stopped()) && rs.empty();
258 template<
class Jobs,
class RetType>
261 : n_threads(0), jobs(j), idx(0), sidx(-1), rs(
heap) {
272 template<
class Jobs,
class RetType>
303 template<
class Jobs,
class RetType>
316 template<
class Jobs,
class RetType>
325 template<
class Jobs,
class RetType>
330 template<
class Jobs,
class RetType>
340 template<
class Jobs,
class RetType>
347 template<
class Jobs,
class RetType>
352 template<
class Jobs,
class RetType>
355 return master->run(
r);
358 template<
class Jobs,
class RetType>
361 if (!master->needthread())
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.
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.
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.
RetType sres
Result from a the first stopped job (passed in exception)