Tpetra parallel linear algebra  Version of the Day
Tpetra_DirectoryImpl_decl.hpp
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 
45 #include <Tpetra_ConfigDefs.hpp>
46 #include "Tpetra_TieBreak.hpp"
47 
48 //
49 // mfh 13-15 May 2013: HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX governs
50 // the fix for Bug 5822. The fix is enabled by default. To disable
51 // the fix, uncomment out the three lines below that undefine
52 // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX, and comment out the three
53 // lines below them that define that macro.
54 //
55 // mfh 23 Mar 2014: I want Bug 5822 to stay fixed, so I am removing
56 // all references to HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX. I hope no
57 // downstream code is using that macro, but just in case, I will leave
58 // it defined.
59 
60 #ifndef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
61 # define HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 1
62 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
63 
64 #include <Tpetra_Details_FixedHashTable_decl.hpp>
65 
66 
67 namespace Tpetra {
68  // Forward declaration.
69  template <class LocalOrdinal, class GlobalOrdinal, class Node> class Map;
70 
71  namespace Details {
72  // Forward declaration.
73  template <class LocalOrdinal, class GlobalOrdinal> class TieBreak;
74 
82  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
83  class Directory : public Teuchos::Describable {
84  public:
85  typedef LocalOrdinal local_ordinal_type;
86  typedef GlobalOrdinal global_ordinal_type;
87  typedef NodeType node_type;
88  typedef ::Tpetra::Map<LocalOrdinal, GlobalOrdinal, NodeType> map_type;
89 
97  Directory ();
98 
132  getEntries (const map_type& map,
133  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
134  const Teuchos::ArrayView<int> &nodeIDs,
135  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
136  const bool computeLIDs) const;
137 
144  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const = 0;
145 
146  protected:
148  virtual LookupStatus
149  getEntriesImpl (const map_type& map,
150  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
151  const Teuchos::ArrayView<int> &nodeIDs,
152  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
153  const bool computeLIDs) const = 0;
154  };
155 
158  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
160  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
161  public:
163  typedef typename base_type::map_type map_type;
164 
166  ReplicatedDirectory (const map_type& map);
167 
170 
171  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
172 
173  template <class Node2>
175  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
176  {
178  return new Dir2 (cloneMap);
179  }
180 
182 
183 
185  std::string description () const;
187  protected:
190  getEntriesImpl (const map_type& map,
191  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
192  const Teuchos::ArrayView<int> &nodeIDs,
193  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
194  const bool computeLIDs) const;
195 
196  private:
198  const int numProcs_;
199  };
200 
201 
210  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
212  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
213  private:
214  // This friend declaration lets us implement clone().
215  template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
216 
219 
220  public:
222  typedef typename base_type::map_type map_type;
223 
225  ContiguousUniformDirectory (const map_type& map);
226 
227  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
228  return true;
229  }
230 
231  template <class Node2>
233  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
234  {
236  return new Dir2 (cloneMap);
237  }
238 
240 
241 
243  std::string description () const;
245 
246  protected:
249  getEntriesImpl (const map_type& map,
250  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
251  const Teuchos::ArrayView<int> &nodeIDs,
252  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
253  const bool computeLIDs) const;
254  };
255 
256 
259  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
261  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
262  private:
263  template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
264 
267 
268  public:
270  typedef typename base_type::map_type map_type;
271 
273  DistributedContiguousDirectory (const map_type& map);
274 
275  virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
276  return true;
277  }
278 
279  template <class Node2>
281  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
282  {
284  Dir2* dir = new Dir2 (cloneMap);
285  try {
286  dir->allMinGIDs_ = allMinGIDs_;
287  } catch (std::exception& e) {
288  delete dir; // clean up just in case assignment throws (it shouldn't)
289  throw;
290  }
291  return dir;
292  }
293 
295 
296 
298  std::string description () const;
300 
301  protected:
304  getEntriesImpl (const map_type& map,
305  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
306  const Teuchos::ArrayView<int> &nodeIDs,
307  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
308  const bool computeLIDs) const;
309 
310  private:
334  Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
335  };
336 
339  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
341  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
342  private:
343  template <class LO, class GO, class N> friend class DistributedNoncontiguousDirectory;
346 
347  public:
350  typedef typename base_type::map_type map_type;
351 
353  DistributedNoncontiguousDirectory (const map_type& map);
354 
356  DistributedNoncontiguousDirectory (const map_type& map,
357  const tie_break_type& tie_break);
358 
359  virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
360 
361  template <class Node2>
363  clone (const ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
364  {
366  typedef ::Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node2> output_map_type;
367  Dir2* dir = new Dir2 (cloneMap);
368 
369  // This method returns a raw pointer. Thus, take care to
370  // check whether intermediate operations succeed, so that we
371  // don't leak memory if they don't.
372  RCP<const output_map_type> outDirMap;
373  try {
374  outDirMap = directoryMap_->template clone<Node2> (cloneMap.getNode ());
375  }
376  catch (...) {
377  outDirMap = Teuchos::null; // deallocate
378  throw;
379  }
380 
381  dir->directoryMap_ = outDirMap;
382  dir->PIDs_ = PIDs_;
383  dir->LIDs_ = LIDs_;
384  dir->lidToPidTable_ = lidToPidTable_;
385  dir->lidToLidTable_ = lidToLidTable_;
386  dir->useHashTables_ = useHashTables_;
387  return dir;
388  }
389 
391 
392 
394  std::string description () const;
396  protected:
399  getEntriesImpl (const map_type& map,
400  const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
401  const Teuchos::ArrayView<int> &nodeIDs,
402  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
403  const bool computeLIDs) const;
404  private:
411  void
412  initialize (const map_type& map,
413  Teuchos::Ptr<const tie_break_type> tie_break);
414 
427  bool isLocallyOneToOne () const {
428  return locallyOneToOne_;
429  }
430 
448  Teuchos::RCP<const map_type> directoryMap_;
449 
451 
452 
458  Teuchos::ArrayRCP<int> PIDs_;
459 
465  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
466 
468 
470 
476  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int,
477  Kokkos::Device<typename NodeType::execution_space,
478  typename NodeType::memory_space> > > lidToPidTable_;
479 
485  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal,
486  Kokkos::Device<typename NodeType::execution_space,
487  typename NodeType::memory_space> > > lidToLidTable_;
489 
496  mutable enum EOneToOneResult {
497  ONE_TO_ONE_NOT_CALLED_YET,
498  ONE_TO_ONE_FALSE,
499  ONE_TO_ONE_TRUE
500  } oneToOneResult_;
501 
505  bool locallyOneToOne_;
506 
514  bool useHashTables_;
515  };
516  } // namespace Details
517 } // namespace Tpetra
518 
519 #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.