Tpetra parallel linear algebra  Version of the Day
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  template <class Node2>
180  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
181  {
183  return new Dir2 (cloneMap);
184  }
185 
187 
188 
190  std::string description () const;
192  protected:
195  getEntriesImpl (const map_type& map,
196  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
197  const Teuchos::ArrayView<int> &nodeIDs,
198  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
199  const bool computeLIDs) const;
200 
201  private:
203  const int numProcs_;
204  };
205 
206 
215  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
217  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
218  private:
219  // This friend declaration lets us implement clone().
220  template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
221 
224 
225  public:
227  typedef typename base_type::map_type map_type;
228 
231 
232  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
233  return true;
234  }
235 
236  template <class Node2>
238  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
239  {
241  return new Dir2 (cloneMap);
242  }
243 
245 
246 
248  std::string description () const;
250 
251  protected:
254  getEntriesImpl (const map_type& map,
255  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
256  const Teuchos::ArrayView<int> &nodeIDs,
257  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
258  const bool computeLIDs) const;
259  };
260 
261 
264  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
266  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
267  private:
268  template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
269 
272 
273  public:
275  typedef typename base_type::map_type map_type;
276 
279 
280  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
281  return true;
282  }
283 
284  template <class Node2>
286  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
287  {
289  Dir2* dir = new Dir2 (cloneMap);
290  try {
291  dir->allMinGIDs_ = allMinGIDs_;
292  } catch (std::exception& e) {
293  delete dir; // clean up just in case assignment throws (it shouldn't)
294  throw;
295  }
296  return dir;
297  }
298 
300 
301 
303  std::string description () const;
305 
306  protected:
309  getEntriesImpl (const map_type& map,
310  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
311  const Teuchos::ArrayView<int> &nodeIDs,
312  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
313  const bool computeLIDs) const;
314 
315  private:
339  Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
340  };
341 
344  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
346  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
347  private:
348  template <class LO, class GO, class N> friend class DistributedNoncontiguousDirectory;
351 
352  public:
355  typedef typename base_type::map_type map_type;
356 
359 
362  const tie_break_type& tie_break);
363 
364  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
365 
366  template <class Node2>
368  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
369  {
370  using Teuchos::RCP;
372  typedef ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2> output_map_type;
373  Dir2* dir = new Dir2 (cloneMap);
374 
375  // This method returns a raw pointer. Thus, take care to
376  // check whether intermediate operations succeed, so that we
377  // don't leak memory if they don't.
378  RCP<const output_map_type> outDirMap;
379  try {
380  outDirMap = directoryMap_->template clone<Node2> (cloneMap.getNode ());
381  }
382  catch (...) {
383  outDirMap = Teuchos::null; // deallocate
384  throw;
385  }
386 
387  dir->directoryMap_ = outDirMap;
388  dir->PIDs_ = PIDs_;
389  dir->LIDs_ = LIDs_;
390  dir->lidToPidTable_ = lidToPidTable_;
391  dir->lidToLidTable_ = lidToLidTable_;
392  dir->useHashTables_ = useHashTables_;
393  return dir;
394  }
395 
397 
398 
400  std::string description () const;
402  protected:
405  getEntriesImpl (const map_type& map,
406  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
407  const Teuchos::ArrayView<int> &nodeIDs,
408  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
409  const bool computeLIDs) const;
410  private:
417  void
418  initialize (const map_type& map,
419  Teuchos::Ptr<const tie_break_type> tie_break);
420 
433  bool isLocallyOneToOne () const {
434  return locallyOneToOne_;
435  }
436 
454  Teuchos::RCP<const map_type> directoryMap_;
455 
457 
458 
464  Teuchos::ArrayRCP<int> PIDs_;
465 
471  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
472 
474 
476 
482  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int,
483  Kokkos::Device<typename NodeType::execution_space,
484  typename NodeType::memory_space> > > lidToPidTable_;
485 
491  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal,
492  Kokkos::Device<typename NodeType::execution_space,
493  typename NodeType::memory_space> > > lidToLidTable_;
495 
502  mutable enum EOneToOneResult {
503  ONE_TO_ONE_NOT_CALLED_YET,
504  ONE_TO_ONE_FALSE,
505  ONE_TO_ONE_TRUE
506  } oneToOneResult_;
507 
511  bool locallyOneToOne_;
512 
520  bool useHashTables_;
521  };
522  } // namespace Details
523 } // namespace Tpetra
524 
525 #endif // __Tpetra_DirectoryImpl_decl_hpp
Tpetra::Details::ContiguousUniformDirectory::isOneToOne
virtual bool isOneToOne(const Teuchos::Comm< int > &) const
Whether the Directory's input Map is (globally) one to one.
Definition: Tpetra_DirectoryImpl_decl.hpp:232
Tpetra::Details::ReplicatedDirectory::ReplicatedDirectory
ReplicatedDirectory()
Constructor (that takes no arguments).
Definition: Tpetra_DirectoryImpl_def.hpp:116
Tpetra::Details::DistributedContiguousDirectory::description
std::string description() const
A one-line human-readable description of this object.
Definition: Tpetra_DirectoryImpl_def.hpp:375
Tpetra_Map_fwd.hpp
Forward declaration of Tpetra::Map.
Tpetra::Details::DistributedContiguousDirectory::isOneToOne
virtual bool isOneToOne(const Teuchos::Comm< int > &) const
Whether the Directory's input Map is (globally) one to one.
Definition: Tpetra_DirectoryImpl_decl.hpp:280
Tpetra::Details::DistributedNoncontiguousDirectory::description
std::string description() const
A one-line human-readable description of this object.
Definition: Tpetra_DirectoryImpl_def.hpp:933
Tpetra::Details::ReplicatedDirectory::description
std::string description() const
A one-line human-readable description of this object.
Definition: Tpetra_DirectoryImpl_def.hpp:135
Tpetra::Details::DistributedContiguousDirectory
Implementation of Directory for a distributed contiguous Map.
Definition: Tpetra_DirectoryImpl_decl.hpp:265
Tpetra::Details::ContiguousUniformDirectory
Implementation of Directory for a contiguous, uniformly distributed Map.
Definition: Tpetra_DirectoryImpl_decl.hpp:216
Details
Implementation details of Tpetra.
Tpetra::Details::Directory::isOneToOne
virtual bool isOneToOne(const Teuchos::Comm< int > &comm) const =0
Whether the Directory's input Map is (globally) one to one.
Tpetra::Details::DistributedNoncontiguousDirectory
Implementation of Directory for a distributed noncontiguous Map.
Definition: Tpetra_DirectoryImpl_decl.hpp:345
Tpetra_TieBreak.hpp
Interface for breaking ties in ownership.
Tpetra::Details::ReplicatedDirectory
Implementation of Directory for a locally replicated Map.
Definition: Tpetra_DirectoryImpl_decl.hpp:164
Tpetra::Details::ContiguousUniformDirectory::getEntriesImpl
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.
Definition: Tpetra_DirectoryImpl_def.hpp:173
Tpetra::Details::ContiguousUniformDirectory::description
std::string description() const
A one-line human-readable description of this object.
Definition: Tpetra_DirectoryImpl_def.hpp:159
Tpetra::Details::FixedHashTable
Definition: Tpetra_Details_FixedHashTable_decl.hpp:86
Tpetra::Details::DistributedNoncontiguousDirectory::isOneToOne
virtual bool isOneToOne(const Teuchos::Comm< int > &comm) const
Whether the Directory's input Map is (globally) one to one.
Definition: Tpetra_DirectoryImpl_def.hpp:1175
Tpetra::Details::DistributedContiguousDirectory::getEntriesImpl
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.
Definition: Tpetra_DirectoryImpl_def.hpp:431
Tpetra::LookupStatus
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
Definition: Tpetra_ConfigDefs.hpp:124
Tpetra::Details::Directory::Directory
Directory()
Constructor.
Definition: Tpetra_DirectoryImpl_def.hpp:67
Tpetra::Details::Directory
Computes the local ID and process ID corresponding to given global IDs.
Definition: Tpetra_DirectoryImpl_decl.hpp:88
Tpetra::Details::Directory::getEntries
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
Definition: Tpetra_DirectoryImpl_def.hpp:72
Tpetra::Details::Classes::TieBreak
Interface for breaking ties in ownership.
Definition: Tpetra_TieBreak.hpp:69
Tpetra::Details::ReplicatedDirectory::isOneToOne
virtual bool isOneToOne(const Teuchos::Comm< int > &comm) const
Whether the Directory's input Map is (globally) one to one.
Definition: Tpetra_DirectoryImpl_def.hpp:124
Tpetra::Details::Directory::getEntriesImpl
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.
Tpetra::Classes::Map
A parallel distribution of indices over processes.
Definition: Tpetra_Map_decl.hpp:247
Tpetra::Details::DistributedNoncontiguousDirectory::getEntriesImpl
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.
Definition: Tpetra_DirectoryImpl_def.hpp:946
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Tpetra::Details::ReplicatedDirectory::getEntriesImpl
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.
Definition: Tpetra_DirectoryImpl_def.hpp:388