| 56 | |
| 57 | template <typename Iter, typename Comp> |
| 58 | void Sort(Context const *ctx, Iter begin, Iter end, Comp comp) { |
| 59 | if (ctx->Threads() > 1) { |
| 60 | #if defined(GCC_HAS_PARALLEL) |
| 61 | __gnu_parallel::sort(begin, end, comp, __gnu_parallel::default_parallel_tag(ctx->Threads())); |
| 62 | #elif defined(MSVC_HAS_PARALLEL) |
| 63 | auto n = std::distance(begin, end); |
| 64 | // use chunk size as hint to number of threads. No local policy/scheduler input with the |
| 65 | // concurrency module. |
| 66 | std::size_t chunk_size = n / ctx->Threads(); |
| 67 | // 2048 is the default of msvc ppl as of v2022. |
| 68 | chunk_size = std::max(chunk_size, static_cast<std::size_t>(2048)); |
| 69 | concurrency::parallel_sort(begin, end, comp, chunk_size); |
| 70 | #else |
| 71 | std::sort(begin, end, comp); |
| 72 | #endif // GLIBC VERSION |
| 73 | } else { |
| 74 | std::sort(begin, end, comp); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | template <typename Idx, typename Iter, typename V = typename std::iterator_traits<Iter>::value_type, |
| 79 | typename Comp = std::less<V>> |