Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sort.h
Go to the documentation of this file.
1 #ifndef SORT_H
2 #define SORT_H
3 
4 #if !defined(TYPES_H) || !defined(MEM_H)
5 #warning "sort.h" requires "types.h" and "mem.h"
6 /* types.h defines uint, ulong
7  mem.h defines buffer */
8 #endif
9 
10 /*------------------------------------------------------------------------------
11 
12  Sort
13 
14  O(n) stable sort with good performance for all n
15 
16  sortv (uint *out, const uint *A, uint n, uint stride, buffer *buf)
17  sortv_long(ulong *out, const ulong *A, uint n, uint stride, buffer *buf)
18 
19  sortp (buffer *buf, int perm_start, const uint *A, uint n, uint stride)
20  sortp_long(buffer *buf, int perm_start, const ulong *A, uint n, uint stride)
21 
22  A, n, stride : specifices the input (stride is in bytes!)
23  out : the sorted values on output
24 
25  For the value sort, (sortv*)
26  A and out may alias (A == out) exactly when stride == sizeof(T)
27 
28  For the permutation sort, (sortp*)
29  The permutation can be both input (when start_perm!=0) and output,
30  following the convention that it is always at the start of the buffer buf:
31  uint *perm = buf->ptr;
32  The permutation denotes the ordering
33  A[perm[0]], A[perm[1]], ..., A[perm[n-1]]
34  (assuming stride == sizeof(uint) or sizeof(ulong) as appropriate)
35  and is re-arranged stably to give a sorted ordering.
36  Specifying start_perm==0 is equivalent to specifying
37  perm[i] = i, i=0,...,n-1
38  for an initial permutation (but may be faster).
39  The buffer will be expanded as necessary to accomodate the permutation
40  and the required scratch space.
41 
42  Most code calls these routines indirectly via the higher-level routine
43  sarray_sort for sorting arrays of structs (see "sarray_sort.h").
44 
45  ----------------------------------------------------------------------------*/
46 
47 #define sortv_ui PREFIXED_NAME(sortv_ui)
48 #define sortv_ul PREFIXED_NAME(sortv_ul)
49 #define sortv_ull PREFIXED_NAME(sortv_ull)
50 #define sortp_ui PREFIXED_NAME(sortp_ui)
51 #define sortp_ul PREFIXED_NAME(sortp_ul)
52 #define sortp_ull PREFIXED_NAME(sortp_ull)
53 
54 #define sortv TYPE_LOCAL(sortv_ui,sortv_ul,sortv_ull)
55 #define sortp TYPE_LOCAL(sortp_ui,sortp_ul,sortp_ull)
56 #define sortv_long TYPE_GLOBAL(sortv_ui,sortv_ul,sortv_ull)
57 #define sortp_long TYPE_GLOBAL(sortp_ui,sortp_ul,sortp_ull)
58 
59 void sortv_ui(unsigned *out, const unsigned *A, uint n, unsigned stride,
60  buffer *restrict buf);
61 void sortv_ul(unsigned long *out,
62  const unsigned long *A, uint n, unsigned stride,
63  buffer *restrict buf);
64 uint *sortp_ui(buffer *restrict buf, int start_perm,
65  const unsigned *restrict A, uint n, unsigned stride);
66 uint *sortp_ul(buffer *restrict buf, int start_perm,
67  const unsigned long *restrict A, uint n, unsigned stride);
68 #if defined(USE_LONG_LONG) || defined(GLOBAL_LONG_LONG)
69 void sortv_ull(unsigned long long *out,
70  const unsigned long long *A, uint n, unsigned stride,
71  buffer *restrict buf);
72 uint *sortp_ull(buffer *restrict buf, int start_perm,
73  const unsigned long long *restrict A, uint n, unsigned stride);
74 #endif
75 
76 #endif
#define uint
Definition: types.h:70
#define sortp_ul
Definition: sort.h:51
#define sortp_ui
Definition: sort.h:50
#define sortv_ul
Definition: sort.h:48
n
Definition: xxt_test.m:73
ulong A[NUM][SI]
Definition: sort_test.c:17
Definition: mem.h:111
#define restrict
Definition: c99.h:11
#define sortv_ui
Definition: sort.h:47
#define sortv_ull
Definition: sort.h:49
ulong out[N]
Definition: sort_test2.c:20
#define sortp_ull
Definition: sort.h:52