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 Teuchos::Array<std::string>
32 Teuchos::Array<std::string> sendTypes;
33 sendTypes.push_back (
"Isend");
34 sendTypes.push_back (
"Send");
35 sendTypes.push_back (
"Alltoall");
36#if defined(HAVE_TPETRACORE_MPI_ADVANCE)
37 sendTypes.push_back (
"MpiAdvanceAlltoall");
38 sendTypes.push_back (
"MpiAdvanceNbralltoallv");
44 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
45 const Teuchos::RCP<Teuchos::FancyOStream>& ,
46 const Teuchos::RCP<Teuchos::ParameterList>& plist)
53 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
58 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
59 const Teuchos::RCP<Teuchos::FancyOStream>& out)
64 Distributor (
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
65 const Teuchos::RCP<Teuchos::ParameterList>& plist)
71 : plan_(distributor.plan_)
72 , actor_(distributor.actor_)
73 , verbose_ (distributor.verbose_)
74 , reverseDistributor_ (distributor.reverseDistributor_)
76 using Teuchos::ParameterList;
80 RCP<const ParameterList> rhsList = distributor.getParameterList ();
81 RCP<ParameterList> newList = rhsList.is_null () ? Teuchos::null :
82 Teuchos::parameterList (*rhsList);
87 using Teuchos::ParameterList;
88 using Teuchos::parameterList;
91 std::swap (plan_, rhs.plan_);
92 std::swap (actor_, rhs.actor_);
93 std::swap (verbose_, rhs.verbose_);
94 std::swap (reverseDistributor_, rhs.reverseDistributor_);
98 RCP<ParameterList> lhsList = this->getNonconstParameterList ();
99 RCP<ParameterList> rhsList = rhs.getNonconstParameterList ();
100 if (lhsList.getRawPtr () == rhsList.getRawPtr () && ! rhsList.is_null ()) {
101 rhsList = parameterList (*rhsList);
103 if (! rhsList.is_null ()) {
104 this->setMyParamList (rhsList);
106 if (! lhsList.is_null ()) {
107 rhs.setMyParamList (lhsList);
115 Distributor::getVerbose()
121 std::unique_ptr<std::string>
123 createPrefix(
const char methodName[])
const
126 plan_.getComm().getRawPtr(),
"Distributor", methodName);
134 using Teuchos::FancyOStream;
135 using Teuchos::getIntegralValue;
136 using Teuchos::includesVerbLevel;
137 using Teuchos::ParameterList;
138 using Teuchos::parameterList;
142 if (! plist.is_null()) {
144 plist->validateParametersAndSetDefaults (*validParams);
148 this->setMyParamList (plist);
150 RCP<ParameterList> planParams(plist);
151 planParams->remove(
"Debug",
false);
152 planParams->remove(
"VerboseObject",
false);
153 plan_.setParameterList(planParams);
157 Teuchos::RCP<const Teuchos::ParameterList>
160 using Teuchos::Array;
161 using Teuchos::ParameterList;
162 using Teuchos::parameterList;
164 using Teuchos::setStringToIntegralParameter;
166 const bool debug = tpetraDistributorDebugDefault;
169 const std::string defaultSendType (
"Send");
170 Array<Details::EDistributorSendType> sendTypeEnums;
171 sendTypeEnums.push_back (Details::DISTRIBUTOR_ISEND);
172 sendTypeEnums.push_back (Details::DISTRIBUTOR_SEND);
173 sendTypeEnums.push_back (Details::DISTRIBUTOR_ALLTOALL);
174#if defined(HAVE_TPETRACORE_MPI_ADVANCE)
175 sendTypeEnums.push_back(Details::DISTRIBUTOR_MPIADVANCE_ALLTOALL);
176 sendTypeEnums.push_back(Details::DISTRIBUTOR_MPIADVANCE_NBRALLTOALLV);
179 RCP<ParameterList> plist = parameterList (
"Tpetra::Distributor");
180 setStringToIntegralParameter<Details::EDistributorSendType> (
"Send type",
181 defaultSendType,
"When using MPI, the variant of send to use in "
182 "do[Reverse]Posts()", sendTypes(), sendTypeEnums(), plist.getRawPtr());
183 plist->set (
"Debug", debug,
"Whether to print copious debugging output on "
185 plist->set (
"Timer Label",
"",
"Label for Time Monitor output");
193 Teuchos::setupVerboseObjectSublist (&*plist);
194 return Teuchos::rcp_const_cast<const ParameterList> (plist);
199 {
return plan_.getTotalReceiveLength(); }
202 {
return plan_.getNumReceives(); }
205 {
return plan_.hasSelfMessage(); }
208 {
return plan_.getNumSends(); }
211 {
return plan_.getMaxSendLength(); }
214 {
return plan_.getProcsFrom(); }
217 {
return plan_.getLengthsFrom(); }
220 {
return plan_.getProcsTo(); }
223 {
return plan_.getLengthsTo(); }
225 Teuchos::RCP<Distributor>
227 if (reverseDistributor_.is_null () && create) {
228 createReverseDistributor ();
230 TEUCHOS_TEST_FOR_EXCEPTION
231 (reverseDistributor_.is_null () && create, std::logic_error,
"The reverse "
232 "Distributor is null after createReverseDistributor returned. "
233 "Please report this bug to the Tpetra developers.");
234 return reverseDistributor_;
239 Distributor::createReverseDistributor()
const
241 reverseDistributor_ = Teuchos::rcp(
new Distributor(plan_.getComm()));
242 reverseDistributor_->plan_ = *plan_.getReversePlan();
243 reverseDistributor_->verbose_ = verbose_;
259 reverseDistributor_->reverseDistributor_ = Teuchos::null;
265 actor_.doWaits(plan_);
270 if (! reverseDistributor_.is_null()) {
271 reverseDistributor_->doWaits();
276 std::ostringstream out;
278 out <<
"\"Tpetra::Distributor\": {";
279 const std::string label = this->getObjectLabel ();
281 out <<
"Label: " << label <<
", ";
283 out <<
"How initialized: "
287 << DistributorSendTypeEnumToString (plan_.getSendType())
288 <<
", Debug: " << (verbose_ ?
"true" :
"false")
295 localDescribeToString (
const Teuchos::EVerbosityLevel vl)
const
297 using Teuchos::toString;
298 using Teuchos::VERB_HIGH;
299 using Teuchos::VERB_EXTREME;
303 if (vl <= Teuchos::VERB_LOW || plan_.getComm().is_null ()) {
304 return std::string ();
307 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
308 auto outp = Teuchos::getFancyOStream (outStringP);
309 Teuchos::FancyOStream& out = *outp;
311 const int myRank = plan_.getComm()->getRank ();
312 const int numProcs = plan_.getComm()->getSize ();
313 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
314 Teuchos::OSTab tab1 (out);
318 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
319 out <<
"procsTo: " << toString (plan_.getProcsTo()) << endl;
320 out <<
"lengthsTo: " << toString (plan_.getLengthsTo()) << endl;
323 if (vl == VERB_EXTREME) {
324 out <<
"startsTo: " << toString (plan_.getStartsTo()) << endl;
325 out <<
"indicesTo: " << toString (plan_.getIndicesTo()) << endl;
327 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
330 out <<
"lengthsFrom: " << toString (plan_.getLengthsFrom()) << endl;
331 out <<
"procsFrom: " << toString (plan_.getProcsFrom()) << endl;
335 return outStringP->str ();
340 describe (Teuchos::FancyOStream& out,
341 const Teuchos::EVerbosityLevel verbLevel)
const
344 using Teuchos::VERB_DEFAULT;
345 using Teuchos::VERB_NONE;
346 using Teuchos::VERB_LOW;
347 using Teuchos::VERB_MEDIUM;
348 using Teuchos::VERB_HIGH;
349 using Teuchos::VERB_EXTREME;
350 const Teuchos::EVerbosityLevel vl =
351 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
353 if (vl == VERB_NONE) {
361 if (plan_.getComm().is_null ()) {
364 const int myRank = plan_.getComm()->getRank ();
365 const int numProcs = plan_.getComm()->getSize ();
374 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
380 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
383 out <<
"\"Tpetra::Distributor\":" << endl;
384 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
386 const std::string label = this->getObjectLabel ();
388 out <<
"Label: " << label << endl;
390 out <<
"Number of processes: " << numProcs << endl
391 <<
"How initialized: "
395 out <<
"Parameters: " << endl;
396 Teuchos::OSTab tab2 (out);
397 out <<
"\"Send type\": "
398 << DistributorSendTypeEnumToString (plan_.getSendType()) << endl
399 <<
"\"Debug\": " << (verbose_ ?
"true" :
"false") << endl;
405 const std::string lclStr = this->localDescribeToString (vl);
409 out <<
"Reverse Distributor:";
410 if (reverseDistributor_.is_null ()) {
411 out <<
" null" << endl;
415 reverseDistributor_->describe (out, vl);
423 return plan_.createFromSends(exportProcIDs);
429 const Teuchos::ArrayView<const int>& remoteProcIDs)
431 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.
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.