Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sort_test.c
Go to the documentation of this file.
1 #include <stddef.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <limits.h>
5 #include <string.h>
6 #include "c99.h"
7 #include "name.h"
8 #include "fail.h"
9 #include "types.h"
10 #include "mem.h"
11 #include "sort.h"
12 
13 #define SMALL 22
14 #define NUM 500
15 #define SI 9
16 
18 uint B[NUM][SI], Bv[NUM];
19 
20 uint P[NUM], Q[NUM];
21 
22 int main()
23 {
24  buffer buf = {0,0,0};
25  uint i;
26 
27  /*buffer_init(&buf, sortp_long_worksize(NUM,0));*/
28 
29 #if 0
30  printf("\nsource:\n");
31 #endif
32  for(i=0;i!=NUM;++i) {
33  A[i][0]=rand();
34  A[i][0]<<=CHAR_BIT*sizeof(int)-1;
35  A[i][0]^=rand();
36  A[i][0]<<=CHAR_BIT*sizeof(int)-1;
37  A[i][0]^=rand();
38  if(0) A[i][0]&=0x000ff00;
39  B[i][0]=A[i][0];
40 #if 0
41  printf("%016lx\t%016lx\n",(unsigned long)A[i][0],(unsigned long)B[i][0]);
42 #endif
43  }
44 #if 0
45  printf("\n");
46 #endif
47  printf("merge sort:\n");
48  for(i=0;i!=SMALL;++i) Q[i]=SMALL-1-i;
49  sortv_long(Av, &A[0][0],SMALL,sizeof(ulong[SI]), &buf);
50  sortp_long(&buf,0, &A[0][0],SMALL,sizeof(ulong[SI]));
51  memcpy(P,buf.ptr,SMALL*sizeof(uint));
52  memcpy(buf.ptr,Q,SMALL*sizeof(uint));
53  sortp_long(&buf,1, &A[0][0],SMALL,sizeof(ulong[SI]));
54  memcpy(Q,buf.ptr,SMALL*sizeof(uint));
55  for(i=0;i!=SMALL;++i)
56  printf("%u\t%u\t%016lx\t%d\t%d\n",(unsigned)P[i],(unsigned)Q[i],
57  (unsigned long)A[P[i]][0],
58  A[P[i]][0]==A[Q[i]][0],
59  Av[i]==A[P[i]][0]);
60  printf("\n");
61  printf("radix sort:\n");
62  for(i=0;i!=NUM;++i) Q[i]=NUM-1-i;
63  sortv_long(Av, &A[0][0],NUM,sizeof(ulong[SI]), &buf);
64  sortp_long(&buf,0, &A[0][0],NUM,sizeof(ulong[SI]));
65  memcpy(P,buf.ptr,NUM*sizeof(uint));
66  memcpy(buf.ptr,Q,NUM*sizeof(uint));
67  sortp_long(&buf,1, &A[0][0],NUM,sizeof(ulong[SI]));
68  memcpy(Q,buf.ptr,NUM*sizeof(uint));
69  for(i=0;i!=NUM;++i)
70  printf("%u\t%u\t%016lx\t%d\t%d\n",(unsigned)P[i],(unsigned)Q[i],
71  (unsigned long)A[P[i]][0],
72  A[P[i]][0]==A[Q[i]][0],
73  Av[i]==A[P[i]][0]);
74 
75  printf("\nsmall integers:\n");
76  printf("\n");
77 
78  printf("heap sort:\n");
79  for(i=0;i!=SMALL;++i) Q[i]=SMALL-1-i;
80  sortv(Q, Q,SMALL,sizeof(uint), &buf);
81  for(i=0;i!=SMALL;++i) printf("\t%u\n",(unsigned)Q[i]);
82 
83  printf("merge sort:\n");
84  for(i=0;i!=SMALL;++i) Q[i]=SMALL-1-i;
85  sortv(Bv, &B[0][0],SMALL,sizeof(uint[SI]), &buf);
86  sortp(&buf,0, &B[0][0],SMALL,sizeof(uint[SI]));
87  memcpy(P,buf.ptr,SMALL*sizeof(uint));
88  memcpy(buf.ptr,Q,SMALL*sizeof(uint));
89  sortp(&buf,1, &B[0][0],SMALL,sizeof(uint[SI]));
90  memcpy(Q,buf.ptr,SMALL*sizeof(uint));
91  for(i=0;i!=SMALL;++i)
92  printf("%u\t%u\t%016lx\t%d\t%d\n",(unsigned)P[i],(unsigned)Q[i],
93  (unsigned long)B[P[i]][0],
94  B[P[i]][0]==B[Q[i]][0],
95  B[P[i]][0]==Bv[i]);
96  printf("\n");
97  printf("radix sort:\n");
98  for(i=0;i!=NUM;++i) Q[i]=NUM-1-i;
99  sortv(Bv, &B[0][0],NUM,sizeof(uint[SI]), &buf);
100  sortp(&buf,0, &B[0][0],NUM,sizeof(uint[SI]));
101  memcpy(P,buf.ptr,NUM*sizeof(uint));
102  memcpy(buf.ptr,Q,NUM*sizeof(uint));
103  sortp(&buf,1, &B[0][0],NUM,sizeof(uint[SI]));
104  memcpy(Q,buf.ptr,NUM*sizeof(uint));
105  for(i=0;i!=NUM;++i)
106  printf("%u\t%u\t%016lx\t%d\t%d\n",(unsigned)P[i],(unsigned)Q[i],
107  (unsigned long)B[P[i]][0],
108  B[P[i]][0]==B[Q[i]][0],
109  B[P[i]][0]==Bv[i]);
110  buffer_free(&buf);
111  return 0;
112 }
113 
#define uint
Definition: types.h:70
void sortv(T *out, const T *A, uint n, unsigned stride, buffer *restrict buf)
Definition: sort_imp.h:446
#define buffer_free(b)
Definition: mem.h:158
uint Q[NUM]
Definition: sort_test.c:20
ulong A[NUM][SI]
Definition: sort_test.c:17
uint B[NUM][SI]
Definition: sort_test.c:18
Definition: mem.h:111
#define ulong
Definition: types.h:75
ulong Av[NUM]
Definition: sort_test.c:17
#define sortp_long
Definition: sort.h:57
int main()
Definition: sort_test.c:22
uint * sortp(buffer *restrict buf, int start_perm, const T *restrict A, uint n, unsigned stride)
Definition: sort_imp.h:477
for i
Definition: xxt_test.m:74
void * ptr
Definition: mem.h:111
uint Bv[NUM]
Definition: sort_test.c:18
#define SI
Definition: sort_test.c:15
#define SMALL
Definition: sort_test.c:13
#define NUM
Definition: sort_test.c:14
establishes some macros to establish naming conventions
uint P[NUM]
Definition: sort_test.c:20
#define sortv_long
Definition: sort.h:56