Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
47 //
48 // mfh 13-15 May 2013: HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX governs
49 // the fix for Bug 5822. The fix is enabled by default. To disable
50 // the fix, uncomment out the three lines below that undefine
51 // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX, and comment out the three
52 // lines below them that define that macro.
53 //
54 
55 // #ifdef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
56 // # undef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
57 // #endif HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
58 
59 #ifndef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
60 # define HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 1
61 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
62 
63 #ifdef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
64 # include <Tpetra_Details_FixedHashTable_decl.hpp>
65 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
66 
67 
68 namespace Tpetra {
69  // Forward declaration.
70  template <class LocalOrdinal, class GlobalOrdinal, class Node> class Map;
71 
72  namespace Details {
80  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
81  class Directory : public Teuchos::Describable {
82  public:
83  typedef LocalOrdinal local_ordinal_type;
84  typedef GlobalOrdinal global_ordinal_type;
85  typedef NodeType node_type;
87 
89  Directory (const Teuchos::RCP<const map_type>& map);
90 
119  getEntries (const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
120  const Teuchos::ArrayView<int> &nodeIDs,
121  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
122  const bool computeLIDs) const;
123 
124  protected:
126  virtual LookupStatus
127  getEntriesImpl (const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
128  const Teuchos::ArrayView<int> &nodeIDs,
129  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
130  const bool computeLIDs) const = 0;
131 
133  Teuchos::RCP<const map_type> getMap () const { return map_; }
134 
136  void setMap (const Teuchos::RCP<const map_type> &map) { map_ = map; }
137 
140 
141  private:
143  Teuchos::RCP<const map_type> map_;
144  };
145 
148  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
150  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
151  public:
153  typedef typename base_type::map_type map_type;
154 
156  ReplicatedDirectory (const Teuchos::RCP<const map_type>& map);
157 
158  template <class Node2>
159  RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
160  clone(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node2> > &clone_map) const
161  {
162  // this class has only the map as its data; cloning is trivial
164  }
165 
167 
168 
170  std::string description () const;
172  protected:
175  getEntriesImpl (const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
176  const Teuchos::ArrayView<int> &nodeIDs,
177  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
178  const bool computeLIDs) const;
179  };
180 
181 
190  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
192  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
193  private:
194  // This friend declaration lets us implement clone().
195  template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
196 
199 
200  public:
202  typedef typename base_type::map_type map_type;
203 
205  ContiguousUniformDirectory (const Teuchos::RCP<const map_type>& map);
206 
207  template <class Node2>
208  RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
209  clone (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node2> > &clone_map) const
210  {
212  RCP<Dir2> dir = rcp (new Dir2 ());
213  dir->setMap (clone_map);
214  return dir;
215  }
216 
218 
219 
221  std::string description () const;
223 
224  protected:
227  getEntriesImpl (const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
228  const Teuchos::ArrayView<int> &nodeIDs,
229  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
230  const bool computeLIDs) const;
231  };
232 
233 
236  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
238  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
239  private:
240  template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
241 
244 
245  public:
247  typedef typename base_type::map_type map_type;
248 
250  DistributedContiguousDirectory (const Teuchos::RCP<const map_type>& map);
251 
252  template <class Node2>
253  RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
254  clone(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node2> > &clone_map) const
255  {
257  RCP<Dir2> dir = rcp(new Dir2());
258  dir->setMap ( clone_map );
259  dir->allMinGIDs_ = allMinGIDs_;
260  return dir;
261  }
262 
264 
265 
267  std::string description () const;
269 
270  protected:
273  getEntriesImpl (const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
274  const Teuchos::ArrayView<int> &nodeIDs,
275  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
276  const bool computeLIDs) const;
277  private:
301  Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
302  };
303 
306  template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
308  public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
309  private:
310  template <class LO, class GO, class N> friend class DistributedNoncontiguousDirectory;
313 
314  public:
316  typedef typename base_type::map_type map_type;
317 
319  DistributedNoncontiguousDirectory (const Teuchos::RCP<const map_type>& map);
320 
321  template <class Node2>
322  RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
323  clone (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node2> >& cloneMap) const
324  {
326  RCP<Dir2> dir (new Dir2 ());
327  dir->setMap (cloneMap);
328  dir->directoryMap_ =
329  directoryMap_->template clone<Node2> (cloneMap->getNode ());
330  dir->PIDs_ = PIDs_;
331  dir->LIDs_ = LIDs_;
332  return dir;
333  }
334 
336 
337 
339  std::string description () const;
341  protected:
344  getEntriesImpl (const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
345  const Teuchos::ArrayView<int> &nodeIDs,
346  const Teuchos::ArrayView<LocalOrdinal> &localIDs,
347  const bool computeLIDs) const;
348  private:
366  Teuchos::RCP<const map_type> directoryMap_;
367 
369 
370 
376  Teuchos::ArrayRCP<int> PIDs_;
377 
383  Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
384 
385 #ifdef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
386 
387 
389 
395  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int> > lidToPidTable_;
396 
402  Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal> > lidToLidTable_;
404 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
405 
413  bool useHashTables_;
414  };
415  } // namespace Details
416 } // namespace Tpetra
417 
418 #endif // __Tpetra_DirectoryImpl_decl_hpp
LookupStatus getEntries(const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs, const Teuchos::ArrayView< LocalOrdinal > &localIDs, const bool computeLIDs) const
Implementation of Directory for a locally replicated Map.
std::string description() const
A one-line human-readable description of this object.
Implementation of Directory for a distributed noncontiguous Map.
Implementation of Directory for a distributed contiguous Map.
LookupStatus getEntriesImpl(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 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.
Directory()
Empty constructor for post-constructor initialization.
LookupStatus getEntriesImpl(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 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.
void setMap(const Teuchos::RCP< const map_type > &map)
Set the Map for this object, for post-contructor initialization.
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.
Describes a parallel distribution of objects over processes.
virtual LookupStatus getEntriesImpl(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.
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.
Teuchos::RCP< const map_type > getMap() const
Get the Map with which this object was created.
Implementation of Directory for a contiguous, uniformly distributed Map.
ReplicatedDirectory(const Teuchos::RCP< const map_type > &map)
Constructor.