All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sort.h
Go to the documentation of this file.
1//
2// Copyright 2024 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_WORK_SORT_H
8#define PXR_BASE_WORK_SORT_H
9
11
12#include "pxr/pxr.h"
14
15#include <tbb/parallel_sort.h>
16#include <algorithm>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
22template <typename C>
23void
24WorkParallelSort(C* container)
25{
26 // Don't bother with parallel_for, if concurrency is limited to 1.
27 if (WorkHasConcurrency()) {
28 tbb::parallel_sort(container->begin(), container->end());
29 }else{
30 std::sort(container->begin(), container->end());
31 }
32}
33
34
38template <typename C, typename Compare>
39void
40WorkParallelSort(C* container, const Compare& comp)
41{
42 // Don't bother with parallel_for, if concurrency is limited to 1.
43 if (WorkHasConcurrency()) {
44 tbb::parallel_sort(container->begin(), container->end(), comp);
45 }else{
46 std::sort(container->begin(), container->end(), comp);
47 }
48}
49
50PXR_NAMESPACE_CLOSE_SCOPE
51
52#endif
void WorkParallelSort(C *container)
Sorts in-place a container that provides begin() and end() methods.
Definition: sort.h:24
WORK_API bool WorkHasConcurrency()
Return true if WorkGetPhysicalConcurrencyLimit() returns a number greater than 1 and PXR_WORK_THREAD_...