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>
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);
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()) {
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()) {
209 const bool computeLIDs =
true;
210 return impl_->getEntries(map, globalIDs, nodeIDs, localIDs, computeLIDs);
213template <
class LO,
class GO,
class NT>
215 if (!initialized()) {
221 return impl_->isOneToOne(*(map.getComm()));
224template <
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>;
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.
Directory()
Default constructor: the only one you should use.
A parallel distribution of indices over processes.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
bool isUniform() const
Whether the range of global indices is uniform.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
local_ordinal_type getMinLocalIndex() const
The minimum local index.
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
local_ordinal_type getMaxLocalIndex() const
The maximum local index on the calling process.
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()).