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>
47 TEUCHOS_TEST_FOR_EXCEPTION(
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;
86 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT> (map);
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);
110 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
111 pidLidList[0] = std::make_pair (myRank, locInd);
129 std::vector<std::pair<int, LO> > pidLidList (1);
132 const int myRank = map.
getComm ()->getRank ();
133 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
134 pidLidList[0] = std::make_pair (myRank, 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 ()) {
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 ()) {
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 ()) {
233 return impl_->isOneToOne (* (map.getComm ()));
236 template<
class LO,
class GO,
class NT>
240 using Teuchos::TypeNameTraits;
242 std::ostringstream os;
244 <<
"<" << TypeNameTraits<LO>::name ()
245 <<
", " << TypeNameTraits<GO>::name ()
246 <<
", " << TypeNameTraits<NT>::name () <<
">";
258#define TPETRA_DIRECTORY_INSTANT(LO,GO,NODE) \
259 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()).