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 
51 //
52 // mfh 13-15 May 2013: HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX governs
53 // the fix for Bug 5822. The fix is enabled by default. To disable
54 // the fix, uncomment out the three lines below that undefine
55 // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX, and comment out the three
56 // lines below them that define that macro.
57 //
58 // mfh 23 Mar 2014: I want Bug 5822 to stay fixed, so I am removing
59 // all references to HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX. I hope no
60 // downstream code is using that macro, but just in case, I will leave
61 // it defined.
62 
63 #ifndef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
64 # define HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 1
65 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
66 
67 #include <Tpetra_Details_FixedHashTable_decl.hpp>
68 
69 
70 namespace Tpetra {
71  // Forward declaration.
72  template <class LocalOrdinal, class GlobalOrdinal, class Node> class Map;
73 
74  namespace Details {
75  // Forward declaration.
76  template <class LocalOrdinal, class GlobalOrdinal> class TieBreak;
77 
85  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
86  class Directory : public Teuchos::Describable {
87  public:
88  typedef LocalOrdinal local_ordinal_type;
89  typedef GlobalOrdinal global_ordinal_type;
90  typedef NodeType node_type;
91  typedef ::Tpetra::Map<LocalOrdinal, GlobalOrdinal, NodeType> map_type;
92 
100  Directory ();
101 
135  getEntries (const map_type& map,
136  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
137  const Teuchos::ArrayView<int> &nodeIDs,
138  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
139  const bool computeLIDs) const;
140 
147  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const = 0;
148 
149  protected:
151  virtual LookupStatus
152  getEntriesImpl (const map_type& map,
153  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
154  const Teuchos::ArrayView<int> &nodeIDs,
155  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
156  const bool computeLIDs) const = 0;
157  };
158 
161  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
163  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
164  public:
166  typedef typename base_type::map_type map_type;
167 
169  ReplicatedDirectory (const map_type& map);
170 
173 
174  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
175 
176  template <class Node2>
178  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
179  {
181  return new Dir2 (cloneMap);
182  }
183 
185 
186 
188  std::string description () const;
190  protected:
193  getEntriesImpl (const map_type& map,
194  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
195  const Teuchos::ArrayView<int> &nodeIDs,
196  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
197  const bool computeLIDs) const;
198 
199  private:
201  const int numProcs_;
202  };
203 
204 
213  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
215  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
216  private:
217  // This friend declaration lets us implement clone().
218  template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
219 
222 
223  public:
225  typedef typename base_type::map_type map_type;
226 
229 
230  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
231  return true;
232  }
233 
234  template <class Node2>
236  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
237  {
239  return new Dir2 (cloneMap);
240  }
241 
243 
244 
246  std::string description () const;
248 
249  protected:
252  getEntriesImpl (const map_type& map,
253  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
254  const Teuchos::ArrayView<int> &nodeIDs,
255  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
256  const bool computeLIDs) const;
257  };
258 
259 
262  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
264  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
265  private:
266  template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
267 
270 
271  public:
273  typedef typename base_type::map_type map_type;
274 
277 
278  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
279  return true;
280  }
281 
282  template <class Node2>
284  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
285  {
287  Dir2* dir = new Dir2 (cloneMap);
288  try {
289  dir->allMinGIDs_ = allMinGIDs_;
290  } catch (std::exception& e) {
291  delete dir; // clean up just in case assignment throws (it shouldn't)
292  throw;
293  }
294  return dir;
295  }
296 
298 
299 
301  std::string description () const;
303 
304  protected:
307  getEntriesImpl (const map_type& map,
308  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
309  const Teuchos::ArrayView<int> &nodeIDs,
310  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
311  const bool computeLIDs) const;
312 
313  private:
337  Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
338  };
339 
342  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
344  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
345  private:
346  template <class LO, class GO, class N> friend class DistributedNoncontiguousDirectory;
349 
350  public:
353  typedef typename base_type::map_type map_type;
354 
357 
360  const tie_break_type& tie_break);
361 
362  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
363 
364  template <class Node2>
366  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
367  {
368  using Teuchos::RCP;
370  typedef ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2> output_map_type;
371  Dir2* dir = new Dir2 (cloneMap);
372 
373  // This method returns a raw pointer. Thus, take care to
374  // check whether intermediate operations succeed, so that we
375  // don't leak memory if they don't.
376  RCP<const output_map_type> outDirMap;
377  try {
378  outDirMap = directoryMap_->template clone<Node2> (cloneMap.getNode ());
379  }
380  catch (...) {
381  outDirMap = Teuchos::null; // deallocate
382  throw;
383  }
384 
385  dir->directoryMap_ = outDirMap;
386  dir->PIDs_ = PIDs_;
387  dir->LIDs_ = LIDs_;
388  dir->lidToPidTable_ = lidToPidTable_;
389  dir->lidToLidTable_ = lidToLidTable_;
390  dir->useHashTables_ = useHashTables_;
391  return dir;
392  }
393 
395 
396 
398  std::string description () const;
400  protected:
403  getEntriesImpl (const map_type& map,
404  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
405  const Teuchos::ArrayView<int> &nodeIDs,
406  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
407  const bool computeLIDs) const;
408  private:
415  void
416  initialize (const map_type& map,
417  Teuchos::Ptr<const tie_break_type> tie_break);
418 
431  bool isLocallyOneToOne () const {
432  return locallyOneToOne_;
433  }
434 
452  Teuchos::RCP<const map_type> directoryMap_;
453 
455 
456 
462  Teuchos::ArrayRCP<int> PIDs_;
463 
469  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
470 
472 
474 
480  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int,
481  Kokkos::Device<typename NodeType::execution_space,
482  typename NodeType::memory_space> > > lidToPidTable_;
483 
489  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal,
490  Kokkos::Device<typename NodeType::execution_space,
491  typename NodeType::memory_space> > > lidToLidTable_;
493 
500  mutable enum EOneToOneResult {
501  ONE_TO_ONE_NOT_CALLED_YET,
502  ONE_TO_ONE_FALSE,
503  ONE_TO_ONE_TRUE
504  } oneToOneResult_;
505 
509  bool locallyOneToOne_;
510 
518  bool useHashTables_;
519  };
520  } // namespace Details
521 } // namespace Tpetra
522 
523 #endif // __Tpetra_DirectoryImpl_decl_hpp
Interface for breaking ties in ownership.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
std::string description() const
A one-line human-readable description of this object.
Implementation of Directory for a locally replicated Map.
Interface for breaking ties in ownership.
virtual bool isOneToOne(const Teuchos::Comm< int > &) const
Whether the Directory&#39;s input Map is (globally) one to one.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
Implementation of Directory for a distributed noncontiguous Map.
Implementation of Directory for a distributed contiguous Map.
ReplicatedDirectory()
Constructor (that takes no arguments).
Implementation details of Tpetra.
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.
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.
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.
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.
virtual bool isOneToOne(const Teuchos::Comm< int > &) const
Whether the Directory&#39;s input Map is (globally) one to one.
Describes a parallel distribution of objects over processes.
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.
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 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 bool isOneToOne(const Teuchos::Comm< int > &comm) const
Whether the Directory&#39;s input Map is (globally) one to one.
Implementation of Directory for a contiguous, uniformly distributed Map.
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