TPIE

2362a60
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() () override
 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 211 of file parallel_sort.h.

211  {
212  // Unfortunately, it might not be safe to delete our children at
213  // this point, as other threads might in theory wait for them to
214  // .join(). It is safer to postpone deletion until our own
215  // deletion.
216  if (!parent) {
217  std::lock_guard<std::mutex> lock(progress.mutex);
218  progress.work_estimate = progress.total_work_estimate;
219  progress.cond.notify_one();
220  }
221  }
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() ( )
inlineoverridevirtual

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

Run this job.

Invoke operator() and call done().


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