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>
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)
74 , reverseDistributor_ (
distributor.reverseDistributor_)
76 using Teuchos::ParameterList;
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_);
115 Distributor::getVerbose()
121 std::unique_ptr<std::string>
123 createPrefix(
const char methodName[])
const
126 plan_.getComm().getRawPtr(),
"Distributor", methodName);
133 using ::Tpetra::Details::Behavior;
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()) {
157 Teuchos::RCP<const Teuchos::ParameterList>
160 using Teuchos::Array;
161 using Teuchos::ParameterList;
162 using Teuchos::parameterList;
164 using Teuchos::setStringToIntegralParameter;
174#if defined(HAVE_TPETRACORE_MPI_ADVANCE)
175 sendTypeEnums.push_back(Details::DISTRIBUTOR_MPIADVANCE_ALLTOALL);
176 sendTypeEnums.push_back(Details::DISTRIBUTOR_MPIADVANCE_NBRALLTOALLV);
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 ();
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\": {";
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 ();
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 =
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));
388 out <<
"Label: " << label <<
endl;
391 <<
"How initialized: "
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 ()) {
415 reverseDistributor_->describe (
out,
vl);
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.
Struct that holds views of the contents of a CrsMatrix.
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.