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>
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 ::Tpetra::Details::Directory<LO, GO, NT>* dir = NULL;
115 bool usedTieBreak =
false;
116 if (map.isDistributed ()) {
117 if (map.isUniform ()) {
118 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT> (map);
120 else if (map.isContiguous ()) {
121 dir = new ::Tpetra::Details::DistributedContiguousDirectory<LO, GO, NT> (map);
124 dir = new ::Tpetra::Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map, tieBreak);
129 dir = new ::Tpetra::Details::ReplicatedDirectory<LO, GO, NT> (map);
134 const int myRank = map.getComm ()->getRank ();
139 std::vector<std::pair<int, LO> > pidLidList (1);
140 const LO minLocInd = map.getMinLocalIndex ();
141 const LO maxLocInd = map.getMaxLocalIndex ();
142 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
143 pidLidList[0] = std::make_pair (myRank, locInd);
144 const GO globInd = map.getGlobalElement (locInd);
158 map.getLocalNumElements () != 0) {
161 std::vector<std::pair<int, LO> > pidLidList (1);
162 const LO minLocInd = map.getMinLocalIndex ();
163 const LO maxLocInd = map.getMaxLocalIndex ();
164 const int myRank = map.getComm ()->getRank ();
165 for (LO locInd = minLocInd; locInd <= maxLocInd; ++locInd) {
166 pidLidList[0] = std::make_pair (myRank, locInd);
167 const GO globInd = map.getGlobalElement (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 ::Tpetra::Details::Directory<LO, GO, NT>* dir = NULL;
200 if (map.isDistributed ()) {
201 if (map.isUniform ()) {
202 dir = new ::Tpetra::Details::ContiguousUniformDirectory<LO, GO, NT> (map);
204 else if (map.isContiguous ()) {
205 dir = new ::Tpetra::Details::DistributedContiguousDirectory<LO, GO, NT> (map);
208 dir = new ::Tpetra::Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map);
212 dir = new ::Tpetra::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;
290#define TPETRA_DIRECTORY_INSTANT(LO,GO,NODE) \
291 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()).