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>
24 template <
class LO,
class GO,
class NT>
32 template <
class LO,
class GO,
class NT>
37 template <
class LO,
class GO,
class NT>
42 TEUCHOS_TEST_FOR_EXCEPTION(
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;
82 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT>(map);
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);
103 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
104 pidLidList[0] = std::make_pair(myRank, locInd);
122 std::vector<std::pair<int, LO> > pidLidList(1);
125 const int myRank = map.
getComm()->getRank();
126 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
127 pidLidList[0] = std::make_pair(myRank, locInd);
139 template <
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.");
180 template <
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);
196 template <
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);
213 template <
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()));
224 template <
class LO,
class GO,
class NT>
227 using Teuchos::TypeNameTraits;
229 std::ostringstream os;
231 <<
"<" << TypeNameTraits<LO>::name()
232 <<
", " << TypeNameTraits<GO>::name()
233 <<
", " << TypeNameTraits<NT>::name() <<
">";
245 #define TPETRA_DIRECTORY_INSTANT(LO, GO, NODE) \
246 template class Directory<LO, GO, NODE>;
248 #endif // TPETRA_DIRECTORY_HPP
Interface for breaking ties in ownership.
void initialize(int *argc, char ***argv)
Initialize Tpetra.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
bool isUniform() const
Whether the range of global indices is uniform.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
local_ordinal_type getMinLocalIndex() const
The minimum local index.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
bool isOneToOne(const map_type &map) const
Whether the Directory's input Map is (globally) one to one.
local_ordinal_type getMaxLocalIndex() const
The maximum local index on the calling process.
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.
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.
A parallel distribution of indices over processes.
bool initialized() const
Whether the Directory is initialized.
void initialize(const map_type &map)
Initialize the Directory with its Map.
Directory()
Default constructor: the only one you should use.
std::string description() const
A one-line human-readable description of this object.
virtual bool mayHaveSideEffects() const
Whether selectedIndex() may have side effects.