10 #include "Tpetra_Distributor.hpp"
14 #include "Tpetra_Details_makeValidVerboseStream.hpp"
15 #include "Teuchos_StandardParameterEntryValidators.hpp"
16 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
26 const bool tpetraDistributorDebugDefault =
false;
29 #if defined(TPETRA_ENABLE_DEPRECATED_CODE)
30 Teuchos::Array<std::string>
37 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
38 const Teuchos::RCP<Teuchos::FancyOStream>& ,
39 const Teuchos::RCP<Teuchos::ParameterList>& plist)
45 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
46 :
Distributor(comm, Teuchos::null, Teuchos::null) {}
49 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
50 const Teuchos::RCP<Teuchos::FancyOStream>& out)
54 Distributor(
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
55 const Teuchos::RCP<Teuchos::ParameterList>& plist)
60 : plan_(distributor.plan_)
61 , actor_(distributor.actor_)
62 , verbose_(distributor.verbose_)
63 , reverseDistributor_(distributor.reverseDistributor_) {
64 using Teuchos::ParameterList;
68 RCP<const ParameterList> rhsList = distributor.getParameterList();
69 RCP<ParameterList> newList = rhsList.is_null() ? Teuchos::null : Teuchos::parameterList(*rhsList);
74 using Teuchos::ParameterList;
75 using Teuchos::parameterList;
78 std::swap(plan_, rhs.plan_);
79 std::swap(actor_, rhs.actor_);
80 std::swap(verbose_, rhs.verbose_);
81 std::swap(reverseDistributor_, rhs.reverseDistributor_);
85 RCP<ParameterList> lhsList = this->getNonconstParameterList();
86 RCP<ParameterList> rhsList = rhs.getNonconstParameterList();
87 if (lhsList.getRawPtr() == rhsList.getRawPtr() && !rhsList.is_null()) {
88 rhsList = parameterList(*rhsList);
90 if (!rhsList.is_null()) {
91 this->setMyParamList(rhsList);
93 if (!lhsList.is_null()) {
94 rhs.setMyParamList(lhsList);
101 bool Distributor::getVerbose() {
106 std::unique_ptr<std::string>
108 createPrefix(
const char methodName[])
const {
110 plan_.getComm().getRawPtr(),
"Distributor", methodName);
116 using Teuchos::FancyOStream;
117 using Teuchos::getIntegralValue;
118 using Teuchos::includesVerbLevel;
119 using Teuchos::ParameterList;
120 using Teuchos::parameterList;
122 using ::Tpetra::Details::Behavior;
124 if (!plist.is_null()) {
126 plist->validateParametersAndSetDefaults(*validParams);
130 this->setMyParamList(plist);
132 RCP<ParameterList> planParams(plist);
133 planParams->remove(
"Debug",
false);
134 planParams->remove(
"VerboseObject",
false);
135 plan_.setParameterList(planParams);
139 Teuchos::RCP<const Teuchos::ParameterList>
141 using Teuchos::Array;
142 using Teuchos::ParameterList;
143 using Teuchos::parameterList;
145 using Teuchos::setStringToIntegralParameter;
147 const bool debug = tpetraDistributorDebugDefault;
153 RCP<ParameterList> plist = parameterList(
"Tpetra::Distributor");
154 setStringToIntegralParameter<Details::EDistributorSendType>(
"Send type",
156 "When using MPI, the variant of send to use in "
157 "do[Reverse]Posts()",
158 sendTypes(), sendTypeEnums(), plist.getRawPtr());
159 plist->set(
"Debug", debug,
160 "Whether to print copious debugging output on "
162 plist->set(
"Timer Label",
"",
"Label for Time Monitor output");
170 Teuchos::setupVerboseObjectSublist(&*plist);
171 return Teuchos::rcp_const_cast<
const ParameterList>(plist);
192 Teuchos::RCP<Distributor>
194 if (reverseDistributor_.is_null() && create) {
195 createReverseDistributor();
197 TEUCHOS_TEST_FOR_EXCEPTION(reverseDistributor_.is_null() && create, std::logic_error,
199 "Distributor is null after createReverseDistributor returned. "
200 "Please report this bug to the Tpetra developers.");
201 return reverseDistributor_;
204 void Distributor::createReverseDistributor()
const {
205 reverseDistributor_ = Teuchos::rcp(
new Distributor(plan_.getComm()));
206 reverseDistributor_->plan_ = *plan_.getReversePlan();
207 reverseDistributor_->verbose_ = verbose_;
223 reverseDistributor_->reverseDistributor_ = Teuchos::null;
227 actor_.doWaits(plan_);
232 if (!reverseDistributor_.is_null()) {
233 reverseDistributor_->doWaits();
238 std::ostringstream out;
240 out <<
"\"Tpetra::Distributor\": {";
241 const std::string label = this->getObjectLabel();
243 out <<
"Label: " << label <<
", ";
245 out <<
"How initialized: "
249 << DistributorSendTypeEnumToString(plan_.getSendType())
250 <<
", Debug: " << (verbose_ ?
"true" :
"false")
257 localDescribeToString(
const Teuchos::EVerbosityLevel vl)
const {
259 using Teuchos::toString;
260 using Teuchos::VERB_EXTREME;
261 using Teuchos::VERB_HIGH;
264 if (vl <= Teuchos::VERB_LOW || plan_.getComm().is_null()) {
265 return std::string();
268 auto outStringP = Teuchos::rcp(
new std::ostringstream());
269 auto outp = Teuchos::getFancyOStream(outStringP);
270 Teuchos::FancyOStream& out = *outp;
272 const int myRank = plan_.getComm()->getRank();
273 const int numProcs = plan_.getComm()->getSize();
274 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
275 Teuchos::OSTab tab1(out);
279 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
280 out <<
"procsTo: " << toString(plan_.getProcsTo()) << endl;
281 out <<
"lengthsTo: " << toString(plan_.getLengthsTo()) << endl;
284 if (vl == VERB_EXTREME) {
285 out <<
"startsTo: " << toString(plan_.getStartsTo()) << endl;
286 out <<
"indicesTo: " << toString(plan_.getIndicesTo()) << endl;
288 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
291 out <<
"lengthsFrom: " << toString(plan_.getLengthsFrom()) << endl;
292 out <<
"procsFrom: " << toString(plan_.getProcsFrom()) << endl;
296 return outStringP->str();
301 const Teuchos::EVerbosityLevel verbLevel)
const {
303 using Teuchos::VERB_DEFAULT;
304 using Teuchos::VERB_EXTREME;
305 using Teuchos::VERB_HIGH;
306 using Teuchos::VERB_LOW;
307 using Teuchos::VERB_MEDIUM;
308 using Teuchos::VERB_NONE;
309 const Teuchos::EVerbosityLevel vl =
310 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
312 if (vl == VERB_NONE) {
320 if (plan_.getComm().is_null()) {
323 const int myRank = plan_.getComm()->getRank();
324 const int numProcs = plan_.getComm()->getSize();
333 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
339 tab0 = Teuchos::rcp(
new Teuchos::OSTab(out));
342 out <<
"\"Tpetra::Distributor\":" << endl;
343 tab1 = Teuchos::rcp(
new Teuchos::OSTab(out));
345 const std::string label = this->getObjectLabel();
347 out <<
"Label: " << label << endl;
349 out <<
"Number of processes: " << numProcs << endl
350 <<
"How initialized: "
354 out <<
"Parameters: " << endl;
355 Teuchos::OSTab tab2(out);
356 out <<
"\"Send type\": "
357 << DistributorSendTypeEnumToString(plan_.getSendType()) << endl
358 <<
"\"Debug\": " << (verbose_ ?
"true" :
"false") << endl;
364 const std::string lclStr = this->localDescribeToString(vl);
368 out <<
"Reverse Distributor:";
369 if (reverseDistributor_.is_null()) {
370 out <<
" null" << endl;
373 reverseDistributor_->describe(out, vl);
380 return plan_.createFromSends(exportProcIDs);
385 const Teuchos::ArrayView<const int>& remoteProcIDs) {
386 plan_.createFromSendsAndRecvs(exportProcIDs, remoteProcIDs);
size_t getNumReceives() const
The number of processes from which we will receive data.
std::string description() const
Return a one-line description of this object.
Teuchos::RCP< Distributor > getReverse(bool create=true) const
A reverse communication plan Distributor.
Declaration of a function that prints strings from each process.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
List of valid Distributor parameters.
const std::string & validSendTypeOrThrow(const std::string &s)
Valid enum values of distributor send types.
void swap(Distributor &rhs)
Swap the contents of rhs with those of *this.
Teuchos::ArrayView< const size_t > getLengthsFrom() const
Number of values this process will receive from each process.
Teuchos::ArrayView< const int > getProcsFrom() const
Ranks of the processes sending values to this process.
size_t createFromSends(const Teuchos::ArrayView< const int > &exportProcIDs)
Set up Distributor using list of process ranks to which this process will send.
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, in rank order.
Teuchos::Array< EDistributorSendType > distributorSendTypeEnums()
Valid enum values of distributor send types.
Teuchos::ArrayView< const int > getProcsTo() const
Ranks of the processes to which this process will send values.
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...
bool hasSelfMessage() const
Whether the calling process will send or receive messages to itself.
Sets up and executes a communication plan for a Tpetra DistObject.
static bool verbose()
Whether Tpetra is in verbose mode.
size_t getTotalReceiveLength() const
Total number of values this process will receive from other processes.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set Distributor parameters.
Teuchos::ArrayView< const size_t > getLengthsTo() const
Number of values this process will send to each process.
std::string DistributorHowInitializedEnumToString(EDistributorHowInitialized how)
Convert an EDistributorHowInitialized enum value to a string.
Stand-alone utility functions and macros.
Teuchos::Array< std::string > distributorSendTypes()
Valid string values for Distributor's "Send type" parameter.
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.
size_t getMaxSendLength() const
Maximum number of values this process will send to another single process.
static std::string defaultSendType()
Default send type.
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
Distributor(const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Construct using the specified communicator and default parameters.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.