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)
39 :
Distributor(comm, Teuchos::null, Teuchos::null) {}
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)
53 : plan_(distributor.plan_)
54 , actor_(distributor.actor_)
55 , verbose_(distributor.verbose_)
56 , reverseDistributor_(distributor.reverseDistributor_) {
57 using Teuchos::ParameterList;
61 RCP<const ParameterList> rhsList = distributor.getParameterList();
62 RCP<ParameterList> newList = rhsList.is_null() ? Teuchos::null : Teuchos::parameterList(*rhsList);
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_);
78 RCP<ParameterList> lhsList = this->getNonconstParameterList();
79 RCP<ParameterList> rhsList = rhs.getNonconstParameterList();
80 if (lhsList.getRawPtr() == rhsList.getRawPtr() && !rhsList.is_null()) {
81 rhsList = parameterList(*rhsList);
83 if (!rhsList.is_null()) {
84 this->setMyParamList(rhsList);
86 if (!lhsList.is_null()) {
87 rhs.setMyParamList(lhsList);
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;
117 if (!plist.is_null()) {
119 plist->validateParametersAndSetDefaults(*validParams);
123 this->setMyParamList(plist);
125 RCP<ParameterList> planParams(plist);
126 planParams->remove(
"Debug",
false);
127 planParams->remove(
"VerboseObject",
false);
128 plan_->setParameterList(planParams);
132Teuchos::RCP<const Teuchos::ParameterList>
134 using Teuchos::Array;
135 using Teuchos::ParameterList;
136 using Teuchos::parameterList;
138 using Teuchos::setStringToIntegralParameter;
140 const bool debug = tpetraDistributorDebugDefault;
146 RCP<ParameterList> plist = parameterList(
"Tpetra::Distributor");
147 setStringToIntegralParameter<Details::EDistributorSendType>(
"Send type",
149 "When using MPI, the variant of send to use in "
150 "do[Reverse]Posts()",
151 sendTypes(), sendTypeEnums(), plist.getRawPtr());
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();
190 TEUCHOS_TEST_FOR_EXCEPTION(reverseDistributor_.is_null() && create, std::logic_error,
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 auto revPlan = plan_->getReversePlan();
200 reverseDistributor_->plan_ = revPlan;
201 reverseDistributor_->verbose_ = verbose_;
217 reverseDistributor_->reverseDistributor_ = Teuchos::null;
221 actor_.doWaits(*plan_);
226 if (!reverseDistributor_.is_null()) {
227 reverseDistributor_->doWaits();
232 std::ostringstream out;
234 out <<
"\"Tpetra::Distributor\": {";
235 const std::string label = this->getObjectLabel();
237 out <<
"Label: " << label <<
", ";
239 out <<
"How initialized: "
243 << DistributorSendTypeEnumToString(plan_->getSendType())
244 <<
", Debug: " << (verbose_ ?
"true" :
"false")
251 localDescribeToString(
const Teuchos::EVerbosityLevel vl)
const {
253 using Teuchos::toString;
254 using Teuchos::VERB_EXTREME;
255 using Teuchos::VERB_HIGH;
258 if (vl <= Teuchos::VERB_LOW || plan_->getComm().is_null()) {
259 return std::string();
262 auto outStringP = Teuchos::rcp(
new std::ostringstream());
263 auto outp = Teuchos::getFancyOStream(outStringP);
264 Teuchos::FancyOStream& out = *outp;
266 const int myRank = plan_->getComm()->getRank();
267 const int numProcs = plan_->getComm()->getSize();
268 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
269 Teuchos::OSTab tab1(out);
273 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
274 out <<
"procsTo: " << toString(plan_->getProcsTo()) << endl;
275 out <<
"lengthsTo: " << toString(plan_->getLengthsTo()) << endl;
278 if (vl == VERB_EXTREME) {
279 out <<
"startsTo: " << toString(plan_->getStartsTo()) << endl;
280 out <<
"indicesTo: " << toString(plan_->getIndicesTo()) << endl;
282 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
285 out <<
"lengthsFrom: " << toString(plan_->getLengthsFrom()) << endl;
286 out <<
"procsFrom: " << toString(plan_->getProcsFrom()) << endl;
290 return outStringP->str();
294 describe(Teuchos::FancyOStream& out,
295 const Teuchos::EVerbosityLevel verbLevel)
const {
297 using Teuchos::VERB_DEFAULT;
298 using Teuchos::VERB_EXTREME;
299 using Teuchos::VERB_HIGH;
300 using Teuchos::VERB_LOW;
301 using Teuchos::VERB_MEDIUM;
302 using Teuchos::VERB_NONE;
303 const Teuchos::EVerbosityLevel vl =
304 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
306 if (vl == VERB_NONE) {
314 if (plan_->getComm().is_null()) {
317 const int myRank = plan_->getComm()->getRank();
318 const int numProcs = plan_->getComm()->getSize();
327 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
333 tab0 = Teuchos::rcp(
new Teuchos::OSTab(out));
336 out <<
"\"Tpetra::Distributor\":" << endl;
337 tab1 = Teuchos::rcp(
new Teuchos::OSTab(out));
339 const std::string label = this->getObjectLabel();
341 out <<
"Label: " << label << endl;
343 out <<
"Number of processes: " << numProcs << endl
344 <<
"How initialized: "
348 out <<
"Parameters: " << endl;
349 Teuchos::OSTab tab2(out);
350 out <<
"\"Send type\": "
351 << DistributorSendTypeEnumToString(plan_->getSendType()) << endl
352 <<
"\"Debug\": " << (verbose_ ?
"true" :
"false") << endl;
358 const std::string lclStr = this->localDescribeToString(vl);
362 out <<
"Reverse Distributor:";
363 if (reverseDistributor_.is_null()) {
364 out <<
" null" << endl;
367 reverseDistributor_->describe(out, vl);
374 return plan_->createFromSends(exportProcIDs);
379 const Teuchos::ArrayView<const int>& remoteProcIDs) {
380 plan_->createFromSendsAndRecvs(exportProcIDs, remoteProcIDs);
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.
Description of Tpetra's behavior.
static bool verbose()
Whether Tpetra is in verbose mode.
static std::string defaultSendType()
Default send type.
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.