parallel.qbk 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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:parallel 3.- Parallel Algorithms]
  8. [:
  9. [h4[_Parallel Algorithms]]
  10. [:
  11. This table provides a brief description of the parallel algorithms of the library.
  12. [*[teletype]
  13. ``
  14. | | | |
  15. Algorithm |Stable | Additional memory |Best, average, and worst case |
  16. ----------------------+-------+------------------------+------------------------------+
  17. block_indirect_sort | no |block_size * num_threads| N, N LogN , N LogN |
  18. sample_sort | yes | N | N, N LogN , N LogN |
  19. parallel_stable_sort | yes | N / 2 | N, N LogN , N LogN |
  20. | | | |
  21. ``
  22. ]
  23. * *Sample_sort* is a implementation of the [*[@ https://en.wikipedia.org/wiki/Samplesort Samplesort algorithm]] done by Francisco Tapia.
  24. * *Parallel_stable_sort* is based on the samplesort algorithm, but using a half of the memory used by sample_sort, conceived and implemented by Francisco Tapia.
  25. * *Block_indirect_sort* is a novel parallel sort algorithm, very fast, with low additional memory consumption, conceived and implemented by Francisco Tapia.
  26. The *block_size* is an internal parameter of the algorithm, which in order to achieve the
  27. highest speed, changes according to the size of the objects to sort according to the next table. The strings use a block_size of 128.
  28. [*[teletype]
  29. ``
  30. | | | | | | | |
  31. object size (bytes) | 1 - 15 | 16 - 31 | 32 - 63 | 64 - 127|128 - 255|256 - 511| 512 - |
  32. --------------------------------+--------+---------+---------+---------+---------+---------+----------+
  33. block_size (number of elements) | 4096 | 2048 | 1024 | 768 | 512 | 256 | 128 |
  34. | | | | | | | |
  35. ``
  36. ]
  37. ]
  38. [h4[_Thread Specification]]
  39. [:
  40. The parallel algorithms have a integer parameter indicating the *number of threads* to use in the sorting process,
  41. which always is the last value in the call.
  42. The default value (if left unspecified) is the number of HW threads of
  43. the machine where the program is running provided by std::thread::hardware_concurrency().
  44. If the number is 1 or 0, the algorithm runs with only 1 thread.
  45. The number of threads is not a fixed number, but is calculated in each execution. The number of threads passed can be greater
  46. than the number of hardware threads on the machine. We can pass 100 threads in a machine with 4 HW threads, and in the same mode we can pass a function as (std::thread::hardware_concurrency() / 4 ). If this value is 0, the program is executed with 1 thread.
  47. ]
  48. [h4[_Programming]]
  49. [:
  50. You only need to include the file boost/sort/sort.hpp to use these algorithms.
  51. All the algorithms run in the namespace boost::sort
  52. [c++]
  53. ``
  54. #include <boost/sort/sort.hpp>
  55. ``
  56. The parallel algorithms have 4 invocation formats:
  57. [c++]
  58. ``
  59. algorithm ( first iterator, last iterator, comparison object, number of threads )
  60. algorithm ( first iterator, last iterator, comparison object )
  61. algorithm ( first iterator, last iterator, number of threads )
  62. algorithm ( first iterator, last iterator )
  63. ``
  64. These algorithms need a *C++11 compliant compiler*, but don't need any other code or library. With older compilers correct operation isn't guaranteed.
  65. If the number of threads is unspecified, use the result of std::thread::hardware_concurrency()
  66. These algorithms use a [*comparison object], in the same way as the standard library sort algorithms. If you don't define it,
  67. the comparison object defaults to std::less, which uses the < operator internally for comparisons.
  68. These algorithms are [*exception safe], meaning that, the exceptions generated by the algorithms guarantee the integrity
  69. of the objects to sort, but not their relative order. If the exception is generated inside the objects (in the move or copy constructors) the results are undefined.
  70. ]
  71. ]
  72. [include block_indirect_sort.qbk]
  73. [include sample_sort.qbk]
  74. [include parallel_stable_sort.qbk]
  75. [include linux_parallel.qbk]
  76. [include windows_parallel.qbk]
  77. [endsect]