Tpetra parallel linear algebra
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
Tpetra_Details_Hash.hpp
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
#ifndef TPETRA_DETAILS_HASH_HPP
11
#define TPETRA_DETAILS_HASH_HPP
12
13
#include "Tpetra_ConfigDefs.hpp"
14
#ifdef TPETRA_USE_MURMUR_HASH
15
#include <Kokkos_Functional.hpp>
// hash function used by Kokkos::UnorderedMap
16
#endif
// TPETRA_USE_MURMUR_HASH
17
#include <type_traits>
// make_signed
18
19
namespace
Tpetra
{
20
namespace
Details
{
21
22
namespace
Impl {
23
25
int
getRecommendedSizeInt(
const
int
size);
26
27
}
// namespace Impl
28
37
template
<
class
KeyType,
38
class
DeviceType,
39
class
OffsetType =
typename
std::make_signed<typename Kokkos::View<KeyType*, DeviceType>::size_type>::type,
40
class
ResultType =
int
>
41
struct
Hash
{
45
typedef
KeyType
argument_type
;
46
50
typedef
ResultType
result_type
;
51
53
typedef
OffsetType
offset_type
;
54
61
static
KOKKOS_INLINE_FUNCTION
result_type
62
hashFunc
(
const
argument_type
&
/*key*/
,
const
offset_type
&
/*size*/
) {
63
static_assert
(!std::is_same<result_type, int>::value,
64
"Not yet implemented for ResultType != int"
);
65
}
66
78
static
result_type
getRecommendedSize
(
const
offset_type
/*size*/
) {
79
static_assert
(!std::is_same<result_type, int>::value,
80
"Not yet implemented for ResultType != int"
);
81
}
82
};
83
97
template
<
class
KeyType,
class
DeviceType,
class
OffsetType>
98
struct
Hash
<KeyType, DeviceType, OffsetType, int> {
102
typedef
KeyType
argument_type
;
103
107
typedef
int
result_type
;
108
110
typedef
OffsetType
offset_type
;
111
118
static
KOKKOS_INLINE_FUNCTION
result_type
119
hashFunc
(
const
argument_type
& key,
const
offset_type
& size) {
120
#ifdef TPETRA_USE_MURMUR_HASH
121
Kokkos::pod_hash<argument_type> hash;
122
const
uint32_t k = hash(key);
123
return
static_cast<
result_type
>
(k % size);
124
#else
125
// We are using Epetra's hash function by default, as we have
126
// observed that it is much faster than the Murmur hash
127
// function. However, this is not a good hash function for general
128
// sets of keys. For our typical use case, this is good. Use
129
// Murmur hash if the maps are sparse.
130
const
unsigned
int
seed = (2654435761U);
131
const
int
intkey = (int)((key & 0x000000007fffffffLL) +
132
((key & 0x7fffffff80000000LL) >> 31));
133
return
static_cast<
result_type
>
((seed ^ intkey) %
static_cast<
int
>
(size));
134
#endif
135
}
136
143
static
result_type
getRecommendedSize
(
const
offset_type
size) {
144
return
Impl::getRecommendedSizeInt(
static_cast<
int
>
(size));
145
}
146
};
147
148
}
// namespace Details
149
}
// namespace Tpetra
150
151
#endif
// TPETRA_DETAILS_HASH_HPP
Tpetra::Details
Nonmember function that computes a residual Computes R = B - A * X.
Definition
Tpetra_KokkosRefactor_Details_MultiVectorLocalDeepCopy.hpp:17
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Tpetra::Details::Hash< KeyType, DeviceType, OffsetType, int >::offset_type
OffsetType offset_type
Type of offsets into the hash table's array of (key,value) pairs.
Definition
Tpetra_Details_Hash.hpp:110
Tpetra::Details::Hash< KeyType, DeviceType, OffsetType, int >::hashFunc
static KOKKOS_INLINE_FUNCTION result_type hashFunc(const argument_type &key, const offset_type &size)
The hash function.
Definition
Tpetra_Details_Hash.hpp:119
Tpetra::Details::Hash< KeyType, DeviceType, OffsetType, int >::getRecommendedSize
static result_type getRecommendedSize(const offset_type size)
Number of "buckets" that the constructor of FixedHashTable should allocate.
Definition
Tpetra_Details_Hash.hpp:143
Tpetra::Details::Hash< KeyType, DeviceType, OffsetType, int >::result_type
int result_type
Type of the return value of the hash function.
Definition
Tpetra_Details_Hash.hpp:107
Tpetra::Details::Hash< KeyType, DeviceType, OffsetType, int >::argument_type
KeyType argument_type
Type of the hash function's input.
Definition
Tpetra_Details_Hash.hpp:102
Tpetra::Details::Hash
The hash function for FixedHashTable.
Definition
Tpetra_Details_Hash.hpp:41
Tpetra::Details::Hash< KeyType, device_type >::result_type
int result_type
Definition
Tpetra_Details_Hash.hpp:50
Tpetra::Details::Hash< KeyType, device_type >::argument_type
KeyType argument_type
Definition
Tpetra_Details_Hash.hpp:45
Tpetra::Details::Hash::hashFunc
static KOKKOS_INLINE_FUNCTION result_type hashFunc(const argument_type &, const offset_type &)
The hash function.
Definition
Tpetra_Details_Hash.hpp:62
Tpetra::Details::Hash< KeyType, device_type >::offset_type
typename std::make_signed< typename Kokkos::View< KeyType *, device_type >::size_type >::type offset_type
Definition
Tpetra_Details_Hash.hpp:53
Tpetra::Details::Hash::getRecommendedSize
static result_type getRecommendedSize(const offset_type)
Number of "buckets" that the constructor of FixedHashTable should allocate.
Definition
Tpetra_Details_Hash.hpp:78
Generated by
1.17.0