TPIE

2362a60
tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size > Class Template Reference

A simple parallel sort implementation with progress tracking. More...

#include <tpie/parallel_sort.h>

Classes

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

Public Member Functions

 parallel_sort_impl (typename P::base *p)
 
void operator() (iterator_type a, iterator_type b, comp_type comp=std::less< value_type >())
 Perform a parallel sort of the items in the interval [a,b). 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 >

A simple parallel sort implementation with progress tracking.

The partition step is sequential, as a parallel partition only speeds up the top layer, which does not warrant the hassle of implementation. Uses the TPIE job manager to transparently distribute work across the machine cores. Uses the pseudo median of nine as pivot.

Definition at line 52 of file parallel_sort.h.

Member Function 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)>
void tpie::parallel_sort_impl< iterator_type, comp_type, Progress, min_size >::operator() ( iterator_type  a,
iterator_type  b,
comp_type  comp = std::less<value_type>() 
)
inline

Perform a parallel sort of the items in the interval [a,b).

Waits until all workers are done. The calling thread handles progress tracking, so a thread-safe progress tracker is not required.

Definition at line 248 of file parallel_sort.h.

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

248  {
249  progress.work_estimate = 0;
250  progress.total_work_estimate = sortWork(b-a);
251  if (progress.pi) progress.pi->init(progress.total_work_estimate);
252 
253  if (static_cast<size_t>(b - a) < min_size) {
254  std::sort(a, b, comp);
255  if (progress.pi) progress.pi->done();
256  return;
257  }
258 
259  qsort_job * master = new qsort_job(a, b, comp, 0, progress);
260  master->enqueue();
261 
262  std::uint64_t prev_work_estimate = 0;
263  std::unique_lock<std::mutex> lock(progress.mutex);
264  while (progress.work_estimate < progress.total_work_estimate) {
265  if (progress.pi && progress.work_estimate > prev_work_estimate) progress.pi->step(progress.work_estimate - prev_work_estimate);
266  prev_work_estimate = progress.work_estimate;
267  progress.cond.wait(lock);
268  }
269  lock.unlock();
270 
271  master->join();
272  delete master;
273  if (progress.pi) progress.pi->done();
274  }
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

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