TPIE

v1.1rc1-6-g0c97303
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 54 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 249 of file parallel_sort.h.

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

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

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