/usr/include/trilinos/Tpetra_DistObject.hpp is in libtrilinos-dev 10.4.0.dfsg-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | // @HEADER
// ***********************************************************************
//
// Tpetra: Templated Linear Algebra Services Package
// Copyright (2008) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ***********************************************************************
// @HEADER
#ifndef TPETRA_DISTOBJECT_HPP
#define TPETRA_DISTOBJECT_HPP
#include "Tpetra_ConfigDefs.hpp"
#include "Tpetra_Map.hpp"
#include "Tpetra_Import.hpp"
#include "Tpetra_Export.hpp"
#include "Tpetra_Distributor.hpp"
#include <Kokkos_DefaultNode.hpp>
#include <Teuchos_Describable.hpp>
#include <Teuchos_OrdinalTraits.hpp>
#include <Teuchos_RCP.hpp>
#include <Teuchos_Comm.hpp>
namespace Tpetra {
//! A base class for distributed objects that support import and export operations.
/*! The DistObject is a base class for all Tpetra distributed global objects. It provides the basic
mechanisms and interface specifications for importing and exporting operations using Tpetra::Import and
Tpetra::Export objects.
<b> Distributed Global vs. Replicated Local.</b>
<ul>
<li> Distributed Global objects - In most instances, a distributed object will be partitioned
across multiple memory images associated with multiple processors. In this case, there is
a unique copy of each element and elements are spread across all images specified by
the Teuchos::Comm object.
<li> Replicated Local Objects - Some algorithms use objects that are too small to
be distributed across all processors, the Hessenberg matrix in a GMRES
computation. In other cases, such as with block iterative methods, block dot product
functions produce small dense matrices that are required by all images.
Replicated local objects handle these types of situation.
</ul>
*/
template <class Packet, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = Kokkos::DefaultNode::DefaultNodeType>
class DistObject : virtual public Teuchos::Describable {
public:
//! @name Constructor/Destructor Methods
//@{
//! constructor
explicit DistObject(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map);
//! copy constructor
DistObject(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> &source);
//! destructor
virtual ~DistObject();
//@}
//! @name Import/Export Methods
//@{
//! Import
void doImport(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> &source,
const Import<LocalOrdinal,GlobalOrdinal,Node> &importer, CombineMode CM);
//! Export
void doExport(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> &dest,
const Export<LocalOrdinal,GlobalOrdinal,Node> &exporter, CombineMode CM);
//! Import (using an Exporter)
void doImport(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> &source,
const Export<LocalOrdinal,GlobalOrdinal,Node>& exporter, CombineMode CM);
//! Export (using an Importer)
void doExport(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> &dest,
const Import<LocalOrdinal,GlobalOrdinal,Node>& importer, CombineMode CM);
//@}
//! @name Attribute Accessor Methods
//@{
//! Accessor for whether or not this is a global object
inline bool isDistributed() const;
//! Access function for the Tpetra::Map this DistObject was constructed with.
inline const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getMap() const { return map_; }
//@}
//! @name I/O methods
//@{
//! Print method.
void print(std::ostream &os) const;
//@}
protected:
//! Enum indicating whether the transer should be performed in forward or reverse mode.
enum ReverseOption {
DoForward, //*!< Indicates that the transfer should be performed in forward mode.
DoReverse //*!< Indicates that the transfer should be performed in reverse mode.
};
//! Perform transfer (redistribution) of data across memory images.
virtual void doTransfer(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> &source,
CombineMode CM,
size_t numSameIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &remoteLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
Distributor &distor,
ReverseOption revOp);
// The following four methods must be implemented by the derived class
//! Allows the source and target (\e this) objects to be compared for compatibility.
/*! Return true if they are compatible, return false if they aren't. */
virtual bool checkSizes(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & source) = 0;
//! Perform copies and permutations that are local to this image.
/*!
\param source In
On entry, the DistObject that we are importing from.
\param numSameIDs In
On entry, the number of elements that are the same on the source and dest objects.
(i.e. The element is owned by the same image in both source and dest,
and no permutation occurs.)
\param numPermuteIDs In
On entry, the number of elements that are locally permuted between source and dest objects.
\param permuteToLIDs In
On entry, contains a list of the elements that are permuted. (Listed by their LID in the
destination DistObject.)
\param permuteFromLIDs In
On entry, contains a list of the elements that are permuted. (Listed by their LID in the
source DistObject.)
*/
virtual void copyAndPermute(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & source,
size_t numSameIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs) = 0;
//! Perform any packing or preparation required for communication.
/*!
\param source In
On entry, the DistObject that we are importing from.
\param exportLIDs In
On entry, a list of the entries we will be sending to other images.
(Listed by their LID in the source DistObject.)
\param exports Out
On exit, buffer for data we will be sending out.
\param numPacketsPerLID Out
On exit, numPacketsPerLID[i] contains the number of packets to be exported for
exportLIDs[i].
\param constantNumPackets Out
On exit, 0 if numPacketsPerLID has variable contents (different size for each LID).
If nonzero, then it is expected that num-packets-per-LID is constant, and
constantNumPackets holds that value.
\param distor In
On entry, contains the Distributor object we are using.
*/
virtual void packAndPrepare(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & source,
const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
Teuchos::Array<Packet> &exports,
const Teuchos::ArrayView<size_t> & numPacketsPerLID,
size_t& constantNumPackets,
Distributor &distor) = 0;
//! Perform any unpacking and combining after communication.
/*!
\param importLIDs In
On entry, a list of the entries we received from other images.
(Listed by their LID in the target DistObject.)
\param imports In
Buffer containing data we received.
\param numPacketsPerLID In
numPacketsPerLID[i] contains the number of packets imported for
importLIDs[i].
\param constantNumPackets In
If nonzero, then numPacketsPerLID is constant (same value in all entries)
and constantNumPackets is that value.
\param distor In
The Distributor object we are using.
\param CM In
The Tpetra::CombineMode to use when combining the imported entries with existing entries.
*/
virtual void unpackAndCombine(const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
const Teuchos::ArrayView<const Packet> &imports,
const Teuchos::ArrayView<size_t> &numPacketsPerLID,
size_t constantNumPackets,
Distributor &distor,
CombineMode CM) = 0;
virtual void createViews() const {}
virtual void createViewsNonConst(Kokkos::ReadWriteOption rwo) {}
virtual void releaseViews() const {}
private:
Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > map_;
// buffers into which packed data is imported
Teuchos::Array<Packet> imports_;
Teuchos::Array<size_t> numImportPacketsPerLID_;
// buffers from which packed data is exported
Teuchos::Array<Packet> exports_;
Teuchos::Array<size_t> numExportPacketsPerLID_;
}; // class DistObject
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::DistObject(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & map)
: map_(map)
{}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::DistObject(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & source)
: map_(source.map_)
{}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::~DistObject()
{}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
void DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::doImport(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & A,
const Import<LocalOrdinal,GlobalOrdinal,Node> & importer, CombineMode CM)
{
TEST_FOR_EXCEPTION( getMap() != importer.getTargetMap(), std::runtime_error, "Target Maps don't match.");
TEST_FOR_EXCEPTION( A.getMap() != importer.getSourceMap(), std::runtime_error, "Source Maps don't match.");
size_t numSameIDs = importer.getNumSameIDs();
const Teuchos::ArrayView<const LocalOrdinal> exportLIDs = importer.getExportLIDs();
const Teuchos::ArrayView<const LocalOrdinal> remoteLIDs = importer.getRemoteLIDs();
const Teuchos::ArrayView<const LocalOrdinal> permuteToLIDs = importer.getPermuteToLIDs();
const Teuchos::ArrayView<const LocalOrdinal> permuteFromLIDs = importer.getPermuteFromLIDs();
this->doTransfer(A, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs, exportLIDs,
importer.getDistributor(), DoForward);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
void DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::doExport(const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & A,
const Export<LocalOrdinal,GlobalOrdinal,Node> & exporter, CombineMode CM)
{
TEST_FOR_EXCEPTION( getMap() != exporter.getTargetMap(), std::runtime_error, "Target Maps don't match.");
TEST_FOR_EXCEPTION( A.getMap() != exporter.getSourceMap(), std::runtime_error, "Source Maps don't match.");
size_t numSameIDs = exporter.getNumSameIDs();
Teuchos::ArrayView<const LocalOrdinal> exportLIDs = exporter.getExportLIDs();
Teuchos::ArrayView<const LocalOrdinal> remoteLIDs = exporter.getRemoteLIDs();
Teuchos::ArrayView<const LocalOrdinal> permuteToLIDs = exporter.getPermuteToLIDs();
Teuchos::ArrayView<const LocalOrdinal> permuteFromLIDs = exporter.getPermuteFromLIDs();
doTransfer(A, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs, exportLIDs,
exporter.getDistributor(), DoForward);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
void DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::doImport(
const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & A,
const Export<LocalOrdinal,GlobalOrdinal,Node> & exporter,
CombineMode CM) {
TEST_FOR_EXCEPTION( getMap() != exporter.getSourceMap(), std::runtime_error, "Target Maps don't match.");
TEST_FOR_EXCEPTION( A.getMap() != exporter.getTargetMap(), std::runtime_error, "Source Maps don't match.");
size_t numSameIDs = exporter.getNumSameIDs();
Teuchos::ArrayView<const LocalOrdinal> exportLIDs = exporter.getRemoteLIDs();
Teuchos::ArrayView<const LocalOrdinal> remoteLIDs = exporter.getExportLIDs();
Teuchos::ArrayView<const LocalOrdinal> permuteToLIDs = exporter.getPermuteFromLIDs();
Teuchos::ArrayView<const LocalOrdinal> permuteFromLIDs = exporter.getPermuteToLIDs();
doTransfer(A, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs, exportLIDs,
exporter.getDistributor(), DoReverse);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
void DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::doExport(
const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & A,
const Import<LocalOrdinal,GlobalOrdinal,Node> & importer, CombineMode CM) {
TEST_FOR_EXCEPTION( getMap() != importer.getSourceMap(), std::runtime_error, "Target Maps don't match.");
TEST_FOR_EXCEPTION( A.getMap() != importer.getTargetMap(), std::runtime_error, "Source Maps don't match.");
size_t numSameIDs = importer.getNumSameIDs();
Teuchos::ArrayView<const LocalOrdinal> exportLIDs = importer.getRemoteLIDs();
Teuchos::ArrayView<const LocalOrdinal> remoteLIDs = importer.getExportLIDs();
Teuchos::ArrayView<const LocalOrdinal> permuteToLIDs = importer.getPermuteFromLIDs();
Teuchos::ArrayView<const LocalOrdinal> permuteFromLIDs = importer.getPermuteToLIDs();
doTransfer(A, CM, numSameIDs, permuteToLIDs, permuteFromLIDs, remoteLIDs, exportLIDs,
importer.getDistributor(), DoReverse);
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
bool DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::isDistributed() const {
return map_->isDistributed();
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
void DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::doTransfer(
const DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node> & source,
CombineMode CM,
size_t numSameIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &remoteLIDs,
const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
Distributor &distor, ReverseOption revOp)
{
TEST_FOR_EXCEPTION( checkSizes(source) == false, std::runtime_error,
"Tpetra::DistObject::doTransfer(): checkSizes() indicates that DistOjbects are not size-compatible.");
Kokkos::ReadWriteOption rwo = Kokkos::ReadWrite;
if (CM == INSERT || CM == REPLACE) {
if (numSameIDs + permuteToLIDs.size() + remoteLIDs.size() == this->getMap()->getNodeNumElements()) {
// we are overwriting, and everything will be overwritten
rwo = Kokkos::WriteOnly;
}
}
source.createViews();
this->createViewsNonConst(rwo);
if (numSameIDs + permuteToLIDs.size()) {
copyAndPermute(source,numSameIDs,permuteToLIDs,permuteFromLIDs);
}
size_t constantNumPackets = 0;
numExportPacketsPerLID_.resize(exportLIDs.size());
numImportPacketsPerLID_.resize(remoteLIDs.size());
packAndPrepare(source,exportLIDs,exports_,numExportPacketsPerLID_(),constantNumPackets,distor);
source.releaseViews();
if (constantNumPackets != 0) {
size_t rbufLen = remoteLIDs.size()*constantNumPackets;
imports_.resize(rbufLen);
}
if ((isDistributed() && revOp == DoReverse) || (source.isDistributed() && revOp == DoForward))
{
// call one of the doPostsAndWaits functions
if (revOp == DoReverse) {
if (constantNumPackets == 0) { //variable num-packets-per-LID:
distor.doReversePostsAndWaits(numExportPacketsPerLID_().getConst(), 1,
numImportPacketsPerLID_());
size_t totalImportPackets = 0;
for(Array_size_type i=0; i<numImportPacketsPerLID_.size(); ++i) {
totalImportPackets += numImportPacketsPerLID_[i];
}
imports_.resize(totalImportPackets);
distor.doReversePostsAndWaits(exports_().getConst(),numExportPacketsPerLID_(),
imports_(), numImportPacketsPerLID_());
}
else {
distor.doReversePostsAndWaits(exports_().getConst(),constantNumPackets,imports_());
}
}
else {
if (constantNumPackets == 0) { //variable num-packets-per-LID:
distor.doPostsAndWaits(numExportPacketsPerLID_().getConst(), 1,
numImportPacketsPerLID_());
size_t totalImportPackets = 0;
for(Array_size_type i=0; i<numImportPacketsPerLID_.size(); ++i) {
totalImportPackets += numImportPacketsPerLID_[i];
}
imports_.resize(totalImportPackets);
distor.doPostsAndWaits(exports_().getConst(),numExportPacketsPerLID_(),
imports_(), numImportPacketsPerLID_());
}
else {
distor.doPostsAndWaits(exports_().getConst(),constantNumPackets,imports_());
}
}
unpackAndCombine(remoteLIDs,imports_(),numImportPacketsPerLID_(), constantNumPackets, distor,CM);
}
this->releaseViews();
}
template <class Packet, class LocalOrdinal, class GlobalOrdinal, class Node>
void DistObject<Packet,LocalOrdinal,GlobalOrdinal,Node>::print(std::ostream &os) const
{
using std::endl;
os << "Tpetra::DistObject" << endl
<< " export buffer size: " << exports_.size() << endl
<< " import buffer size: " << imports_.size() << endl
<< "Map:" << endl
<< map_;
}
} // namespace Tpetra
#endif /* TPETRA_DISTOBJECT_HPP */
|