Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef __Tpetra_DirectoryImpl_decl_hpp
43 #define __Tpetra_DirectoryImpl_decl_hpp
44 
47 
48 #include <Tpetra_ConfigDefs.hpp>
49 #include "Tpetra_TieBreak.hpp"
50 #include "Tpetra_Map_fwd.hpp"
51 
52 //
53 // mfh 13-15 May 2013: HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX governs
54 // the fix for Bug 5822. The fix is enabled by default. To disable
55 // the fix, uncomment out the three lines below that undefine
56 // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX, and comment out the three
57 // lines below them that define that macro.
58 //
59 // mfh 23 Mar 2014: I want Bug 5822 to stay fixed, so I am removing
60 // all references to HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX. I hope no
61 // downstream code is using that macro, but just in case, I will leave
62 // it defined.
63 
64 #ifndef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
65 # define HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 1
66 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
67 
68 #include <Tpetra_Details_FixedHashTable_decl.hpp>
69 
70 #ifndef DOXYGEN_SHOULD_SKIP_THIS
71 // Forward declaration of Teuchos::Comm
72 namespace Teuchos {
73  template<class OrdinalType>
74  class Comm;
75 } // namespace Teuchos
76 #endif // DOXYGEN_SHOULD_SKIP_THIS
77 
78 namespace Tpetra {
79  namespace Details {
87  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
88  class Directory : public Teuchos::Describable {
89  public:
90  typedef LocalOrdinal local_ordinal_type;
91  typedef GlobalOrdinal global_ordinal_type;
92  typedef NodeType node_type;
93  typedef ::Tpetra::Map<LocalOrdinal, GlobalOrdinal, NodeType> map_type;
94 
102  Directory ();
103 
137  getEntries (const map_type& map,
138  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
139  const Teuchos::ArrayView<int> &nodeIDs,
140  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
141  const bool computeLIDs) const;
142 
149  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const = 0;
150 
151  protected:
153  virtual LookupStatus
154  getEntriesImpl (const map_type& map,
155  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
156  const Teuchos::ArrayView<int> &nodeIDs,
157  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
158  const bool computeLIDs) const = 0;
159  };
160 
163  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
165  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
166  public:
168  typedef typename base_type::map_type map_type;
169 
171  ReplicatedDirectory (const map_type& map);
172 
175 
176  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
177 
178 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
179  template <class Node2>
181  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
182  {
184  return new Dir2 (cloneMap);
185  }
186 #endif
187 
189 
190 
192  std::string description () const;
194  protected:
197  getEntriesImpl (const map_type& map,
198  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
199  const Teuchos::ArrayView<int> &nodeIDs,
200  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
201  const bool computeLIDs) const;
202 
203  private:
205  const int numProcs_;
206  };
207 
208 
217  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
219  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
220  private:
221  // This friend declaration lets us implement clone().
222  template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
223 
226 
227  public:
229  typedef typename base_type::map_type map_type;
230 
233 
234  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
235  return true;
236  }
237 
238 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
239  template <class Node2>
241  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
242  {
244  return new Dir2 (cloneMap);
245  }
246 #endif
247 
249 
250 
252  std::string description () const;
254 
255  protected:
258  getEntriesImpl (const map_type& map,
259  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
260  const Teuchos::ArrayView<int> &nodeIDs,
261  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
262  const bool computeLIDs) const;
263  };
264 
265 
268  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
270  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
271  private:
272  template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
273 
276 
277  public:
279  typedef typename base_type::map_type map_type;
280 
283 
284  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
285  return true;
286  }
287 
288 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
289  template <class Node2>
291  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
292  {
294  Dir2* dir = new Dir2 (cloneMap);
295  try {
296  dir->allMinGIDs_ = allMinGIDs_;
297  } catch (std::exception& e) {
298  delete dir; // clean up just in case assignment throws (it shouldn't)
299  throw;
300  }
301  return dir;
302  }
303 #endif
304 
306 
307 
309  std::string description () const;
311 
312  protected:
315  getEntriesImpl (const map_type& map,
316  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
317  const Teuchos::ArrayView<int> &nodeIDs,
318  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
319  const bool computeLIDs) const;
320 
321  private:
345  Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
346  };
347 
350  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
352  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
353  private:
354  template <class LO, class GO, class N> friend class DistributedNoncontiguousDirectory;
357 
358  public:
361  typedef typename base_type::map_type map_type;
362 
365 
368  const tie_break_type& tie_break);
369 
370  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
371 
372 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
373  template <class Node2>
375  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
376  {
377  using Teuchos::RCP;
379  typedef ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2> output_map_type;
380  Dir2* dir = new Dir2 (cloneMap);
381 
382  // This method returns a raw pointer. Thus, take care to
383  // check whether intermediate operations succeed, so that we
384  // don't leak memory if they don't.
385  RCP<const output_map_type> outDirMap;
386  try {
387  outDirMap = directoryMap_->template clone<Node2> (cloneMap.getNode ());
388  }
389  catch (...) {
390  outDirMap = Teuchos::null; // deallocate
391  throw;
392  }
393 
394  dir->directoryMap_ = outDirMap;
395  dir->PIDs_ = PIDs_;
396  dir->LIDs_ = LIDs_;
397  dir->lidToPidTable_ = lidToPidTable_;
398  dir->lidToLidTable_ = lidToLidTable_;
399  dir->useHashTables_ = useHashTables_;
400  return dir;
401  }
402 #endif
403 
405 
406 
408  std::string description () const;
410  protected:
413  getEntriesImpl (const map_type& map,
414  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
415  const Teuchos::ArrayView<int> &nodeIDs,
416  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
417  const bool computeLIDs) const;
418  private:
425  void
426  initialize (const map_type& map,
427  Teuchos::Ptr<const tie_break_type> tie_break);
428 
441  bool isLocallyOneToOne () const {
442  return locallyOneToOne_;
443  }
444 
462  Teuchos::RCP<const map_type> directoryMap_;
463 
465 
466 
472  Teuchos::ArrayRCP<int> PIDs_;
473 
479  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
480 
482 
484 
490  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int,
491  Kokkos::Device<typename NodeType::execution_space,
492  typename NodeType::memory_space> > > lidToPidTable_;
493 
499  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal,
500  Kokkos::Device<typename NodeType::execution_space,
501  typename NodeType::memory_space> > > lidToLidTable_;
503 
510  mutable enum EOneToOneResult {
511  ONE_TO_ONE_NOT_CALLED_YET,
512  ONE_TO_ONE_FALSE,
513  ONE_TO_ONE_TRUE
514  } oneToOneResult_;
515 
519  bool locallyOneToOne_;
520 
528  bool useHashTables_;
529  };
530  } // namespace Details
531 } // namespace Tpetra
532 
533 #endif // __Tpetra_DirectoryImpl_decl_hpp
Interface for breaking ties in ownership.
Implementation of Directory for a locally replicated Map.
Interface for breaking ties in ownership.
std::string description() const
A one-line human-readable description of this object.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
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
Find process IDs and (optionally) local IDs for the given global IDs.
Implementation of Directory for a distributed noncontiguous Map.
Implementation of Directory for a distributed contiguous Map.
virtual bool isOneToOne(const Teuchos::Comm< int > &comm) const
Whether the Directory&#39;s input Map is (globally) one to one.
ReplicatedDirectory()
Constructor (that takes no arguments).
virtual bool isOneToOne(const Teuchos::Comm< int > &comm) const
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
Find process IDs and (optionally) local IDs for the given global IDs.
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 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
Find process IDs and (optionally) local IDs for the given global IDs.
std::string description() const
A one-line human-readable description of this object.
std::string description() const
A one-line human-readable description of this object.
A parallel distribution of indices over processes.
Computes the local ID and process ID corresponding to given global IDs.
std::string description() const
A one-line human-readable description of this object.
virtual bool isOneToOne(const Teuchos::Comm< int > &comm) const =0
Whether the Directory&#39;s input Map is (globally) one to one.
virtual bool isOneToOne(const Teuchos::Comm< int > &) const
Whether the Directory&#39;s input Map is (globally) one to one.
Implementation of Directory for a contiguous, uniformly distributed 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
Find process IDs and (optionally) local IDs for the given global IDs.
Forward declaration of Tpetra::Map.
virtual bool isOneToOne(const Teuchos::Comm< int > &) const
Whether the Directory&#39;s input Map is (globally) one to one.