Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Details_LocalMap.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Tpetra: Templated Linear Algebra Services Package
5// Copyright (2008) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ************************************************************************
40// @HEADER
41
42#ifndef TPETRA_DETAILS_LOCALMAP_HPP
43#define TPETRA_DETAILS_LOCALMAP_HPP
44
48
49#include "Tpetra_Details_FixedHashTable.hpp"
50// #include "Tpetra_Details_OrdinalTraits.hpp" // comes in above
51// #include "Kokkos_Core.hpp" // comes in above
53
54namespace Tpetra {
55namespace Details {
56
70template<class LocalOrdinal, class GlobalOrdinal, class DeviceType>
71class LocalMap {
72public:
75
78
80 using device_type = DeviceType;
81
83 using execution_space = typename device_type::execution_space;
84
86 using memory_space = typename device_type::memory_space;
87
89#ifdef KOKKOS_ENABLE_CUDA
90 using no_uvm_memory_space = typename std::conditional<std::is_same<memory_space, Kokkos::CudaUVMSpace>::value,
91 Kokkos::CudaSpace, memory_space>::type;
92 using no_uvm_device_type = Kokkos::Device<execution_space, no_uvm_memory_space>;
93#else
95#endif
96
99
100 LocalMap (const ::Tpetra::Details::FixedHashTable<GlobalOrdinal, LocalOrdinal, no_uvm_device_type>& glMap,
101 const ::Kokkos::View<const GlobalOrdinal*, ::Kokkos::LayoutLeft, no_uvm_device_type>& lgMap,
108 const bool contiguous) :
109 glMap_ (glMap),
110 lgMap_ (lgMap),
111 indexBase_ (indexBase),
112 myMinGid_ (myMinGid),
113 myMaxGid_ (myMaxGid),
114 firstContiguousGid_ (firstContiguousGid),
115 lastContiguousGid_ (lastContiguousGid),
116 numLocalElements_ (numLocalElements),
117 contiguous_ (contiguous)
118 {}
119
122 return numLocalElements_;
123 }
124
127 return indexBase_;
128 }
129
135 return contiguous_;
136 }
137
142
146 {
147 if (numLocalElements_ == 0) {
148 return ::Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
149 } else { // Local indices are always zero-based.
150 return static_cast<LocalOrdinal> (numLocalElements_ - 1);
151 }
152 }
153
156 return myMinGid_;
157 }
158
161 return myMaxGid_;
162 }
163
167 {
168 if (contiguous_) {
170 return ::Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
171 }
172 return static_cast<LocalOrdinal> (globalIndex - myMinGid_);
173 }
174 else if (globalIndex >= firstContiguousGid_ &&
175 globalIndex <= lastContiguousGid_) {
176 return static_cast<LocalOrdinal> (globalIndex - firstContiguousGid_);
177 }
178 else {
179 // If the given global index is not in the table, this returns
180 // the same value as OrdinalTraits<LocalOrdinal>::invalid().
181 return glMap_.get (globalIndex);
182 }
183 }
184
188 {
190 return ::Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ();
191 }
192 if (isContiguous ()) {
193 return getMinGlobalIndex () + localIndex;
194 }
195 else {
196 return lgMap_(localIndex);
197 }
198 }
199
200private:
217 ::Kokkos::View<const GlobalOrdinal*, ::Kokkos::LayoutLeft, no_uvm_device_type> lgMap_;
218
219 GlobalOrdinal indexBase_ = 0;
220 GlobalOrdinal myMinGid_ = Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
221 GlobalOrdinal myMaxGid_ = Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
222 GlobalOrdinal firstContiguousGid_ = Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
223 GlobalOrdinal lastContiguousGid_ = Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
224 LocalOrdinal numLocalElements_ = 0;
225 bool contiguous_ = false;
226};
227
228} // namespace Details
229} // namespace Tpetra
230
231#endif // TPETRA_DETAILS_LOCALMAP_HPP
232
Forward declaration of Tpetra::Details::LocalMap.
Struct that holds views of the contents of a CrsMatrix.
KOKKOS_INLINE_FUNCTION ValueType get(const KeyType &key) const
Get the value corresponding to the given key.
"Local" part of Map suitable for Kokkos kernels.
KOKKOS_INLINE_FUNCTION LocalOrdinal getLocalNumElements() const
The number of indices that live on the calling process.
KOKKOS_INLINE_FUNCTION LocalOrdinal getLocalElement(const GlobalOrdinal globalIndex) const
Get the local index corresponding to the given global index. (device only)
typename device_type::execution_space execution_space
The Kokkos execution space.
KOKKOS_INLINE_FUNCTION GlobalOrdinal getMaxGlobalIndex() const
The maximum global index on the calling process.
KOKKOS_INLINE_FUNCTION bool isContiguous() const
Whether the Map is (locally) contiguous.
KOKKOS_INLINE_FUNCTION LocalOrdinal getMinLocalIndex() const
The minimum local index.
KOKKOS_DEFAULTED_FUNCTION LocalMap()=default
Default constructor.
typename device_type::memory_space memory_space
The Kokkos memory space.
KOKKOS_INLINE_FUNCTION LocalOrdinal getMaxLocalIndex() const
The maximum local index.
KOKKOS_INLINE_FUNCTION GlobalOrdinal getIndexBase() const
The (global) index base.
KOKKOS_INLINE_FUNCTION GlobalOrdinal getGlobalElement(const LocalOrdinal localIndex) const
Get the global index corresponding to the given local index. (device only)
KOKKOS_INLINE_FUNCTION GlobalOrdinal getMinGlobalIndex() const
The minimum global index on the calling process.
device_type no_uvm_device_type
The hash will be CudaSpace, not CudaUVMSpace.
DeviceType device_type
The device type.
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.