42 #ifndef TPETRA_DIRECTORY_HPP 43 #define TPETRA_DIRECTORY_HPP 45 #include "Tpetra_Distributor.hpp" 46 #include "Tpetra_Map.hpp" 47 #include "Tpetra_DirectoryImpl.hpp" 48 #include "Tpetra_Directory_decl.hpp" 52 template<
class LO,
class GO,
class NT>
57 template<
class LO,
class GO,
class NT>
65 template<
class LO,
class GO,
class NT>
72 template<
class LO,
class GO,
class NT>
79 TEUCHOS_TEST_FOR_EXCEPTION(
80 impl_ == NULL, std::logic_error,
"Tpetra::Directory::initialize: " 81 "The Directory claims that it has been initialized, " 82 "but its implementation object has not yet been created. " 83 "Please report this bug to the Tpetra developers.");
86 TEUCHOS_TEST_FOR_EXCEPTION(
87 impl_ != NULL, std::logic_error,
"Tpetra::Directory::initialize: " 88 "Directory implementation has already been initialized, " 89 "but initialized() returns false. " 90 "Please report this bug to the Tpetra developers.");
114 const Details::Directory<LO, GO, NT>* dir = NULL;
115 bool usedTieBreak =
false;
118 dir =
new Details::ContiguousUniformDirectory<LO, GO, NT> (map);
121 dir =
new Details::DistributedContiguousDirectory<LO, GO, NT> (map);
124 dir =
new Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map, tieBreak);
129 dir =
new Details::ReplicatedDirectory<LO, GO, NT> (map);
134 const int myRank = map.
getComm ()->getRank ();
139 std::vector<std::pair<int, LO> > pidLidList (1);
142 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
143 pidLidList[0] = std::make_pair (myRank, locInd);
161 std::vector<std::pair<int, LO> > pidLidList (1);
164 const int myRank = map.
getComm ()->getRank ();
165 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
166 pidLidList[0] = std::make_pair (myRank, locInd);
178 template<
class LO,
class GO,
class NT>
182 if (initialized ()) {
183 TEUCHOS_TEST_FOR_EXCEPTION(
184 impl_ == NULL, std::logic_error,
"Tpetra::Directory::initialize: " 185 "The Directory claims that it has been initialized, " 186 "but its implementation object has not yet been created. " 187 "Please report this bug to the Tpetra developers.");
190 TEUCHOS_TEST_FOR_EXCEPTION(
191 impl_ != NULL, std::logic_error,
"Tpetra::Directory::initialize: " 192 "Directory implementation has already been initialized, " 193 "but initialized() returns false. " 194 "Please report this bug to the Tpetra developers.");
199 const Details::Directory<LO, GO, NT>* dir = NULL;
200 if (map.isDistributed ()) {
201 if (map.isUniform ()) {
202 dir =
new Details::ContiguousUniformDirectory<LO, GO, NT> (map);
204 else if (map.isContiguous ()) {
205 dir =
new Details::DistributedContiguousDirectory<LO, GO, NT> (map);
208 dir =
new Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map);
212 dir =
new Details::ReplicatedDirectory<LO, GO, NT> (map);
214 TEUCHOS_TEST_FOR_EXCEPTION(
215 dir == NULL, std::logic_error,
"Tpetra::Directory::initialize: " 216 "Failed to create Directory implementation. " 217 "Please report this bug to the Tpetra developers.");
222 template<
class LO,
class GO,
class NT>
226 const Teuchos::ArrayView<const GO>& globalIDs,
227 const Teuchos::ArrayView<int>& nodeIDs)
const 229 if (! initialized ()) {
233 const_cast<Directory<LO, GO, NT>*
> (
this)->
initialize (map);
235 const bool computeLIDs =
false;
236 return impl_->getEntries (map, globalIDs, nodeIDs, Teuchos::null, computeLIDs);
239 template<
class LO,
class GO,
class NT>
243 const Teuchos::ArrayView<const GO>& globalIDs,
244 const Teuchos::ArrayView<int>& nodeIDs,
245 const Teuchos::ArrayView<LO>& localIDs)
const 247 if (! initialized ()) {
251 const_cast<Directory<LO, GO, NT>*
> (
this)->
initialize (map);
253 const bool computeLIDs =
true;
254 return impl_->getEntries (map, globalIDs, nodeIDs, localIDs, computeLIDs);
257 template<
class LO,
class GO,
class NT>
259 if (! initialized ()) {
263 const_cast<Directory<LO, GO, NT>*
> (
this)->
initialize (map);
265 return impl_->isOneToOne (* (map.getComm ()));
268 template<
class LO,
class GO,
class NT>
272 using Teuchos::TypeNameTraits;
274 std::ostringstream os;
276 <<
"<" << TypeNameTraits<LO>::name ()
277 <<
", " << TypeNameTraits<GO>::name ()
278 <<
", " << TypeNameTraits<NT>::name () <<
">";
290 #define TPETRA_DIRECTORY_INSTANT(LO,GO,NODE) \ 292 template class Directory< LO , GO , NODE >; \ 294 #endif // TPETRA_DIRECTORY_HPP Interface for breaking ties in ownership.
void initialize(int *argc, char ***argv)
Initialize Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
bool isOneToOne(const map_type &map) const
Whether the Directory's input Map is (globally) one to one.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
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.
bool initialized() const
Whether the Directory is initialized.
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
virtual bool mayHaveSideEffects() const
Whether selectedIndex() may have side effects.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
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.
Describes a parallel distribution of objects over processes.
void initialize(const map_type &map)
Initialize the Directory with its Map.
Directory()
Default constructor: the only one you should use.
bool isUniform() const
Whether the range of global indices is uniform.
std::string description() const
A one-line human-readable description of this object.
LocalOrdinal getMinLocalIndex() const
The minimum local index.