10 #ifndef TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP
11 #define TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP
13 #include "Tpetra_Details_Hash.hpp"
18 #include "Teuchos_Describable.hpp"
19 #include "Teuchos_FancyOStream.hpp"
20 #include "Teuchos_VerbosityLevel.hpp"
22 #include "Kokkos_Core.hpp"
23 #if KOKKOS_VERSION >= 40799
24 #include "KokkosKernels_ArithTraits.hpp"
26 #include "Kokkos_ArithTraits.hpp"
57 template <
class KeyType,
62 typedef typename DeviceType::execution_space execution_space;
63 typedef typename DeviceType::memory_space memory_space;
64 typedef Kokkos::Device<execution_space, memory_space> device_type;
76 typedef typename Kokkos::View<
const offset_type*, Kokkos::LayoutLeft,
85 typedef typename Kokkos::View<const Kokkos::pair<KeyType, ValueType>*,
86 Kokkos::LayoutLeft, device_type>
95 KOKKOS_INLINE_FUNCTION
bool hasContiguousValues()
const {
96 return contiguousValues_;
103 typedef Kokkos::View<const KeyType*, Kokkos::LayoutLeft, device_type>
keys_type;
142 const ValueType startingValue);
156 const ValueType startingValue);
177 const KeyType firstContigKey,
178 const KeyType lastContigKey,
179 const ValueType startingValue);
197 const KeyType firstContigKey,
198 const KeyType lastContigKey,
199 const ValueType startingValue);
210 const Teuchos::ArrayView<const ValueType>& vals);
212 template <
class K,
class V,
class D>
220 template <
class InDeviceType>
222 typename std::enable_if<!std::is_same<DeviceType, InDeviceType>::value,
int>::type* = NULL) {
223 using Kokkos::ViewAllocateWithoutInitializing;
224 typedef typename ptr_type::non_const_type nonconst_ptr_type;
225 typedef typename val_type::non_const_type nonconst_val_type;
237 nonconst_ptr_type ptr(ViewAllocateWithoutInitializing(
"Tpetra::FixedHashTable::ptr"),
240 nonconst_val_type val(ViewAllocateWithoutInitializing(
"Tpetra::FixedHashTable::val"),
249 this->minKey_ = src.minKey_;
250 this->maxKey_ = src.maxKey_;
251 this->minVal_ = src.minVal_;
252 this->maxVal_ = src.maxVal_;
253 this->firstContigKey_ = src.firstContigKey_;
254 this->lastContigKey_ = src.lastContigKey_;
255 this->contiguousValues_ = src.contiguousValues_;
256 this->checkedForDuplicateKeys_ = src.checkedForDuplicateKeys_;
257 this->hasDuplicateKeys_ = src.hasDuplicateKeys_;
261 KOKKOS_INLINE_FUNCTION ValueType
get(
const KeyType& key)
const {
262 const offset_type size = this->getSize();
266 return Tpetra::Details::OrdinalTraits<ValueType>::invalid();
271 if (this->hasContiguousValues() &&
272 key >= firstContigKey_ && key <= lastContigKey_) {
273 return static_cast<ValueType
>(key - firstContigKey_) + this->
minVal();
279 const offset_type
start = ptr_[hashVal];
280 const offset_type end = ptr_[hashVal + 1];
281 for (offset_type k = start; k < end; ++k) {
282 if (val_[k].first == key) {
283 return val_[k].second;
289 return Tpetra::Details::OrdinalTraits<ValueType>::invalid();
295 KOKKOS_INLINE_FUNCTION offset_type
numPairs()
const {
301 if (this->hasContiguousValues()) {
302 return val_.extent(0) +
static_cast<offset_type
>(lastContigKey_ - firstContigKey_);
304 return val_.extent(0);
316 KOKKOS_INLINE_FUNCTION KeyType
minKey()
const {
328 KOKKOS_INLINE_FUNCTION KeyType
maxKey()
const {
339 KOKKOS_INLINE_FUNCTION ValueType
minVal()
const {
350 KOKKOS_INLINE_FUNCTION ValueType
maxVal()
const {
379 describe(Teuchos::FancyOStream& out,
380 const Teuchos::EVerbosityLevel verbLevel =
381 Teuchos::Describable::verbLevel_default)
const;
395 #if KOKKOS_VERSION >= 40799
396 KeyType minKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
398 KeyType minKey_ = ::Kokkos::ArithTraits<KeyType>::max();
406 #if KOKKOS_VERSION >= 40799
407 KeyType maxKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
409 KeyType maxKey_ = ::Kokkos::ArithTraits<KeyType>::max();
416 #if KOKKOS_VERSION >= 40799
417 ValueType minVal_ = ::KokkosKernels::ArithTraits<ValueType>::max();
419 ValueType minVal_ = ::Kokkos::ArithTraits<ValueType>::max();
426 #if KOKKOS_VERSION >= 40799
427 ValueType maxVal_ = ::KokkosKernels::ArithTraits<ValueType>::is_integer ? ::KokkosKernels::ArithTraits<ValueType>::min() : -::KokkosKernels::ArithTraits<ValueType>::max();
429 ValueType maxVal_ = ::Kokkos::ArithTraits<ValueType>::is_integer ? ::Kokkos::ArithTraits<ValueType>::min() : -::Kokkos::ArithTraits<ValueType>::max();
438 #if KOKKOS_VERSION >= 40799
439 KeyType firstContigKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
441 KeyType firstContigKey_ = ::Kokkos::ArithTraits<KeyType>::max();
450 #if KOKKOS_VERSION >= 40799
451 KeyType lastContigKey_ = ::KokkosKernels::ArithTraits<KeyType>::max();
453 KeyType lastContigKey_ = ::Kokkos::ArithTraits<KeyType>::max();
462 bool contiguousValues_ =
true;
470 bool checkedForDuplicateKeys_ =
true;
475 bool hasDuplicateKeys_ =
false;
481 bool checkForDuplicateKeys()
const;
484 KOKKOS_INLINE_FUNCTION offset_type getSize()
const {
485 return ptr_.extent(0) == 0 ?
static_cast<offset_type
>(0) : static_cast<offset_type>(ptr_.extent(0) - 1);
488 typedef Kokkos::View<
const KeyType*,
489 typename ptr_type::host_mirror_type::array_layout,
490 typename ptr_type::host_mirror_type::execution_space,
491 Kokkos::MemoryUnmanaged>
492 host_input_keys_type;
494 typedef Kokkos::View<
const ValueType*,
495 typename ptr_type::host_mirror_type::array_layout,
496 typename ptr_type::host_mirror_type::execution_space,
497 Kokkos::MemoryUnmanaged>
498 host_input_vals_type;
508 const ValueType startingValue,
511 KeyType firstContigKey,
512 KeyType lastContigKey,
513 const bool computeInitContigKeys);
522 init(
const host_input_keys_type& keys,
523 const host_input_vals_type& vals,
531 #endif // TPETRA_DETAILS_FIXEDHASHTABLE_DECL_HPP
void copyOffsets(const OutputViewType &dst, const InputViewType &src)
Copy row offsets (in a sparse graph or matrix) from src to dst. The offsets may have different types...
Import KokkosSparse::OrdinalTraits, a traits class for "invalid" (flag) values of integer types...
KOKKOS_DEFAULTED_FUNCTION FixedHashTable()=default
Default constructor; makes an empty table.
static KOKKOS_INLINE_FUNCTION result_type hashFunc(const argument_type &, const offset_type &)
The hash function.
KOKKOS_INLINE_FUNCTION ValueType minVal() const
The minimum value in the table.
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity to the output stream.
ResultType result_type
Type of the return value of the hash function.
Declare and define Tpetra::Details::copyOffsets, an implementation detail of Tpetra (in particular...
KOKKOS_INLINE_FUNCTION KeyType minKey() const
The minimum key in the table.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
The hash function for FixedHashTable.
std::string description() const
Implementation of Teuchos::Describable interface.
KOKKOS_INLINE_FUNCTION offset_type numPairs() const
Number of (key, value) pairs in the table.
FixedHashTable(const FixedHashTable< KeyType, ValueType, InDeviceType > &src, typename std::enable_if<!std::is_same< DeviceType, InDeviceType >::value, int >::type *=NULL)
"Copy" constructor that takes a FixedHashTable with the same KeyType and ValueType, but a different DeviceType.
void start()
Start the deep_copy counter.
KOKKOS_INLINE_FUNCTION KeyType maxKey() const
The maximum key in the table.
OffsetType offset_type
Type of offsets into the hash table's array of (key,value) pairs.
bool hasDuplicateKeys()
Whether the table has any duplicate keys.
KOKKOS_INLINE_FUNCTION ValueType maxVal() const
The maximum value in the table.
Kokkos::View< const KeyType *, Kokkos::LayoutLeft, device_type > keys_type
Type of a 1-D Kokkos::View (array) used to store keys.