10#include "Tpetra_Distributor.hpp"
14#include "Tpetra_Details_makeValidVerboseStream.hpp"
15#include "Teuchos_StandardParameterEntryValidators.hpp"
16#include "Teuchos_VerboseObjectParameterListHelpers.hpp"
26const bool tpetraDistributorDebugDefault =
false;
30 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
31 const Teuchos::RCP<Teuchos::FancyOStream>& ,
32 const Teuchos::RCP<Teuchos::ParameterList>&
plist)
38 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
42 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
43 const Teuchos::RCP<Teuchos::FancyOStream>&
out)
47 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
48 const Teuchos::RCP<Teuchos::ParameterList>&
plist)
56 , reverseDistributor_(
distributor.reverseDistributor_) {
57 using Teuchos::ParameterList;
67 using Teuchos::ParameterList;
68 using Teuchos::parameterList;
71 std::swap(plan_,
rhs.plan_);
72 std::swap(actor_,
rhs.actor_);
73 std::swap(verbose_,
rhs.verbose_);
74 std::swap(reverseDistributor_,
rhs.reverseDistributor_);
94bool Distributor::getVerbose() {
99std::unique_ptr<std::string>
101 createPrefix(
const char methodName[])
const {
103 plan_.getComm().getRawPtr(),
"Distributor", methodName);
109 using Teuchos::FancyOStream;
110 using Teuchos::getIntegralValue;
111 using Teuchos::includesVerbLevel;
112 using Teuchos::ParameterList;
113 using Teuchos::parameterList;
115 using ::Tpetra::Details::Behavior;
117 if (!
plist.is_null()) {
132Teuchos::RCP<const Teuchos::ParameterList>
134 using Teuchos::Array;
135 using Teuchos::ParameterList;
136 using Teuchos::parameterList;
138 using Teuchos::setStringToIntegralParameter;
149 "When using MPI, the variant of send to use in "
150 "do[Reverse]Posts()",
152 plist->set(
"Debug", debug,
153 "Whether to print copious debugging output on "
155 plist->set(
"Timer Label",
"",
"Label for Time Monitor output");
163 Teuchos::setupVerboseObjectSublist(&*
plist);
164 return Teuchos::rcp_const_cast<const ParameterList>(
plist);
185Teuchos::RCP<Distributor>
187 if (reverseDistributor_.is_null() &&
create) {
188 createReverseDistributor();
192 "Distributor is null after createReverseDistributor returned. "
193 "Please report this bug to the Tpetra developers.");
194 return reverseDistributor_;
197void Distributor::createReverseDistributor()
const {
198 reverseDistributor_ = Teuchos::rcp(
new Distributor(plan_.getComm()));
199 reverseDistributor_->plan_ = *plan_.getReversePlan();
200 reverseDistributor_->verbose_ = verbose_;
216 reverseDistributor_->reverseDistributor_ = Teuchos::null;
220 actor_.doWaits(plan_);
225 if (!reverseDistributor_.is_null()) {
226 reverseDistributor_->doWaits();
231 std::ostringstream
out;
233 out <<
"\"Tpetra::Distributor\": {";
236 out <<
"Label: " << label <<
", ";
238 out <<
"How initialized: "
242 << DistributorSendTypeEnumToString(plan_.getSendType())
243 <<
", Debug: " << (verbose_ ?
"true" :
"false")
250 localDescribeToString(
const Teuchos::EVerbosityLevel
vl)
const {
252 using Teuchos::toString;
253 using Teuchos::VERB_EXTREME;
254 using Teuchos::VERB_HIGH;
257 if (
vl <= Teuchos::VERB_LOW || plan_.getComm().is_null()) {
258 return std::string();
261 auto outStringP = Teuchos::rcp(
new std::ostringstream());
262 auto outp = Teuchos::getFancyOStream(outStringP);
263 Teuchos::FancyOStream& out = *outp;
265 const int myRank = plan_.getComm()->getRank();
266 const int numProcs = plan_.getComm()->getSize();
267 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
268 Teuchos::OSTab tab1(out);
272 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
273 out <<
"procsTo: " << toString(plan_.getProcsTo()) << endl;
274 out <<
"lengthsTo: " << toString(plan_.getLengthsTo()) << endl;
277 if (vl == VERB_EXTREME) {
278 out <<
"startsTo: " << toString(plan_.getStartsTo()) << endl;
279 out <<
"indicesTo: " << toString(plan_.getIndicesTo()) << endl;
281 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
284 out <<
"lengthsFrom: " << toString(plan_.getLengthsFrom()) << endl;
285 out <<
"procsFrom: " << toString(plan_.getProcsFrom()) << endl;
289 return outStringP->str();
294 const Teuchos::EVerbosityLevel
verbLevel)
const {
296 using Teuchos::VERB_DEFAULT;
297 using Teuchos::VERB_EXTREME;
298 using Teuchos::VERB_HIGH;
299 using Teuchos::VERB_LOW;
300 using Teuchos::VERB_MEDIUM;
301 using Teuchos::VERB_NONE;
302 const Teuchos::EVerbosityLevel
vl =
313 if (plan_.getComm().is_null()) {
316 const int myRank = plan_.getComm()->getRank();
317 const int numProcs = plan_.getComm()->getSize();
326 Teuchos::RCP<Teuchos::OSTab>
tab0,
tab1;
332 tab0 = Teuchos::rcp(
new Teuchos::OSTab(
out));
335 out <<
"\"Tpetra::Distributor\":" <<
endl;
336 tab1 = Teuchos::rcp(
new Teuchos::OSTab(
out));
340 out <<
"Label: " << label <<
endl;
343 <<
"How initialized: "
349 out <<
"\"Send type\": "
350 << DistributorSendTypeEnumToString(plan_.getSendType()) <<
endl
351 <<
"\"Debug\": " << (verbose_ ?
"true" :
"false") <<
endl;
357 const std::string
lclStr = this->localDescribeToString(
vl);
361 out <<
"Reverse Distributor:";
362 if (reverseDistributor_.is_null()) {
366 reverseDistributor_->describe(
out,
vl);
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of a function that prints strings from each process.
Stand-alone utility functions and macros.
Struct that holds views of the contents of a CrsMatrix.
static bool verbose()
Whether Tpetra is in verbose mode.
static std::string defaultSendType()
Default send type.
Sets up and executes a communication plan for a Tpetra DistObject.
size_t getMaxSendLength() const
Maximum number of values this process will send to another single process.
Teuchos::RCP< Distributor > getReverse(bool create=true) const
A reverse communication plan Distributor.
Teuchos::ArrayView< const int > getProcsTo() const
Ranks of the processes to which this process will send values.
size_t getNumReceives() const
The number of processes from which we will receive data.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set Distributor parameters.
size_t getTotalReceiveLength() const
Total number of values this process will receive from other processes.
bool hasSelfMessage() const
Whether the calling process will send or receive messages to itself.
void swap(Distributor &rhs)
Swap the contents of rhs with those of *this.
Teuchos::ArrayView< const size_t > getLengthsTo() const
Number of values this process will send to each process.
Teuchos::ArrayView< const int > getProcsFrom() const
Ranks of the processes sending values to this process.
Distributor(const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Construct using the specified communicator and default parameters.
std::string description() const
Return a one-line description of this object.
size_t createFromSends(const Teuchos::ArrayView< const int > &exportProcIDs)
Set up Distributor using list of process ranks to which this process will send.
void createFromSendsAndRecvs(const Teuchos::ArrayView< const int > &exportProcIDs, const Teuchos::ArrayView< const int > &remoteProcIDs)
Set up Distributor using list of process ranks to which to send, and list of process ranks from which...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
List of valid Distributor parameters.
Teuchos::ArrayView< const size_t > getLengthsFrom() const
Number of values this process will receive from each process.
size_t getNumSends() const
The number of processes to which we will send data.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object in a human-readable way to the given output stream.
Teuchos::Array< EDistributorSendType > distributorSendTypeEnums()
Valid enum values of distributor send types.
Teuchos::Array< std::string > distributorSendTypes()
Valid string values for Distributor's "Send type" parameter.
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
const std::string & validSendTypeOrThrow(const std::string &s)
Valid enum values of distributor send types.
std::string DistributorHowInitializedEnumToString(EDistributorHowInitialized how)
Convert an EDistributorHowInitialized enum value to a string.
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator,...
Namespace Tpetra contains the class and methods constituting the Tpetra library.