Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_Hash.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Tpetra_Details_Hash.hpp"
11 
12 namespace Tpetra {
13 namespace Details {
14 namespace Impl {
15 
16 int getRecommendedSizeInt (const int size)
17 {
18  // A large list of prime numbers.
19  // Based on a recommendation by Andres Valloud in hash forums.
20  // There are only enough primes here so that between any number N and 2*N,
21  // there will be at least about 8 to choose from (except the first 10).
22  // This is a balance between a small list of primes, and getting a
23  // collection size that doesn't waste too much space. In addition,
24  // the primes in this table were chosen so that they do not divide
25  // 256^k +- a, for 1<=k<=8, and -32<=a<=32. This is so that
26  // using them as a modulo will not have a tendency to just throw away
27  // the most significant bits of the object's hash. The primes (except the
28  // first ten) or not close to any power of two to avoid aliasing
29  // between hash functions based on bit manipulation and the moduli.
30  int primes [ ] = {
31  3, 7, 13, 23, 53, 97, 193, 389, 769, 1543,
32  2237, 2423, 2617, 2797, 2999, 3167, 3359, 3539,
33  3727, 3911, 4441 , 4787 , 5119 , 5471 , 5801 , 6143 , 6521 , 6827
34  , 7177 , 7517 , 7853 , 8887 , 9587 , 10243 , 10937 , 11617 , 12289
35  , 12967 , 13649 , 14341 , 15013 , 15727
36  , 17749 , 19121 , 20479 , 21859 , 23209 , 24593 , 25939 , 27329
37  , 28669 , 30047 , 31469 , 35507 , 38231 , 40961 , 43711 , 46439
38  , 49157 , 51893 , 54617 , 57347 , 60077 , 62801 , 70583 , 75619
39  , 80669 , 85703 , 90749 , 95783 , 100823 , 105871 , 110909 , 115963
40  , 120997 , 126031 , 141157 , 151237 , 161323 , 171401 , 181499 , 191579
41  , 201653 , 211741 , 221813 , 231893 , 241979 , 252079
42  , 282311 , 302483 , 322649 , 342803 , 362969 , 383143 , 403301 , 423457
43  , 443629 , 463787 , 483953 , 504121 , 564617 , 604949 , 645313 , 685609
44  , 725939 , 766273 , 806609 , 846931 , 887261 , 927587 , 967919 , 1008239
45  , 1123477 , 1198397 , 1273289 , 1348177 , 1423067 , 1497983 , 1572869
46  , 1647761 , 1722667 , 1797581 , 1872461 , 1947359 , 2022253
47  , 2246953 , 2396759 , 2546543 , 2696363 , 2846161 , 2995973 , 3145739
48  , 3295541 , 3445357 , 3595117 , 3744941 , 3894707 , 4044503
49  , 4493921 , 4793501 , 5093089 , 5392679 , 5692279 , 5991883 , 6291469
50  , 6591059 , 6890641 , 7190243 , 7489829 , 7789447 , 8089033
51  , 8987807 , 9586981 , 10186177 , 10785371 , 11384539 , 11983729
52  , 12582917 , 13182109 , 13781291 , 14380469 , 14979667 , 15578861
53  , 16178053 , 17895707 , 19014187 , 20132683 , 21251141 , 22369661
54  , 23488103 , 24606583 , 25725083 , 26843549 , 27962027 , 29080529
55  , 30198989 , 31317469 , 32435981 , 35791397 , 38028379 , 40265327
56  , 42502283 , 44739259 , 46976221 , 49213237 , 51450131 , 53687099
57  , 55924061 , 58161041 , 60397993 , 62634959 , 64871921
58  , 71582857 , 76056727 , 80530643 , 85004567 , 89478503 , 93952427
59  , 98426347 , 102900263 , 107374217 , 111848111 , 116322053 , 120795971
60  , 125269877 , 129743807 , 143165587 , 152113427 , 161061283 , 170009141
61  , 178956983 , 187904819 , 196852693 , 205800547 , 214748383 , 223696237
62  , 232644089 , 241591943 , 250539763 , 259487603 , 268435399 };
63 
64  int hsize = primes[220] ;
65  for (int i = 0; i < 221; ++i) {
66  if (size <= primes[i]) {
67  hsize = primes[i];
68  break;
69  }
70  }
71  return hsize;
72 }
73 
74 } // namespace Impl
75 } // namespace Details
76 } // namespace Tpetra