Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_DirectoryImpl_decl.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 // ************************************************************************
38 // @HEADER
39 
40 #ifndef __Tpetra_DirectoryImpl_decl_hpp
41 #define __Tpetra_DirectoryImpl_decl_hpp
42 
45 
46 #include "Tpetra_TieBreak.hpp"
47 #include "Tpetra_Map_fwd.hpp"
48 
49 //
50 // mfh 13-15 May 2013: HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX governs
51 // the fix for Bug 5822. The fix is enabled by default. To disable
52 // the fix, uncomment out the three lines below that undefine
53 // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX, and comment out the three
54 // lines below them that define that macro.
55 //
56 // mfh 23 Mar 2014: I want Bug 5822 to stay fixed, so I am removing
57 // all references to HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX. I hope no
58 // downstream code is using that macro, but just in case, I will leave
59 // it defined.
60 
61 #ifndef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
62 # define HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 1
63 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
64 
65 #include "Tpetra_Details_FixedHashTable_decl.hpp"
66 
67 #ifndef DOXYGEN_SHOULD_SKIP_THIS
68 // Forward declaration of Teuchos::Comm
69 namespace Teuchos {
70  template<class OrdinalType>
71  class Comm;
72 } // namespace Teuchos
73 #endif // DOXYGEN_SHOULD_SKIP_THIS
74 
75 namespace Tpetra {
76  namespace Details {
84  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
85  class Directory : public Teuchos::Describable {
86  public:
87  typedef LocalOrdinal local_ordinal_type;
88  typedef GlobalOrdinal global_ordinal_type;
89  typedef NodeType node_type;
90  typedef ::Tpetra::Map<LocalOrdinal, GlobalOrdinal, NodeType> map_type;
91 
99  Directory () = default;
100 
101  virtual ~Directory () = default;
102 
136  getEntries (const map_type& map,
137  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
138  const Teuchos::ArrayView<int> &nodeIDs,
139  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
140  const bool computeLIDs) const;
141 
148  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const = 0;
149 
150  protected:
152  virtual LookupStatus
153  getEntriesImpl (const map_type& map,
154  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
155  const Teuchos::ArrayView<int> &nodeIDs,
156  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
157  const bool computeLIDs) const = 0;
158  };
159 
162  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
164  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
165  public:
167  typedef typename base_type::map_type map_type;
168 
170  ReplicatedDirectory () = default;
171 
173  ReplicatedDirectory (const map_type& map);
174 
175  ~ReplicatedDirectory () override = default;
176 
177  bool isOneToOne (const Teuchos::Comm<int>& comm) const override;
178 
180 
181 
183  std::string description () const override;
185  protected:
188  getEntriesImpl (const map_type& map,
189  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
190  const Teuchos::ArrayView<int> &nodeIDs,
191  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
192  const bool computeLIDs) const override;
193 
194  private:
196  const int numProcs_ = 0;
197  };
198 
199 
208  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
210  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
211  private:
212  // This friend declaration lets us implement clone().
213  template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
214 
215  public:
217  typedef typename base_type::map_type map_type;
218 
219  ContiguousUniformDirectory () = default;
221  ~ContiguousUniformDirectory () override = default;
222 
223  bool isOneToOne (const Teuchos::Comm<int>&) const override {
224  return true;
225  }
226 
228 
229 
231  std::string description () const override;
233 
234  protected:
237  getEntriesImpl (const map_type& map,
238  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
239  const Teuchos::ArrayView<int> &nodeIDs,
240  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
241  const bool computeLIDs) const override;
242  };
243 
244 
247  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
249  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
250  private:
251  template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
252 
253  public:
255  typedef typename base_type::map_type map_type;
256 
257  DistributedContiguousDirectory () = default;
259  ~DistributedContiguousDirectory () override = default;
260 
261  bool isOneToOne (const Teuchos::Comm<int>&) const override {
262  return true;
263  }
264 
266 
267 
269  std::string description () const override;
271 
272  protected:
275  getEntriesImpl (const map_type& map,
276  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
277  const Teuchos::ArrayView<int> &nodeIDs,
278  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
279  const bool computeLIDs) const override;
280 
281  private:
307  Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
308  };
309 
312  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
314  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
315  private:
316  template <class LO, class GO, class N>
318 
319  public:
322  using map_type = typename base_type::map_type;
323 
325  DistributedNoncontiguousDirectory (const map_type& map);
326  DistributedNoncontiguousDirectory (const map_type& map,
327  const tie_break_type& tie_break);
328  ~DistributedNoncontiguousDirectory () override = default;
329 
330  bool isOneToOne (const Teuchos::Comm<int>& comm) const override;
331 
333 
334 
336  std::string description () const override;
338  protected:
341  getEntriesImpl (const map_type& map,
342  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
343  const Teuchos::ArrayView<int> &nodeIDs,
344  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
345  const bool computeLIDs) const override;
346  private:
353  void
354  initialize (const map_type& map,
355  Teuchos::Ptr<const tie_break_type> tie_break);
356 
369  bool isLocallyOneToOne () const {
370  return locallyOneToOne_;
371  }
372 
390  Teuchos::RCP<const map_type> directoryMap_;
391 
393 
394 
400  Teuchos::ArrayRCP<int> PIDs_;
401 
407  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
408 
410 
412 
418  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int,
419  Kokkos::Device<typename NodeType::execution_space,
420  typename NodeType::memory_space> > > lidToPidTable_;
421 
427  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal,
428  Kokkos::Device<typename NodeType::execution_space,
429  typename NodeType::memory_space> > > lidToLidTable_;
431 
438  mutable enum EOneToOneResult {
439  ONE_TO_ONE_NOT_CALLED_YET,
440  ONE_TO_ONE_FALSE,
441  ONE_TO_ONE_TRUE
442  } oneToOneResult_;
443 
447  bool locallyOneToOne_;
448 
456  bool useHashTables_;
457  };
458  } // namespace Details
459 } // namespace Tpetra
460 
461 #endif // __Tpetra_DirectoryImpl_decl_hpp
Interface for breaking ties in ownership.
Implementation of Directory for a locally replicated Map.
std::string description() const override
A one-line human-readable description of this object.
Interface for breaking ties in ownership.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
std::string description() const override
A one-line human-readable description of this object.
Implementation of Directory for a distributed noncontiguous Map.
bool isOneToOne(const Teuchos::Comm< int > &) const override
Whether the Directory&#39;s input Map is (globally) one to one.
Directory()=default
Constructor.
bool isOneToOne(const Teuchos::Comm< int > &comm) const override
Whether the Directory&#39;s input Map is (globally) one to one.
Implementation of Directory for a distributed contiguous Map.
LookupStatus getEntriesImpl(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs, const Teuchos::ArrayView< LocalOrdinal > &localIDs, const bool computeLIDs) const override
Find process IDs and (optionally) local IDs for the given global IDs.
bool isOneToOne(const Teuchos::Comm< int > &comm) const override
Whether the Directory&#39;s input Map is (globally) one to one.
virtual LookupStatus getEntriesImpl(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs, const Teuchos::ArrayView< LocalOrdinal > &localIDs, const bool computeLIDs) const =0
Actually do the work of getEntries(), with no input validation.
LookupStatus getEntriesImpl(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs, const Teuchos::ArrayView< LocalOrdinal > &localIDs, const bool computeLIDs) const override
Find process IDs and (optionally) local IDs for the given global IDs.
LookupStatus getEntries(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs, const Teuchos::ArrayView< LocalOrdinal > &localIDs, const bool computeLIDs) const
LookupStatus getEntriesImpl(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs, const Teuchos::ArrayView< LocalOrdinal > &localIDs, const bool computeLIDs) const override
Find process IDs and (optionally) local IDs for the given global IDs.
std::string description() const override
A one-line human-readable description of this object.
A parallel distribution of indices over processes.
ReplicatedDirectory()=default
Constructor (that takes no arguments).
Computes the local ID and process ID corresponding to given global IDs.
virtual bool isOneToOne(const Teuchos::Comm< int > &comm) const =0
Whether the Directory&#39;s input Map is (globally) one to one.
bool isOneToOne(const Teuchos::Comm< int > &) const override
Whether the Directory&#39;s input Map is (globally) one to one.
LookupStatus getEntriesImpl(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs, const Teuchos::ArrayView< LocalOrdinal > &localIDs, const bool computeLIDs) const override
Find process IDs and (optionally) local IDs for the given global IDs.
Implementation of Directory for a contiguous, uniformly distributed Map.
std::string description() const override
A one-line human-readable description of this object.
Forward declaration of Tpetra::Map.