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"
20template <
class LO,
class GO,
class NT>
24template <
class LO,
class GO,
class NT>
32template <
class LO,
class GO,
class NT>
37template <
class LO,
class GO,
class NT>
43 impl_ ==
NULL, std::logic_error,
44 "Tpetra::Directory::initialize: "
45 "The Directory claims that it has been initialized, "
46 "but its implementation object has not yet been created. "
47 "Please report this bug to the Tpetra developers.");
49 TEUCHOS_TEST_FOR_EXCEPTION(
50 impl_ != NULL, std::logic_error,
51 "Tpetra::Directory::initialize: "
52 "Directory implementation has already been initialized, "
53 "but initialized() returns false. "
54 "Please report this bug to the Tpetra developers.");
78 const ::Tpetra::Details::Directory<LO, GO, NT>* dir = NULL;
79 bool usedTieBreak =
false;
80 if (map.isDistributed()) {
81 if (map.isUniform()) {
82 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT>(map);
83 }
else if (map.isContiguous()) {
84 dir = new ::Tpetra::Details::DistributedContiguousDirectory<LO, GO, NT>(map);
86 dir = new ::Tpetra::Details::DistributedNoncontiguousDirectory<LO, GO, NT>(map, tieBreak);
90 dir = new ::Tpetra::Details::ReplicatedDirectory<LO, GO, NT>(map);
95 const int myRank = map.getComm()->getRank();
100 std::vector<std::pair<int, LO> > pidLidList(1);
101 const LO minLocInd = map.getMinLocalIndex();
102 const LO maxLocInd = map.getMaxLocalIndex();
103 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
104 pidLidList[0] = std::make_pair(myRank, locInd);
105 const GO globInd = map.getGlobalElement(locInd);
119 map.getLocalNumElements() != 0) {
122 std::vector<std::pair<int, LO> > pidLidList(1);
123 const LO minLocInd = map.getMinLocalIndex();
124 const LO maxLocInd = map.getMaxLocalIndex();
125 const int myRank = map.getComm()->getRank();
126 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
127 pidLidList[0] = std::make_pair(myRank, locInd);
128 const GO globInd = map.getGlobalElement(locInd);
139template <
class LO,
class GO,
class NT>
142 TEUCHOS_TEST_FOR_EXCEPTION(
143 impl_ == NULL, std::logic_error,
144 "Tpetra::Directory::initialize: "
145 "The Directory claims that it has been initialized, "
146 "but its implementation object has not yet been created. "
147 "Please report this bug to the Tpetra developers.");
149 TEUCHOS_TEST_FOR_EXCEPTION(
150 impl_ != NULL, std::logic_error,
151 "Tpetra::Directory::initialize: "
152 "Directory implementation has already been initialized, "
153 "but initialized() returns false. "
154 "Please report this bug to the Tpetra developers.");
159 const ::Tpetra::Details::Directory<LO, GO, NT>* dir = NULL;
160 if (map.isDistributed()) {
161 if (map.isUniform()) {
162 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT>(map);
163 }
else if (map.isContiguous()) {
164 dir = new ::Tpetra::Details::DistributedContiguousDirectory<LO, GO, NT>(map);
166 dir = new ::Tpetra::Details::DistributedNoncontiguousDirectory<LO, GO, NT>(map);
169 dir = new ::Tpetra::Details::ReplicatedDirectory<LO, GO, NT>(map);
171 TEUCHOS_TEST_FOR_EXCEPTION(
172 dir == NULL, std::logic_error,
173 "Tpetra::Directory::initialize: "
174 "Failed to create Directory implementation. "
175 "Please report this bug to the Tpetra developers.");
180template <
class LO,
class GO,
class NT>
184 const Teuchos::ArrayView<const GO>& globalIDs,
185 const Teuchos::ArrayView<int>& nodeIDs)
const {
186 if (!initialized()) {
190 const_cast<Directory<LO, GO, NT>*
>(
this)->
initialize(map);
192 const bool computeLIDs =
false;
193 return impl_->getEntries(map, globalIDs, nodeIDs, Teuchos::null, computeLIDs);
196template <
class LO,
class GO,
class NT>
200 const Teuchos::ArrayView<const GO>& globalIDs,
201 const Teuchos::ArrayView<int>& nodeIDs,
202 const Teuchos::ArrayView<LO>& localIDs)
const {
203 if (!initialized()) {
207 const_cast<Directory<LO, GO, NT>*
>(
this)->
initialize(map);
209 const bool computeLIDs =
true;
210 return impl_->getEntries(map, globalIDs, nodeIDs, localIDs, computeLIDs);
213template <
class LO,
class GO,
class NT>
215 if (!initialized()) {
219 const_cast<Directory<LO, GO, NT>*
>(
this)->
initialize(map);
221 return impl_->isOneToOne(*(map.getComm()));
224template <
class LO,
class GO,
class NT>
227 using Teuchos::TypeNameTraits;
229 std::ostringstream
os;
245#define TPETRA_DIRECTORY_INSTANT(LO, GO, NODE) \
246 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()).