10#ifndef TPETRA_DIRECTORY_HPP
11#define TPETRA_DIRECTORY_HPP
13#include "Tpetra_Distributor.hpp"
14#include "Tpetra_Map.hpp"
15#include "Tpetra_DirectoryImpl.hpp"
16#include "Tpetra_Directory_decl.hpp"
20 template<
class LO,
class GO,
class NT>
25 template<
class LO,
class GO,
class NT>
33 template<
class LO,
class GO,
class NT>
40 template<
class LO,
class GO,
class NT>
48 impl_ ==
NULL, std::logic_error,
"Tpetra::Directory::initialize: "
49 "The Directory claims that it has been initialized, "
50 "but its implementation object has not yet been created. "
51 "Please report this bug to the Tpetra developers.");
54 TEUCHOS_TEST_FOR_EXCEPTION(
55 impl_ != NULL, std::logic_error,
"Tpetra::Directory::initialize: "
56 "Directory implementation has already been initialized, "
57 "but initialized() returns false. "
58 "Please report this bug to the Tpetra developers.");
82 const ::Tpetra::Details::Directory<LO, GO, NT>* dir = NULL;
83 bool usedTieBreak =
false;
84 if (map.isDistributed ()) {
85 if (map.isUniform ()) {
86 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT> (map);
88 else if (map.isContiguous ()) {
89 dir = new ::Tpetra::Details::DistributedContiguousDirectory<LO, GO, NT> (map);
92 dir = new ::Tpetra::Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map, tieBreak);
97 dir = new ::Tpetra::Details::ReplicatedDirectory<LO, GO, NT> (map);
102 const int myRank = map.getComm ()->getRank ();
107 std::vector<std::pair<int, LO> > pidLidList (1);
108 const LO minLocInd = map.getMinLocalIndex ();
109 const LO maxLocInd = map.getMaxLocalIndex ();
110 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
111 pidLidList[0] = std::make_pair (myRank, locInd);
112 const GO globInd = map.getGlobalElement (locInd);
126 map.getLocalNumElements () != 0) {
129 std::vector<std::pair<int, LO> > pidLidList (1);
130 const LO minLocInd = map.getMinLocalIndex ();
131 const LO maxLocInd = map.getMaxLocalIndex ();
132 const int myRank = map.getComm ()->getRank ();
133 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
134 pidLidList[0] = std::make_pair (myRank, locInd);
135 const GO globInd = map.getGlobalElement (locInd);
146 template<
class LO,
class GO,
class NT>
150 if (initialized ()) {
151 TEUCHOS_TEST_FOR_EXCEPTION(
152 impl_ == NULL, std::logic_error,
"Tpetra::Directory::initialize: "
153 "The Directory claims that it has been initialized, "
154 "but its implementation object has not yet been created. "
155 "Please report this bug to the Tpetra developers.");
158 TEUCHOS_TEST_FOR_EXCEPTION(
159 impl_ != NULL, std::logic_error,
"Tpetra::Directory::initialize: "
160 "Directory implementation has already been initialized, "
161 "but initialized() returns false. "
162 "Please report this bug to the Tpetra developers.");
167 const ::Tpetra::Details::Directory<LO, GO, NT>* dir = NULL;
168 if (map.isDistributed ()) {
169 if (map.isUniform ()) {
170 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT> (map);
172 else if (map.isContiguous ()) {
173 dir = new ::Tpetra::Details::DistributedContiguousDirectory<LO, GO, NT> (map);
176 dir = new ::Tpetra::Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map);
180 dir = new ::Tpetra::Details::ReplicatedDirectory<LO, GO, NT> (map);
182 TEUCHOS_TEST_FOR_EXCEPTION(
183 dir == NULL, std::logic_error,
"Tpetra::Directory::initialize: "
184 "Failed to create Directory implementation. "
185 "Please report this bug to the Tpetra developers.");
190 template<
class LO,
class GO,
class NT>
194 const Teuchos::ArrayView<const GO>& globalIDs,
195 const Teuchos::ArrayView<int>& nodeIDs)
const
197 if (! initialized ()) {
201 const_cast<Directory<LO, GO, NT>*
> (
this)->
initialize (map);
203 const bool computeLIDs =
false;
204 return impl_->getEntries (map, globalIDs, nodeIDs, Teuchos::null, computeLIDs);
207 template<
class LO,
class GO,
class NT>
211 const Teuchos::ArrayView<const GO>& globalIDs,
212 const Teuchos::ArrayView<int>& nodeIDs,
213 const Teuchos::ArrayView<LO>& localIDs)
const
215 if (! initialized ()) {
219 const_cast<Directory<LO, GO, NT>*
> (
this)->
initialize (map);
221 const bool computeLIDs =
true;
222 return impl_->getEntries (map, globalIDs, nodeIDs, localIDs, computeLIDs);
225 template<
class LO,
class GO,
class NT>
227 if (! initialized ()) {
231 const_cast<Directory<LO, GO, NT>*
> (
this)->
initialize (map);
233 return impl_->isOneToOne (* (map.getComm ()));
236 template<
class LO,
class GO,
class NT>
240 using Teuchos::TypeNameTraits;
242 std::ostringstream
os;
258#define TPETRA_DIRECTORY_INSTANT(LO,GO,NODE) \
259 template class Directory< LO , GO , NODE >;
Struct that holds views of the contents of a CrsMatrix.
Interface for breaking ties in ownership.
virtual bool mayHaveSideEffects() const
Whether selectedIndex() may have side effects.
virtual std::size_t selectedIndex(GlobalOrdinal GID, const std::vector< std::pair< int, LocalOrdinal > > &pid_and_lid) const =0
Break any ties in ownership of the given global index GID.
Implement mapping from global ID to process ID and local ID.
std::string description() const
A one-line human-readable description of this object.
bool isOneToOne(const map_type &map) const
Whether the Directory's input Map is (globally) one to one.
LookupStatus getDirectoryEntries(const map_type &map, 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.
void initialize(const map_type &map)
Initialize the Directory with its Map.
bool initialized() const
Whether the Directory is initialized.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void initialize(int *argc, char ***argv)
Initialize Tpetra.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).