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_TieBreak.hpp"
49 #include "Tpetra_Map_fwd.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 #ifndef DOXYGEN_SHOULD_SKIP_THIS
70 // Forward declaration of Teuchos::Comm
71 namespace Teuchos {
72  template<class OrdinalType>
73  class Comm;
74 } // namespace Teuchos
75 #endif // DOXYGEN_SHOULD_SKIP_THIS
76 
77 namespace Tpetra {
78  namespace Details {
86  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
87  class Directory : public Teuchos::Describable {
88  public:
89  typedef LocalOrdinal local_ordinal_type;
90  typedef GlobalOrdinal global_ordinal_type;
91  typedef NodeType node_type;
92  typedef ::Tpetra::Map<LocalOrdinal, GlobalOrdinal, NodeType> map_type;
93 
101  Directory () = default;
102 
103  virtual ~Directory () = default;
104 
138  getEntries (const map_type& map,
139  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
140  const Teuchos::ArrayView<int> &nodeIDs,
141  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
142  const bool computeLIDs) const;
143 
150  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const = 0;
151 
152  protected:
154  virtual LookupStatus
155  getEntriesImpl (const map_type& map,
156  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
157  const Teuchos::ArrayView<int> &nodeIDs,
158  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
159  const bool computeLIDs) const = 0;
160  };
161 
164  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
166  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
167  public:
169  typedef typename base_type::map_type map_type;
170 
172  ReplicatedDirectory () = default;
173 
175  ReplicatedDirectory (const map_type& map);
176 
177  ~ReplicatedDirectory () override = default;
178 
179  bool isOneToOne (const Teuchos::Comm<int>& comm) const override;
180 
181 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
182  template <class Node2>
184  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
185  {
187  return new Dir2 (cloneMap);
188  }
189 #endif
190 
192 
193 
195  std::string description () const;
197  protected:
200  getEntriesImpl (const map_type& map,
201  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
202  const Teuchos::ArrayView<int> &nodeIDs,
203  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
204  const bool computeLIDs) const override;
205 
206  private:
208  const int numProcs_ = 0;
209  };
210 
211 
220  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
222  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
223  private:
224  // This friend declaration lets us implement clone().
225  template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
226 
227  public:
229  typedef typename base_type::map_type map_type;
230 
231  ContiguousUniformDirectory () = default;
233  ~ContiguousUniformDirectory () override = default;
234 
235  bool isOneToOne (const Teuchos::Comm<int>&) const override {
236  return true;
237  }
238 
239 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
240  template <class Node2>
242  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
243  {
245  return new Dir2 (cloneMap);
246  }
247 #endif
248 
250 
251 
253  std::string description () const;
255 
256  protected:
259  getEntriesImpl (const map_type& map,
260  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
261  const Teuchos::ArrayView<int> &nodeIDs,
262  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
263  const bool computeLIDs) const override;
264  };
265 
266 
269  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
271  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
272  private:
273  template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
274 
275  public:
277  typedef typename base_type::map_type map_type;
278 
279  DistributedContiguousDirectory () = default;
281  ~DistributedContiguousDirectory () override = default;
282 
283  bool isOneToOne (const Teuchos::Comm<int>&) const override {
284  return true;
285  }
286 
287 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
288  template <class Node2>
290  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
291  {
293  Dir2* dir = new Dir2 (cloneMap);
294  try {
295  dir->allMinGIDs_ = allMinGIDs_;
296  } catch (std::exception& e) {
297  delete dir; // clean up just in case assignment throws (it shouldn't)
298  throw;
299  }
300  return dir;
301  }
302 #endif
303 
305 
306 
308  std::string description () const;
310 
311  protected:
314  getEntriesImpl (const map_type& map,
315  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
316  const Teuchos::ArrayView<int> &nodeIDs,
317  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
318  const bool computeLIDs) const override;
319 
320  private:
344  Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
345  };
346 
349  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
351  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
352  private:
353  template <class LO, class GO, class N>
355 
356  public:
359  using map_type = typename base_type::map_type;
360 
362  DistributedNoncontiguousDirectory (const map_type& map);
363  DistributedNoncontiguousDirectory (const map_type& map,
364  const tie_break_type& tie_break);
365  ~DistributedNoncontiguousDirectory () override = default;
366 
367  bool isOneToOne (const Teuchos::Comm<int>& comm) const override;
368 
369 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
370  template <class Node2>
372  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
373  {
374  using Teuchos::RCP;
376  typedef ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2> output_map_type;
377  Dir2* dir = new Dir2 (cloneMap);
378 
379  // This method returns a raw pointer. Thus, take care to
380  // check whether intermediate operations succeed, so that we
381  // don't leak memory if they don't.
382  RCP<const output_map_type> outDirMap;
383  try {
384  outDirMap = directoryMap_->template clone<Node2> (cloneMap.getNode ());
385  }
386  catch (...) {
387  outDirMap = Teuchos::null; // deallocate
388  throw;
389  }
390 
391  dir->directoryMap_ = outDirMap;
392  dir->PIDs_ = PIDs_;
393  dir->LIDs_ = LIDs_;
394  dir->lidToPidTable_ = lidToPidTable_;
395  dir->lidToLidTable_ = lidToLidTable_;
396  dir->useHashTables_ = useHashTables_;
397  return dir;
398  }
399 #endif
400 
402 
403 
405  std::string description () const;
407  protected:
410  getEntriesImpl (const map_type& map,
411  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
412  const Teuchos::ArrayView<int> &nodeIDs,
413  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
414  const bool computeLIDs) const override;
415  private:
422  void
423  initialize (const map_type& map,
424  Teuchos::Ptr<const tie_break_type> tie_break);
425 
438  bool isLocallyOneToOne () const {
439  return locallyOneToOne_;
440  }
441 
459  Teuchos::RCP<const map_type> directoryMap_;
460 
462 
463 
469  Teuchos::ArrayRCP<int> PIDs_;
470 
476  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
477 
479 
481 
487  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int,
488  Kokkos::Device<typename NodeType::execution_space,
489  typename NodeType::memory_space> > > lidToPidTable_;
490 
496  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal,
497  Kokkos::Device<typename NodeType::execution_space,
498  typename NodeType::memory_space> > > lidToLidTable_;
500 
507  mutable enum EOneToOneResult {
508  ONE_TO_ONE_NOT_CALLED_YET,
509  ONE_TO_ONE_FALSE,
510  ONE_TO_ONE_TRUE
511  } oneToOneResult_;
512 
516  bool locallyOneToOne_;
517 
525  bool useHashTables_;
526  };
527  } // namespace Details
528 } // namespace Tpetra
529 
530 #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()).
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
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.
ReplicatedDirectory()=default
Constructor (that takes no arguments).
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.
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.
Forward declaration of Tpetra::Map.