Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Tpetra_Directory_def.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_DIRECTORY_HPP
43 #define TPETRA_DIRECTORY_HPP
44 
45 #include <Teuchos_as.hpp>
46 #include <Tpetra_ConfigDefs.hpp>
47 #include <Tpetra_Distributor.hpp>
48 #include <Tpetra_Map.hpp>
49 #include <Tpetra_DirectoryImpl.hpp>
50 #include <Tpetra_DirectoryImpl_def.hpp>
51 
52 #ifdef DOXYGEN_USE_ONLY
53 # include "Tpetra_Directory_decl.hpp"
54 #endif
55 
56 namespace Tpetra {
57 
58  template<class LO, class GO, class NT>
59  Directory<LO, GO, NT>::
60  Directory (const Teuchos::RCP<const Map<LO, GO, NT> >& map)
61  {
62  // Create an implementation object of the appropriate type,
63  // depending on whether the Map is distributed or replicated, and
64  // contiguous or noncontiguous.
65  RCP<const Details::Directory<LO, GO, NT> > dir;
66  if (map->isDistributed ()) {
67  if (map->isUniform ()) {
68  dir = rcp (new Details::ContiguousUniformDirectory<LO, GO, NT> (map));
69  }
70  else if (map->isContiguous ()) {
71  dir = rcp (new Details::DistributedContiguousDirectory<LO, GO, NT> (map));
72  }
73  else {
74  dir = rcp (new Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map));
75  }
76  }
77  else {
78  dir = rcp (new Details::ReplicatedDirectory<LO, GO, NT> (map));
79  }
80  TEUCHOS_TEST_FOR_EXCEPTION(dir.is_null (), std::logic_error, "Tpetra::"
81  "Directory constructor failed to create Directory implementation. "
82  "Please report this bug to the Tpetra developers.");
83  impl_ = dir;
84  }
85 
86  template<class LO, class GO, class NT>
87  Directory<LO, GO, NT>::Directory() {}
88 
89  template<class LO, class GO, class NT>
91 
92  template<class LO, class GO, class NT>
95  getDirectoryEntries (const Teuchos::ArrayView<const GO>& globalIDs,
96  const Teuchos::ArrayView<int>& nodeIDs) const
97  {
98  const bool computeLIDs = false;
99  return impl_->getEntries (globalIDs, nodeIDs, Teuchos::null, computeLIDs);
100  }
101 
102  template<class LO, class GO, class NT>
105  getDirectoryEntries (const Teuchos::ArrayView<const GO>& globalIDs,
106  const Teuchos::ArrayView<int>& nodeIDs,
107  const Teuchos::ArrayView<LO>& localIDs) const
108  {
109  const bool computeLIDs = true;
110  return impl_->getEntries (globalIDs, nodeIDs, localIDs, computeLIDs);
111  }
112 
113  template<class LO, class GO, class NT>
114  std::string
116  {
117  using Teuchos::TypeNameTraits;
118 
119  std::ostringstream os;
120  os << "Directory"
121  << "<" << TypeNameTraits<LO>::name ()
122  << ", " << TypeNameTraits<GO>::name ()
123  << ", " << TypeNameTraits<NT>::name () << ">";
124  return os.str ();
125  }
126 
127 } // namespace Tpetra
128 
129 //
130 // Explicit instantiation macro
131 //
132 // Must be expanded from within the Tpetra namespace!
133 //
134 
135 #define TPETRA_DIRECTORY_INSTANT(LO,GO,NODE) \
136  \
137  template class Directory< LO , GO , NODE >; \
138 
139 #endif // TPETRA_DIRECTORY_HPP
LookupStatus getDirectoryEntries(const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs) const
Given a global ID list, return the list of their owning process IDs.
std::string description() const
A one-line human-readable description of this object.