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;
166 RCP<ParameterList> plist = parameterList (
"Tpetra::Distributor");
167 setStringToIntegralParameter<Details::EDistributorSendType> (
"Send type",
168 validatedSendType,
"When using MPI, the variant of send to use in "
169 "do[Reverse]Posts()", sendTypes(), sendTypeEnums(), plist.getRawPtr());
170 plist->set (
"Debug", debug,
"Whether to print copious debugging output on "
172 plist->set (
"Timer Label",
"",
"Label for Time Monitor output");
180 Teuchos::setupVerboseObjectSublist (&*plist);
181 return Teuchos::rcp_const_cast<
const ParameterList> (plist);
186 {
return plan_.getTotalReceiveLength(); }
189 {
return plan_.getNumReceives(); }
192 {
return plan_.hasSelfMessage(); }
195 {
return plan_.getNumSends(); }
198 {
return plan_.getMaxSendLength(); }
201 {
return plan_.getProcsFrom(); }
204 {
return plan_.getLengthsFrom(); }
207 {
return plan_.getProcsTo(); }
210 {
return plan_.getLengthsTo(); }
212 Teuchos::RCP<Distributor>
214 if (reverseDistributor_.is_null () && create) {
215 createReverseDistributor ();
217 TEUCHOS_TEST_FOR_EXCEPTION
218 (reverseDistributor_.is_null () && create, std::logic_error,
"The reverse "
219 "Distributor is null after createReverseDistributor returned. "
220 "Please report this bug to the Tpetra developers.");
221 return reverseDistributor_;
226 Distributor::createReverseDistributor()
const
228 reverseDistributor_ = Teuchos::rcp(
new Distributor(plan_.getComm()));
229 reverseDistributor_->plan_ = *plan_.getReversePlan();
230 reverseDistributor_->verbose_ = verbose_;
246 reverseDistributor_->reverseDistributor_ = Teuchos::null;
252 actor_.doWaits(plan_);
257 if (! reverseDistributor_.is_null()) {
258 reverseDistributor_->doWaits();
263 std::ostringstream out;
265 out <<
"\"Tpetra::Distributor\": {";
266 const std::string label = this->getObjectLabel ();
268 out <<
"Label: " << label <<
", ";
270 out <<
"How initialized: "
274 << DistributorSendTypeEnumToString (plan_.getSendType())
275 <<
", Debug: " << (verbose_ ?
"true" :
"false")
282 localDescribeToString (
const Teuchos::EVerbosityLevel vl)
const
284 using Teuchos::toString;
285 using Teuchos::VERB_HIGH;
286 using Teuchos::VERB_EXTREME;
290 if (vl <= Teuchos::VERB_LOW || plan_.getComm().is_null ()) {
291 return std::string ();
294 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
295 auto outp = Teuchos::getFancyOStream (outStringP);
296 Teuchos::FancyOStream& out = *outp;
298 const int myRank = plan_.getComm()->getRank ();
299 const int numProcs = plan_.getComm()->getSize ();
300 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
301 Teuchos::OSTab tab1 (out);
305 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
306 out <<
"procsTo: " << toString (plan_.getProcsTo()) << endl;
307 out <<
"lengthsTo: " << toString (plan_.getLengthsTo()) << endl;
310 if (vl == VERB_EXTREME) {
311 out <<
"startsTo: " << toString (plan_.getStartsTo()) << endl;
312 out <<
"indicesTo: " << toString (plan_.getIndicesTo()) << endl;
314 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
317 out <<
"lengthsFrom: " << toString (plan_.getLengthsFrom()) << endl;
318 out <<
"procsFrom: " << toString (plan_.getProcsFrom()) << endl;
322 return outStringP->str ();
328 const Teuchos::EVerbosityLevel verbLevel)
const
331 using Teuchos::VERB_DEFAULT;
332 using Teuchos::VERB_NONE;
333 using Teuchos::VERB_LOW;
334 using Teuchos::VERB_MEDIUM;
335 using Teuchos::VERB_HIGH;
336 using Teuchos::VERB_EXTREME;
337 const Teuchos::EVerbosityLevel vl =
338 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
340 if (vl == VERB_NONE) {
348 if (plan_.getComm().is_null ()) {
351 const int myRank = plan_.getComm()->getRank ();
352 const int numProcs = plan_.getComm()->getSize ();
361 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
367 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
370 out <<
"\"Tpetra::Distributor\":" << endl;
371 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
373 const std::string label = this->getObjectLabel ();
375 out <<
"Label: " << label << endl;
377 out <<
"Number of processes: " << numProcs << endl
378 <<
"How initialized: "
382 out <<
"Parameters: " << endl;
383 Teuchos::OSTab tab2 (out);
384 out <<
"\"Send type\": "
385 << DistributorSendTypeEnumToString (plan_.getSendType()) << endl
386 <<
"\"Debug\": " << (verbose_ ?
"true" :
"false") << endl;
392 const std::string lclStr = this->localDescribeToString (vl);
396 out <<
"Reverse Distributor:";
397 if (reverseDistributor_.is_null ()) {
398 out <<
" null" << endl;
402 reverseDistributor_->describe (out, vl);
410 return plan_.createFromSends(exportProcIDs);
416 const Teuchos::ArrayView<const int>& remoteProcIDs)
418 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.