39#include "Tpetra_Distributor.hpp"
43#include "Tpetra_Details_makeValidVerboseStream.hpp"
44#include "Teuchos_StandardParameterEntryValidators.hpp"
45#include "Teuchos_VerboseObjectParameterListHelpers.hpp"
55 const bool tpetraDistributorDebugDefault =
false;
58 Teuchos::Array<std::string>
61 Teuchos::Array<std::string> sendTypes;
62 sendTypes.push_back (
"Isend");
63 sendTypes.push_back (
"Send");
64 sendTypes.push_back (
"Alltoall");
69 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
70 const Teuchos::RCP<Teuchos::FancyOStream>& ,
71 const Teuchos::RCP<Teuchos::ParameterList>& plist)
78 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
83 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
84 const Teuchos::RCP<Teuchos::FancyOStream>& out)
89 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
90 const Teuchos::RCP<Teuchos::ParameterList>& plist)
96 : plan_(distributor.plan_)
97 , actor_(distributor.actor_)
98 , verbose_ (distributor.verbose_)
99 , reverseDistributor_ (distributor.reverseDistributor_)
101 using Teuchos::ParameterList;
105 RCP<const ParameterList> rhsList = distributor.getParameterList ();
106 RCP<ParameterList> newList = rhsList.is_null () ? Teuchos::null :
107 Teuchos::parameterList (*rhsList);
112 using Teuchos::ParameterList;
113 using Teuchos::parameterList;
116 std::swap (plan_, rhs.plan_);
117 std::swap (actor_, rhs.actor_);
118 std::swap (verbose_, rhs.verbose_);
119 std::swap (reverseDistributor_, rhs.reverseDistributor_);
123 RCP<ParameterList> lhsList = this->getNonconstParameterList ();
124 RCP<ParameterList> rhsList = rhs.getNonconstParameterList ();
125 if (lhsList.getRawPtr () == rhsList.getRawPtr () && ! rhsList.is_null ()) {
126 rhsList = parameterList (*rhsList);
128 if (! rhsList.is_null ()) {
129 this->setMyParamList (rhsList);
131 if (! lhsList.is_null ()) {
132 rhs.setMyParamList (lhsList);
140 Distributor::getVerbose()
146 std::unique_ptr<std::string>
148 createPrefix(
const char methodName[])
const
151 plan_.getComm().getRawPtr(),
"Distributor", methodName);
158 using ::Tpetra::Details::Behavior;
159 using Teuchos::FancyOStream;
160 using Teuchos::getIntegralValue;
161 using Teuchos::includesVerbLevel;
162 using Teuchos::ParameterList;
163 using Teuchos::parameterList;
167 if (! plist.is_null()) {
169 plist->validateParametersAndSetDefaults (*validParams);
173 this->setMyParamList (plist);
175 RCP<ParameterList> planParams(plist);
176 planParams->remove(
"Debug",
false);
177 planParams->remove(
"VerboseObject",
false);
178 plan_.setParameterList(planParams);
182 Teuchos::RCP<const Teuchos::ParameterList>
185 using Teuchos::Array;
186 using Teuchos::ParameterList;
187 using Teuchos::parameterList;
189 using Teuchos::setStringToIntegralParameter;
191 const bool debug = tpetraDistributorDebugDefault;
194 const std::string defaultSendType (
"Send");
195 Array<Details::EDistributorSendType> sendTypeEnums;
196 sendTypeEnums.push_back (Details::DISTRIBUTOR_ISEND);
197 sendTypeEnums.push_back (Details::DISTRIBUTOR_SEND);
198 sendTypeEnums.push_back (Details::DISTRIBUTOR_ALLTOALL);
200 RCP<ParameterList> plist = parameterList (
"Tpetra::Distributor");
201 setStringToIntegralParameter<Details::EDistributorSendType> (
"Send type",
202 defaultSendType,
"When using MPI, the variant of send to use in "
203 "do[Reverse]Posts()", sendTypes(), sendTypeEnums(), plist.getRawPtr());
204 plist->set (
"Debug", debug,
"Whether to print copious debugging output on "
206 plist->set (
"Timer Label",
"",
"Label for Time Monitor output");
214 Teuchos::setupVerboseObjectSublist (&*plist);
215 return Teuchos::rcp_const_cast<const ParameterList> (plist);
220 {
return plan_.getTotalReceiveLength(); }
223 {
return plan_.getNumReceives(); }
226 {
return plan_.hasSelfMessage(); }
229 {
return plan_.getNumSends(); }
232 {
return plan_.getMaxSendLength(); }
235 {
return plan_.getProcsFrom(); }
238 {
return plan_.getLengthsFrom(); }
241 {
return plan_.getProcsTo(); }
244 {
return plan_.getLengthsTo(); }
246 Teuchos::RCP<Distributor>
248 if (reverseDistributor_.is_null () && create) {
249 createReverseDistributor ();
251 TEUCHOS_TEST_FOR_EXCEPTION
252 (reverseDistributor_.is_null () && create, std::logic_error,
"The reverse "
253 "Distributor is null after createReverseDistributor returned. "
254 "Please report this bug to the Tpetra developers.");
255 return reverseDistributor_;
260 Distributor::createReverseDistributor()
const
262 reverseDistributor_ = Teuchos::rcp(
new Distributor(plan_.getComm()));
263 reverseDistributor_->plan_ = *plan_.getReversePlan();
264 reverseDistributor_->verbose_ = verbose_;
280 reverseDistributor_->reverseDistributor_ = Teuchos::null;
286 actor_.doWaits(plan_);
291 if (! reverseDistributor_.is_null()) {
292 reverseDistributor_->doWaits();
297 std::ostringstream out;
299 out <<
"\"Tpetra::Distributor\": {";
300 const std::string label = this->getObjectLabel ();
302 out <<
"Label: " << label <<
", ";
304 out <<
"How initialized: "
308 << DistributorSendTypeEnumToString (plan_.getSendType())
309 <<
", Debug: " << (verbose_ ?
"true" :
"false")
316 localDescribeToString (
const Teuchos::EVerbosityLevel vl)
const
318 using Teuchos::toString;
319 using Teuchos::VERB_HIGH;
320 using Teuchos::VERB_EXTREME;
324 if (vl <= Teuchos::VERB_LOW || plan_.getComm().is_null ()) {
325 return std::string ();
328 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
329 auto outp = Teuchos::getFancyOStream (outStringP);
330 Teuchos::FancyOStream& out = *outp;
332 const int myRank = plan_.getComm()->getRank ();
333 const int numProcs = plan_.getComm()->getSize ();
334 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
335 Teuchos::OSTab tab1 (out);
339 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
340 out <<
"procsTo: " << toString (plan_.getProcsTo()) << endl;
341 out <<
"lengthsTo: " << toString (plan_.getLengthsTo()) << endl;
344 if (vl == VERB_EXTREME) {
345 out <<
"startsTo: " << toString (plan_.getStartsTo()) << endl;
346 out <<
"indicesTo: " << toString (plan_.getIndicesTo()) << endl;
348 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
351 out <<
"lengthsFrom: " << toString (plan_.getLengthsFrom()) << endl;
352 out <<
"procsFrom: " << toString (plan_.getProcsFrom()) << endl;
356 return outStringP->str ();
361 describe (Teuchos::FancyOStream& out,
362 const Teuchos::EVerbosityLevel verbLevel)
const
365 using Teuchos::VERB_DEFAULT;
366 using Teuchos::VERB_NONE;
367 using Teuchos::VERB_LOW;
368 using Teuchos::VERB_MEDIUM;
369 using Teuchos::VERB_HIGH;
370 using Teuchos::VERB_EXTREME;
371 const Teuchos::EVerbosityLevel vl =
372 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
374 if (vl == VERB_NONE) {
382 if (plan_.getComm().is_null ()) {
385 const int myRank = plan_.getComm()->getRank ();
386 const int numProcs = plan_.getComm()->getSize ();
395 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
401 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
404 out <<
"\"Tpetra::Distributor\":" << endl;
405 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
407 const std::string label = this->getObjectLabel ();
409 out <<
"Label: " << label << endl;
411 out <<
"Number of processes: " << numProcs << endl
412 <<
"How initialized: "
416 out <<
"Parameters: " << endl;
417 Teuchos::OSTab tab2 (out);
418 out <<
"\"Send type\": "
419 << DistributorSendTypeEnumToString (plan_.getSendType()) << endl
420 <<
"\"Debug\": " << (verbose_ ?
"true" :
"false") << endl;
426 const std::string lclStr = this->localDescribeToString (vl);
430 out <<
"Reverse Distributor:";
431 if (reverseDistributor_.is_null ()) {
432 out <<
" null" << endl;
436 reverseDistributor_->describe (out, vl);
444 return plan_.createFromSends(exportProcIDs);
450 const Teuchos::ArrayView<const int>& remoteProcIDs)
452 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.
static bool verbose()
Whether Tpetra is in verbose mode.
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.
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
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.
Teuchos::Array< std::string > distributorSendTypes()
Valid values for Distributor's "Send type" parameter.