sample_sort.qbk 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. [/===========================================================================
  2. Copyright (c) 2017 Steven Ross, Francisco Tapia, Orson Peters
  3. Distributed under the Boost Software License, Version 1.0
  4. See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt
  6. =============================================================================/]
  7. [section:sample_sort 3.2.- Sample_Sort]
  8. [:
  9. This is a implementation of the [*[@https://en.wikipedia.org/wiki/Samplesort Samplesort]] algorithm by Francisco Tapia for the Boost Library.
  10. It is a highly efficient [*parallel stable sort], optimized for use with many threads.
  11. The additional memory needed is of the same size than the data
  12. ]
  13. [section:sample_description Description]
  14. [:
  15. [*[teletype]
  16. ``
  17. | | | |
  18. Algorithm |Stable | Additional memory |Best, average, and worst case |
  19. ----------------------+-------+------------------------+------------------------------+
  20. sample_sort | yes | N | N, N LogN , N LogN |
  21. | | | |
  22. ``
  23. ]
  24. You can see their performance in the [*[link sort.parallel.linux_parallel Benchmarks]] chapter
  25. ]
  26. [endsect]
  27. [section:sample_programming Programming]
  28. [:
  29. [h4[_Thread Specification]]
  30. [:
  31. This algorithm has an integer parameter indicating the *number of threads* to use in the sorting process,
  32. which always is the last value in the call. The default value (if left unspecified) is the number of HW threads of
  33. the machine where the program is running provided by std::thread::hardware_concurrency().
  34. If the number is 1 or 0, the algorithm runs with only 1 thread.
  35. The number of threads is not a fixed number, but is calculated in each execution. The number of threads passed can be greater
  36. than the number of hardware threads on the machine. We can pass 100 threads in a machine with 4 HW threads,
  37. and in the same mode we can pass a function as (std::thread::hardware_concurrency() / 4 ).
  38. If this value is 0, the program is executed with 1 thread.
  39. ]
  40. [h4[_Programming]]
  41. [:
  42. You only need to include the file boost/sort/sort.hpp.
  43. The algorithm run in the namespace boost::sort
  44. [c++]
  45. ``
  46. #include <boost/sort/sort.hpp>
  47. template <class iter_t>
  48. void sample_sort (iter_t first, iter_t last);
  49. template <class iter_t, typename compare>
  50. void sample_sort (iter_t first, iter_t last, compare comp);
  51. template <class iter_t>
  52. void sample_sort (iter_t first, iter_t last, uint32_t num_thread);
  53. template <class iter_t, typename compare>
  54. void sample_sort (iter_t first, iter_t last, compare comp, uint32_t num_thread);
  55. ``
  56. This algorithm needs a *C++11 compliant compiler*, and doesn't need any other code or library. Correct operation is not guaranteed with older compilers.
  57. If the number of threads is unspecified, this uses the result of std::thread::hardware_concurrency().
  58. This algorithm uses a *comparison object*, in the same way as the standard library sort
  59. algorithms. If not defined, the comparison object is std::less, which uses
  60. the < operator internally.
  61. This algorithm is [*exception safe], meaning that, the exceptions generated by the algorithm
  62. guarantee the integrity of the objects to sort, but not their relative order. If the exception
  63. is generated inside the objects (in the move or in the copy constructor.. ) the results can be
  64. unpredictable.
  65. ]
  66. ]
  67. [endsect]
  68. [endsect]