MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
peano.c
Go to the documentation of this file.
1 #include <mpi.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <math.h>
6 
7 #include <gsl/gsl_heapsort.h>
8 #include "peano.h"
9 
10 /* The following rewrite of the original function
11  * peano_hilbert_key_old() has been written by MARTIN REINECKE.
12  * It is about a factor 2.3 - 2.5 faster than Volker's old routine!
13  */
14 const unsigned char rottable3[48][8] = {
15  {36, 28, 25, 27, 10, 10, 25, 27},
16  {29, 11, 24, 24, 37, 11, 26, 26},
17  {8, 8, 25, 27, 30, 38, 25, 27},
18  {9, 39, 24, 24, 9, 31, 26, 26},
19  {40, 24, 44, 32, 40, 6, 44, 6},
20  {25, 7, 33, 7, 41, 41, 45, 45},
21  {4, 42, 4, 46, 26, 42, 34, 46},
22  {43, 43, 47, 47, 5, 27, 5, 35},
23  {33, 35, 36, 28, 33, 35, 2, 2},
24  {32, 32, 29, 3, 34, 34, 37, 3},
25  {33, 35, 0, 0, 33, 35, 30, 38},
26  {32, 32, 1, 39, 34, 34, 1, 31},
27  {24, 42, 32, 46, 14, 42, 14, 46},
28  {43, 43, 47, 47, 25, 15, 33, 15},
29  {40, 12, 44, 12, 40, 26, 44, 34},
30  {13, 27, 13, 35, 41, 41, 45, 45},
31  {28, 41, 28, 22, 38, 43, 38, 22},
32  {42, 40, 23, 23, 29, 39, 29, 39},
33  {41, 36, 20, 36, 43, 30, 20, 30},
34  {37, 31, 37, 31, 42, 40, 21, 21},
35  {28, 18, 28, 45, 38, 18, 38, 47},
36  {19, 19, 46, 44, 29, 39, 29, 39},
37  {16, 36, 45, 36, 16, 30, 47, 30},
38  {37, 31, 37, 31, 17, 17, 46, 44},
39  {12, 4, 1, 3, 34, 34, 1, 3},
40  {5, 35, 0, 0, 13, 35, 2, 2},
41  {32, 32, 1, 3, 6, 14, 1, 3},
42  {33, 15, 0, 0, 33, 7, 2, 2},
43  {16, 0, 20, 8, 16, 30, 20, 30},
44  {1, 31, 9, 31, 17, 17, 21, 21},
45  {28, 18, 28, 22, 2, 18, 10, 22},
46  {19, 19, 23, 23, 29, 3, 29, 11},
47  {9, 11, 12, 4, 9, 11, 26, 26},
48  {8, 8, 5, 27, 10, 10, 13, 27},
49  {9, 11, 24, 24, 9, 11, 6, 14},
50  {8, 8, 25, 15, 10, 10, 25, 7},
51  {0, 18, 8, 22, 38, 18, 38, 22},
52  {19, 19, 23, 23, 1, 39, 9, 39},
53  {16, 36, 20, 36, 16, 2, 20, 10},
54  {37, 3, 37, 11, 17, 17, 21, 21},
55  {4, 17, 4, 46, 14, 19, 14, 46},
56  {18, 16, 47, 47, 5, 15, 5, 15},
57  {17, 12, 44, 12, 19, 6, 44, 6},
58  {13, 7, 13, 7, 18, 16, 45, 45},
59  {4, 42, 4, 21, 14, 42, 14, 23},
60  {43, 43, 22, 20, 5, 15, 5, 15},
61  {40, 12, 21, 12, 40, 6, 23, 6},
62  {13, 7, 13, 7, 41, 41, 22, 20}
63 };
64 
65 const unsigned char subpix3[48][8] = {
66  {0, 7, 1, 6, 3, 4, 2, 5},
67  {7, 4, 6, 5, 0, 3, 1, 2},
68  {4, 3, 5, 2, 7, 0, 6, 1},
69  {3, 0, 2, 1, 4, 7, 5, 6},
70  {1, 0, 6, 7, 2, 3, 5, 4},
71  {0, 3, 7, 4, 1, 2, 6, 5},
72  {3, 2, 4, 5, 0, 1, 7, 6},
73  {2, 1, 5, 6, 3, 0, 4, 7},
74  {6, 1, 7, 0, 5, 2, 4, 3},
75  {1, 2, 0, 3, 6, 5, 7, 4},
76  {2, 5, 3, 4, 1, 6, 0, 7},
77  {5, 6, 4, 7, 2, 1, 3, 0},
78  {7, 6, 0, 1, 4, 5, 3, 2},
79  {6, 5, 1, 2, 7, 4, 0, 3},
80  {5, 4, 2, 3, 6, 7, 1, 0},
81  {4, 7, 3, 0, 5, 6, 2, 1},
82  {6, 7, 5, 4, 1, 0, 2, 3},
83  {7, 0, 4, 3, 6, 1, 5, 2},
84  {0, 1, 3, 2, 7, 6, 4, 5},
85  {1, 6, 2, 5, 0, 7, 3, 4},
86  {2, 3, 1, 0, 5, 4, 6, 7},
87  {3, 4, 0, 7, 2, 5, 1, 6},
88  {4, 5, 7, 6, 3, 2, 0, 1},
89  {5, 2, 6, 1, 4, 3, 7, 0},
90  {7, 0, 6, 1, 4, 3, 5, 2},
91  {0, 3, 1, 2, 7, 4, 6, 5},
92  {3, 4, 2, 5, 0, 7, 1, 6},
93  {4, 7, 5, 6, 3, 0, 2, 1},
94  {6, 7, 1, 0, 5, 4, 2, 3},
95  {7, 4, 0, 3, 6, 5, 1, 2},
96  {4, 5, 3, 2, 7, 6, 0, 1},
97  {5, 6, 2, 1, 4, 7, 3, 0},
98  {1, 6, 0, 7, 2, 5, 3, 4},
99  {6, 5, 7, 4, 1, 2, 0, 3},
100  {5, 2, 4, 3, 6, 1, 7, 0},
101  {2, 1, 3, 0, 5, 6, 4, 7},
102  {0, 1, 7, 6, 3, 2, 4, 5},
103  {1, 2, 6, 5, 0, 3, 7, 4},
104  {2, 3, 5, 4, 1, 0, 6, 7},
105  {3, 0, 4, 7, 2, 1, 5, 6},
106  {1, 0, 2, 3, 6, 7, 5, 4},
107  {0, 7, 3, 4, 1, 6, 2, 5},
108  {7, 6, 4, 5, 0, 1, 3, 2},
109  {6, 1, 5, 2, 7, 0, 4, 3},
110  {5, 4, 6, 7, 2, 3, 1, 0},
111  {4, 3, 7, 0, 5, 2, 6, 1},
112  {3, 2, 0, 1, 4, 5, 7, 6},
113  {2, 5, 1, 6, 3, 4, 0, 7}
114 };
115 
119 peano_t peano_hilbert_key(int x, int y, int z, int bits)
120 {
121  int mask;
122  unsigned char rotation = 0;
123  peano_t key = 0;
124 
125  for(mask = 1 << (bits - 1); mask > 0; mask >>= 1)
126  {
127  unsigned char pix = ((x & mask) ? 4 : 0) | ((y & mask) ? 2 : 0) | ((z & mask) ? 1 : 0);
128 
129  key <<= 3;
130  key |= subpix3[rotation][pix];
131  rotation = rottable3[rotation][pix];
132  }
133 
134  return key;
135 }
136 
peano_t peano_hilbert_key(int x, int y, int z, int bits)
Definition: peano.c:119
const unsigned char subpix3[48][8]
Definition: peano.c:65
const unsigned char rottable3[48][8]
Definition: peano.c:14
uint64_t peano_t
Definition: peano.h:7