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>
38 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
39 const Teuchos::RCP<Teuchos::FancyOStream>& ,
40 const Teuchos::RCP<Teuchos::ParameterList>& plist)
47 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
52 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
53 const Teuchos::RCP<Teuchos::FancyOStream>& out)
58 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
59 const Teuchos::RCP<Teuchos::ParameterList>& plist)
65 : plan_(distributor.plan_)
66 , actor_(distributor.actor_)
67 , verbose_ (distributor.verbose_)
68 , reverseDistributor_ (distributor.reverseDistributor_)
70 using Teuchos::ParameterList;
74 RCP<const ParameterList> rhsList = distributor.getParameterList ();
75 RCP<ParameterList> newList = rhsList.is_null () ? Teuchos::null :
76 Teuchos::parameterList (*rhsList);
81 using Teuchos::ParameterList;
82 using Teuchos::parameterList;
85 std::swap (plan_, rhs.plan_);
86 std::swap (actor_, rhs.actor_);
87 std::swap (verbose_, rhs.verbose_);
88 std::swap (reverseDistributor_, rhs.reverseDistributor_);
92 RCP<ParameterList> lhsList = this->getNonconstParameterList ();
93 RCP<ParameterList> rhsList = rhs.getNonconstParameterList ();
94 if (lhsList.getRawPtr () == rhsList.getRawPtr () && ! rhsList.is_null ()) {
95 rhsList = parameterList (*rhsList);
97 if (! rhsList.is_null ()) {
98 this->setMyParamList (rhsList);
100 if (! lhsList.is_null ()) {
101 rhs.setMyParamList (lhsList);
109 Distributor::getVerbose()
115 std::unique_ptr<std::string>
117 createPrefix(
const char methodName[])
const
120 plan_.getComm().getRawPtr(),
"Distributor", methodName);
127 using ::Tpetra::Details::Behavior;
128 using Teuchos::FancyOStream;
129 using Teuchos::getIntegralValue;
130 using Teuchos::includesVerbLevel;
131 using Teuchos::ParameterList;
132 using Teuchos::parameterList;
136 if (! plist.is_null()) {
138 plist->validateParametersAndSetDefaults (*validParams);
142 this->setMyParamList (plist);
144 RCP<ParameterList> planParams(plist);
145 planParams->remove(
"Debug",
false);
146 planParams->remove(
"VerboseObject",
false);
147 plan_.setParameterList(planParams);
151 Teuchos::RCP<const Teuchos::ParameterList>
154 using Teuchos::Array;
155 using Teuchos::ParameterList;
156 using Teuchos::parameterList;
158 using Teuchos::setStringToIntegralParameter;
160 const bool debug = tpetraDistributorDebugDefault;
165 RCP<ParameterList> plist = parameterList (
"Tpetra::Distributor");
166 setStringToIntegralParameter<Details::EDistributorSendType> (
"Send type",
168 "do[Reverse]Posts()", sendTypes(), sendTypeEnums(), plist.getRawPtr());
169 plist->set (
"Debug", debug,
"Whether to print copious debugging output on "
171 plist->set (
"Timer Label",
"",
"Label for Time Monitor output");
179 Teuchos::setupVerboseObjectSublist (&*plist);
180 return Teuchos::rcp_const_cast<
const ParameterList> (plist);
185 {
return plan_.getTotalReceiveLength(); }
188 {
return plan_.getNumReceives(); }
191 {
return plan_.hasSelfMessage(); }
194 {
return plan_.getNumSends(); }
197 {
return plan_.getMaxSendLength(); }
200 {
return plan_.getProcsFrom(); }
203 {
return plan_.getLengthsFrom(); }
206 {
return plan_.getProcsTo(); }
209 {
return plan_.getLengthsTo(); }
211 Teuchos::RCP<Distributor>
213 if (reverseDistributor_.is_null () && create) {
214 createReverseDistributor ();
216 TEUCHOS_TEST_FOR_EXCEPTION
217 (reverseDistributor_.is_null () && create, std::logic_error,
"The reverse "
218 "Distributor is null after createReverseDistributor returned. "
219 "Please report this bug to the Tpetra developers.");
220 return reverseDistributor_;
225 Distributor::createReverseDistributor()
const
227 reverseDistributor_ = Teuchos::rcp(
new Distributor(plan_.getComm()));
228 reverseDistributor_->plan_ = *plan_.getReversePlan();
229 reverseDistributor_->verbose_ = verbose_;
245 reverseDistributor_->reverseDistributor_ = Teuchos::null;
251 actor_.doWaits(plan_);
256 if (! reverseDistributor_.is_null()) {
257 reverseDistributor_->doWaits();
262 std::ostringstream out;
264 out <<
"\"Tpetra::Distributor\": {";
265 const std::string label = this->getObjectLabel ();
267 out <<
"Label: " << label <<
", ";
269 out <<
"How initialized: "
273 << DistributorSendTypeEnumToString (plan_.getSendType())
274 <<
", Debug: " << (verbose_ ?
"true" :
"false")
281 localDescribeToString (
const Teuchos::EVerbosityLevel vl)
const
283 using Teuchos::toString;
284 using Teuchos::VERB_HIGH;
285 using Teuchos::VERB_EXTREME;
289 if (vl <= Teuchos::VERB_LOW || plan_.getComm().is_null ()) {
290 return std::string ();
293 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
294 auto outp = Teuchos::getFancyOStream (outStringP);
295 Teuchos::FancyOStream& out = *outp;
297 const int myRank = plan_.getComm()->getRank ();
298 const int numProcs = plan_.getComm()->getSize ();
299 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
300 Teuchos::OSTab tab1 (out);
304 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
305 out <<
"procsTo: " << toString (plan_.getProcsTo()) << endl;
306 out <<
"lengthsTo: " << toString (plan_.getLengthsTo()) << endl;
309 if (vl == VERB_EXTREME) {
310 out <<
"startsTo: " << toString (plan_.getStartsTo()) << endl;
311 out <<
"indicesTo: " << toString (plan_.getIndicesTo()) << endl;
313 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
316 out <<
"lengthsFrom: " << toString (plan_.getLengthsFrom()) << endl;
317 out <<
"procsFrom: " << toString (plan_.getProcsFrom()) << endl;
321 return outStringP->str ();
327 const Teuchos::EVerbosityLevel verbLevel)
const
330 using Teuchos::VERB_DEFAULT;
331 using Teuchos::VERB_NONE;
332 using Teuchos::VERB_LOW;
333 using Teuchos::VERB_MEDIUM;
334 using Teuchos::VERB_HIGH;
335 using Teuchos::VERB_EXTREME;
336 const Teuchos::EVerbosityLevel vl =
337 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
339 if (vl == VERB_NONE) {
347 if (plan_.getComm().is_null ()) {
350 const int myRank = plan_.getComm()->getRank ();
351 const int numProcs = plan_.getComm()->getSize ();
360 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
366 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
369 out <<
"\"Tpetra::Distributor\":" << endl;
370 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
372 const std::string label = this->getObjectLabel ();
374 out <<
"Label: " << label << endl;
376 out <<
"Number of processes: " << numProcs << endl
377 <<
"How initialized: "
381 out <<
"Parameters: " << endl;
382 Teuchos::OSTab tab2 (out);
383 out <<
"\"Send type\": "
384 << DistributorSendTypeEnumToString (plan_.getSendType()) << endl
385 <<
"\"Debug\": " << (verbose_ ?
"true" :
"false") << endl;
391 const std::string lclStr = this->localDescribeToString (vl);
395 out <<
"Reverse Distributor:";
396 if (reverseDistributor_.is_null ()) {
397 out <<
" null" << endl;
401 reverseDistributor_->describe (out, vl);
409 return plan_.createFromSends(exportProcIDs);
415 const Teuchos::ArrayView<const int>& remoteProcIDs)
417 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.
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.