TPIE

v1.1rc1-6-g0c97303
tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::qsort_job Class Reference

Represents quick sort work at a given level. More...

#include <tpie/parallel_sort.h>

Inherits tpie::job.

Public Member Functions

 qsort_job (iterator_type a, iterator_type b, comp_type comp, qsort_job *parent, progress_t &p)
 Construct a qsort_job. More...
 
virtual void operator() ()
 Running a job with iterators a and b will repeatedly partition [a,b), spawn a job on the left part and recurse on the right part, until the min_size limit is reached. More...
 
void join ()
 Wait for this job and its subjobs to complete. More...
 
bool is_done ()
 Return true if this job and its subjobs are done. More...
 
void enqueue (job *parent=0)
 Add this job to the job pool. More...
 
void run ()
 Run this job. More...
 

Protected Member Functions

virtual void on_done () override
 Called when this job and all subjobs are done. More...
 

Detailed Description

template<typename iterator_type, typename comp_type, bool Progress, size_t min_size = 1024*1024*8/sizeof(typename boost::iterator_value<iterator_type>::type)>
class tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::qsort_job

Represents quick sort work at a given level.

Definition at line 172 of file parallel_sort.h.

Constructor & Destructor Documentation

template<typename iterator_type, typename comp_type, bool Progress, size_t min_size = 1024*1024*8/sizeof(typename boost::iterator_value<iterator_type>::type)>
tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::qsort_job::qsort_job ( iterator_type  a,
iterator_type  b,
comp_type  comp,
qsort_job parent,
progress_t &  p 
)
inline

Construct a qsort_job.

Definition at line 177 of file parallel_sort.h.

178  : a(a), b(b), comp(comp), parent(parent), progress(p) {
179 
180  // Does nothing.
181  }

Member Function Documentation

void tpie::job::enqueue ( job parent = 0)
inherited

Add this job to the job pool.

Parameters
parent(optional) The parent job, or 0 if this is a root job.

Referenced by tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::qsort_job::operator()(), and tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::operator()().

bool tpie::job::is_done ( )
inherited

Return true if this job and its subjobs are done.

void tpie::job::join ( )
inherited

Wait for this job and its subjobs to complete.

Referenced by tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::operator()().

template<typename iterator_type, typename comp_type, bool Progress, size_t min_size = 1024*1024*8/sizeof(typename boost::iterator_value<iterator_type>::type)>
virtual void tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::qsort_job::on_done ( )
inlineoverrideprotectedvirtual

Called when this job and all subjobs are done.

Reimplemented from tpie::job.

Definition at line 212 of file parallel_sort.h.

212  {
213  // Unfortunately, it might not be safe to delete our children at
214  // this point, as other threads might in theory wait for them to
215  // .join(). It is safer to postpone deletion until our own
216  // deletion.
217  if (!parent) {
218  boost::mutex::scoped_lock lock(progress.mutex);
219  progress.work_estimate = progress.total_work_estimate;
220  progress.cond.notify_one();
221  }
222  }
template<typename iterator_type, typename comp_type, bool Progress, size_t min_size = 1024*1024*8/sizeof(typename boost::iterator_value<iterator_type>::type)>
virtual void tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::qsort_job::operator() ( )
inlinevirtual

Running a job with iterators a and b will repeatedly partition [a,b), spawn a job on the left part and recurse on the right part, until the min_size limit is reached.

Implements tpie::job.

Definition at line 195 of file parallel_sort.h.

References tpie::job::enqueue(), and tpie::sort().

195  {
196  assert(a <= b);
197  assert(&*a != 0);
198  while (static_cast<size_t>(b - a) >= min_size) {
199  iterator_type pivot = partition(a, b, comp);
200  add_progress(b - a);
201  //qsort_job * j = tpie_new<qsort_job>(a, pivot, comp, this);
202  qsort_job * j = new qsort_job(a, pivot, comp, this, progress);
203  j->enqueue(this);
204  children.push_back(j);
205  a = pivot+1;
206  }
207  std::sort(a, b, comp);
208  add_progress(sortWork(b - a));
209  }
qsort_job(iterator_type a, iterator_type b, comp_type comp, qsort_job *parent, progress_t &p)
Construct a qsort_job.
void sort(file_stream< T > &instream, file_stream< T > &outstream, Compare comp, progress_indicator_base &indicator)
Sort elements of a stream using the given STL-style comparator object.
Definition: sort.h:59
void tpie::job::run ( )
inherited

Run this job.

Invoke operator() and call done().


The documentation for this class was generated from the following file: