TTK
Loading...
Searching...
No Matches
OrderDisambiguation.h
Go to the documentation of this file.
1#pragma once
2
3#include <BaseClass.h>
4
5#include <algorithm>
6#include <vector>
7
8namespace ttk {
9
19 template <typename scalarType, typename idType>
20 void sortVertices(const size_t nVerts,
21 const scalarType *const scalars,
22 const idType *const offsets,
23 SimplexId *const order,
24 const int nThreads) {
25
26 // array of pre-sorted vertices
27 std::vector<SimplexId> sortedVertices(nVerts);
28
29 TTK_FORCE_USE(nThreads);
30
31#ifdef TTK_ENABLE_OPENMP
32#pragma omp parallel for num_threads(nThreads)
33#endif // TTK_ENABLE_OPENMP
34 for(size_t i = 0; i < sortedVertices.size(); ++i) {
35 sortedVertices[i] = i;
36 }
37
38 if(offsets != nullptr) {
40 nThreads, sortedVertices.begin(), sortedVertices.end(),
41 [&](const SimplexId a, const SimplexId b) {
42 return (scalars[a] < scalars[b])
43 || (scalars[a] == scalars[b] && offsets[a] < offsets[b]);
44 });
45 } else {
46 TTK_PSORT(nThreads, sortedVertices.begin(), sortedVertices.end(),
47 [&](const SimplexId a, const SimplexId b) {
48 return (scalars[a] < scalars[b])
49 || (scalars[a] == scalars[b] && a < b);
50 });
51 }
52
53#ifdef TTK_ENABLE_OPENMP
54#pragma omp parallel for num_threads(nThreads)
55#endif // TTK_ENABLE_OPENMP
56 for(size_t i = 0; i < sortedVertices.size(); ++i) {
57 order[sortedVertices[i]] = i;
58 }
59 }
60
69 template <typename scalarType>
70 inline void preconditionOrderArray(const size_t nVerts,
71 const scalarType *const scalars,
72 SimplexId *const order,
73 const int nThreads
76 nVerts, scalars, static_cast<int *>(nullptr), order, nThreads);
77 }
78} // namespace ttk
#define TTK_FORCE_USE(x)
Force the compiler to use the function/method parameter.
Definition BaseClass.h:57
#define TTK_PSORT(NTHREADS,...)
Parallel sort macro.
Definition OpenMP.h:46
long long int idType
The Topology ToolKit.
COMMON_EXPORTS int globalThreadNumber_
Definition BaseClass.cpp:6
void sortVertices(const size_t nVerts, const scalarType *const scalars, const idType *const offsets, SimplexId *const order, const int nThreads)
Sort vertices according to scalars disambiguated by offsets.
void preconditionOrderArray(const size_t nVerts, const scalarType *const scalars, SimplexId *const order, const int nThreads=ttk::globalThreadNumber_)
Precondition an order array to be consumed by the base layer API.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22