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 
228  ContiguousUniformDirectory (const map_type& map);
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 
276  DistributedContiguousDirectory (const map_type& map);
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 
356  DistributedNoncontiguousDirectory (const map_type& map);
357 
359  DistributedNoncontiguousDirectory (const map_type& map,
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  {
369  typedef ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2> output_map_type;
370  Dir2* dir = new Dir2 (cloneMap);
371 
372  // This method returns a raw pointer. Thus, take care to
373  // check whether intermediate operations succeed, so that we
374  // don't leak memory if they don't.
375  RCP<const output_map_type> outDirMap;
376  try {
377  outDirMap = directoryMap_->template clone<Node2> (cloneMap.getNode ());
378  }
379  catch (...) {
380  outDirMap = Teuchos::null; // deallocate
381  throw;
382  }
383 
384  dir->directoryMap_ = outDirMap;
385  dir->PIDs_ = PIDs_;
386  dir->LIDs_ = LIDs_;
387  dir->lidToPidTable_ = lidToPidTable_;
388  dir->lidToLidTable_ = lidToLidTable_;
389  dir->useHashTables_ = useHashTables_;
390  return dir;
391  }
392 
394 
395 
397  std::string description () const;
399  protected:
402  getEntriesImpl (const map_type& map,
403  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
404  const Teuchos::ArrayView<int> &nodeIDs,
405  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
406  const bool computeLIDs) const;
407  private:
414  void
415  initialize (const map_type& map,
416  Teuchos::Ptr<const tie_break_type> tie_break);
417 
430  bool isLocallyOneToOne () const {
431  return locallyOneToOne_;
432  }
433 
451  Teuchos::RCP<const map_type> directoryMap_;
452 
454 
455 
461  Teuchos::ArrayRCP<int> PIDs_;
462 
468  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
469 
471 
473 
479  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int,
480  Kokkos::Device<typename NodeType::execution_space,
481  typename NodeType::memory_space> > > lidToPidTable_;
482 
488  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal,
489  Kokkos::Device<typename NodeType::execution_space,
490  typename NodeType::memory_space> > > lidToLidTable_;
492 
499  mutable enum EOneToOneResult {
500  ONE_TO_ONE_NOT_CALLED_YET,
501  ONE_TO_ONE_FALSE,
502  ONE_TO_ONE_TRUE
503  } oneToOneResult_;
504 
508  bool locallyOneToOne_;
509 
517  bool useHashTables_;
518  };
519  } // namespace Details
520 } // namespace Tpetra
521 
522 #endif // __Tpetra_DirectoryImpl_decl_hpp
Interface for breaking ties in ownership.
void initialize(int *argc, char ***argv)
Initialize Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Implementation of Directory for a locally replicated Map.
Interface for breaking ties in ownership.
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.
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.
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
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.
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.
virtual bool isOneToOne(const Teuchos::Comm< int > &) const
Whether the Directory&#39;s input Map is (globally) one to one.