Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sarray_sort.h
Go to the documentation of this file.
1 #ifndef SARRAY_SORT_H
2 #define SARRAY_SORT_H
3 
4 #if !defined(SORT_H)
5 #warning "sarray_sort.h" requires "sort.h"
6 #endif
7 
8 /*------------------------------------------------------------------------------
9 
10  Array of Structs Sort
11 
12  buffer *buf;
13  typedef struct { ... } T;
14  T A[n];
15 
16  sarray_sort(T,A,n, field_name,is_long, buf)
17  - sort A according to the struct field "field_name",
18  which is a ulong/uint field according as is_long is true/false
19 
20  sarray_sort_2(T,A,n, field1,is_long1, field2,is_long2, buf)
21  - sort A by field1 then field2
22 
23  sarray_permute(T,A,n, perm, work)
24  - permute A (in-place)
25  A[0] <- A[perm[0]], etc.
26  work needs to hold sizeof(T) bytes (i.e., 1 T)
27 
28  sarray_permute_buf(T,A,n, buf);
29  - permute A according to the permutation in buf
30  A[0] <- A[perm[0]], etc.
31  where uint *perm = buf->ptr (see "sort.h")
32 
33  ----------------------------------------------------------------------------*/
34 
35 
36 #define sarray_permute_ PREFIXED_NAME(sarray_permute_)
37 #define sarray_permute_buf_ PREFIXED_NAME(sarray_permute_buf_)
38 
39 void sarray_permute_(size_t size, void *A, size_t n, uint *perm, void *work);
41  size_t align, size_t size, void *A, size_t n, buffer *buf);
42 
43 #define sarray_permute(T,A,n, perm, work) \
44  sarray_permute_(sizeof(T),A,n, perm, work)
45 #define sarray_permute_buf(T,A,n, buf) \
46  sarray_permute_buf_(ALIGNOF(T),sizeof(T),A,n,buf)
47 
48 #define sarray_sort_field(T,A,n, field,is_long, buf,keep) do { \
49  if(is_long) \
50  sortp_long(buf,keep, (ulong*)((char*)(A)+offsetof(T,field)),n,sizeof(T)); \
51  else \
52  sortp (buf,keep, (uint *)((char*)(A)+offsetof(T,field)),n,sizeof(T)); \
53 } while (0)
54 
55 #define sarray_sort(T,A,n, field,is_long, buf) do { \
56  sarray_sort_field(T,A,n, field,is_long, buf,0); \
57  sarray_permute_buf(T,A,n, buf); \
58 } while (0)
59 
60 #define sarray_sort_2(T,A,n, field1,is_long1, field2,is_long2, buf) do { \
61  sarray_sort_field(T,A,n, field2,is_long2, buf,0); \
62  sarray_sort_field(T,A,n, field1,is_long1, buf,1); \
63  sarray_permute_buf(T,A,n, buf); \
64 } while (0)
65 
66 #define sarray_sort_3(T,A,n, field1,is_long1, field2,is_long2, \
67  field3,is_long3, buf) do { \
68  sarray_sort_field(T,A,n, field3,is_long3, buf,0); \
69  sarray_sort_field(T,A,n, field2,is_long2, buf,1); \
70  sarray_sort_field(T,A,n, field1,is_long1, buf,1); \
71  sarray_permute_buf(T,A,n, buf); \
72 } while (0)
73 
74 #define sarray_sort_4(T,A,n, field1,is_long1, field2,is_long2, \
75  field3,is_long3, field4,is_long4, buf) do { \
76  sarray_sort_field(T,A,n, field4,is_long4, buf,0); \
77  sarray_sort_field(T,A,n, field3,is_long3, buf,1); \
78  sarray_sort_field(T,A,n, field2,is_long2, buf,1); \
79  sarray_sort_field(T,A,n, field1,is_long1, buf,1); \
80  sarray_permute_buf(T,A,n, buf); \
81 } while (0)
82 
83 static void sarray_perm_invert(
84  uint *const pinv, const uint *const perm, const uint n)
85 {
86  uint i; for(i=0;i<n;++i) pinv[perm[i]] = i;
87 }
88 
89 #endif
#define sarray_permute_
Definition: sarray_sort.h:36
#define uint
Definition: types.h:70
#define sarray_permute_buf_
Definition: sarray_sort.h:37
n
Definition: xxt_test.m:73
ulong A[NUM][SI]
Definition: sort_test.c:17
static void sarray_perm_invert(uint *const pinv, const uint *const perm, const uint n)
Definition: sarray_sort.h:83
Definition: mem.h:111
for i
Definition: xxt_test.m:74
static double work[TNR *NS]