Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Tpetra_Export_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_EXPORT_DEF_HPP
43 #define TPETRA_EXPORT_DEF_HPP
44 
45 #ifdef DOXYGEN_USE_ONLY
46 # include <Tpetra_Export_decl.hpp>
47 #endif // DOXYGEN_USE_ONLY
48 
49 #include <Tpetra_Distributor.hpp>
50 #include <Tpetra_Map.hpp>
51 #include <Tpetra_ImportExportData.hpp>
52 #include <Tpetra_Util.hpp>
53 #include <Tpetra_Import.hpp>
54 #include <Teuchos_as.hpp>
55 
56 namespace {
57  // Default value of Export's "Debug" parameter.
58  const bool tpetraExportDebugDefault = false;
59 } // namespace (anonymous)
60 
61 namespace Tpetra {
62  template <class LocalOrdinal, class GlobalOrdinal, class Node>
63  void
65  setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& plist)
66  {
67  bool debug = tpetraExportDebugDefault;
68  if (! plist.is_null ()) {
69  try {
70  debug = plist->get<bool> ("Debug");
71  } catch (Teuchos::Exceptions::InvalidParameter&) {}
72  }
73  debug_ = debug;
74  ExportData_->distributor_.setParameterList (plist);
75  }
76 
77  template <class LocalOrdinal, class GlobalOrdinal, class Node>
79  Export (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
80  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target) :
81  out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr))),
82  debug_ (tpetraExportDebugDefault)
83  {
84  using Teuchos::rcp;
85  using std::endl;
87 
88  if (! out_.is_null ()) {
89  out_->pushTab ();
90  }
91  if (debug_) {
92  std::ostringstream os;
93  const int myRank = source->getComm ()->getRank ();
94  os << myRank << ": Export ctor" << endl;
95  *out_ << os.str ();
96  }
97  ExportData_ = rcp (new data_type (source, target, out_));
98  Teuchos::Array<GlobalOrdinal> exportGIDs;
99  setupSamePermuteExport (exportGIDs);
100  if (debug_) {
101  std::ostringstream os;
102  const int myRank = source->getComm ()->getRank ();
103  os << myRank << ": Export ctor: "
104  << "setupSamePermuteExport done" << endl;
105  *out_ << os.str ();
106  }
107  if (source->isDistributed ()) {
108  setupRemote (exportGIDs);
109  }
110  if (debug_) {
111  std::ostringstream os;
112  const int myRank = source->getComm ()->getRank ();
113  os << myRank << ": Export ctor: done" << endl;
114  *out_ << os.str ();
115  }
116  if (! out_.is_null ()) {
117  out_->popTab ();
118  }
119  }
120 
121  template <class LocalOrdinal, class GlobalOrdinal, class Node>
123  Export (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
124  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
125  const RCP<Teuchos::FancyOStream>& out) :
126  out_ (out),
127  debug_ (tpetraExportDebugDefault)
128  {
129  using Teuchos::rcp;
130  using std::endl;
132 
133  if (! out_.is_null ()) {
134  out_->pushTab ();
135  }
136  if (debug_) {
137  std::ostringstream os;
138  const int myRank = source->getComm ()->getRank ();
139  os << myRank << ": Export ctor" << endl;
140  *out_ << os.str ();
141  }
142  ExportData_ = rcp (new data_type (source, target, out));
143  Teuchos::Array<GlobalOrdinal> exportGIDs;
144  setupSamePermuteExport (exportGIDs);
145  if (debug_) {
146  std::ostringstream os;
147  const int myRank = source->getComm ()->getRank ();
148  os << myRank << ": Export ctor: "
149  << "setupSamePermuteExport done" << endl;
150  *out_ << os.str ();
151  }
152  if (source->isDistributed ()) {
153  setupRemote (exportGIDs);
154  }
155  if (debug_) {
156  std::ostringstream os;
157  const int myRank = source->getComm ()->getRank ();
158  os << myRank << ": Export ctor: done" << endl;
159  *out_ << os.str ();
160  }
161  if (! out_.is_null ()) {
162  out_->popTab ();
163  }
164  }
165 
166  template <class LocalOrdinal, class GlobalOrdinal, class Node>
168  Export (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
169  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
170  const Teuchos::RCP<Teuchos::ParameterList>& plist) :
171  out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr))),
172  debug_ (tpetraExportDebugDefault)
173  {
174  using Teuchos::rcp;
175  using std::endl;
177 
178  // Read "Debug" parameter from the input ParameterList.
179  bool debug = tpetraExportDebugDefault;
180  if (! plist.is_null ()) {
181  try {
182  debug = plist->get<bool> ("Debug");
183  } catch (Teuchos::Exceptions::InvalidParameter&) {}
184  }
185  debug_ = debug;
186 
187  if (! out_.is_null ()) {
188  out_->pushTab ();
189  }
190  if (debug_) {
191  std::ostringstream os;
192  const int myRank = source->getComm ()->getRank ();
193  os << myRank << ": Export ctor" << endl;
194  *out_ << os.str ();
195  }
196  ExportData_ = rcp (new data_type (source, target, out_, plist));
197  Teuchos::Array<GlobalOrdinal> exportGIDs;
198  setupSamePermuteExport (exportGIDs);
199  if (debug_) {
200  std::ostringstream os;
201  const int myRank = source->getComm ()->getRank ();
202  os << myRank << ": Export ctor: "
203  << "setupSamePermuteExport done" << endl;
204  *out_ << os.str ();
205  }
206  if (source->isDistributed ()) {
207  setupRemote (exportGIDs);
208  }
209  if (debug_) {
210  std::ostringstream os;
211  const int myRank = source->getComm ()->getRank ();
212  os << myRank << ": Export ctor: done" << endl;
213  *out_ << os.str ();
214  }
215  if (! out_.is_null ()) {
216  out_->popTab ();
217  }
218  }
219 
220  template <class LocalOrdinal, class GlobalOrdinal, class Node>
222  Export (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
223  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
224  const RCP<Teuchos::FancyOStream>& out,
225  const Teuchos::RCP<Teuchos::ParameterList>& plist) :
226  out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr))),
227  debug_ (tpetraExportDebugDefault)
228  {
229  using Teuchos::rcp;
230  using std::endl;
232 
233  // Read "Debug" parameter from the input ParameterList.
234  bool debug = tpetraExportDebugDefault;
235  if (! plist.is_null ()) {
236  try {
237  debug = plist->get<bool> ("Debug");
238  } catch (Teuchos::Exceptions::InvalidParameter&) {}
239  }
240  debug_ = debug;
241 
242  if (! out_.is_null ()) {
243  out_->pushTab ();
244  }
245  if (debug_) {
246  std::ostringstream os;
247  const int myRank = source->getComm ()->getRank ();
248  os << myRank << ": Export ctor" << endl;
249  *out_ << os.str ();
250  }
251  ExportData_ = rcp (new data_type (source, target, out, plist));
252  Teuchos::Array<GlobalOrdinal> exportGIDs;
253  setupSamePermuteExport (exportGIDs);
254  if (debug_) {
255  std::ostringstream os;
256  const int myRank = source->getComm ()->getRank ();
257  os << myRank << ": Export ctor: "
258  << "setupSamePermuteExport done" << endl;
259  *out_ << os.str ();
260  }
261  if (source->isDistributed ()) {
262  setupRemote (exportGIDs);
263  }
264  if (debug_) {
265  std::ostringstream os;
266  const int myRank = source->getComm ()->getRank ();
267  os << myRank << ": Export ctor: done" << endl;
268  *out_ << os.str ();
269  }
270  if (! out_.is_null ()) {
271  out_->popTab ();
272  }
273  }
274 
275  template <class LocalOrdinal, class GlobalOrdinal, class Node>
278  : ExportData_ (rhs.ExportData_),
279  out_ (rhs.out_),
280  debug_ (rhs.debug_)
281  {
282  using std::endl;
283 
284  if (! out_.is_null ()) {
285  out_->pushTab ();
286  }
287  if (debug_) {
288  std::ostringstream os;
289  const int myRank = getSourceMap ()->getComm ()->getRank ();
290  os << myRank << ": Export copy ctor (done)" << endl;
291  *out_ << os.str ();
292  }
293  if (! out_.is_null ()) {
294  out_->popTab ();
295  }
296  }
297 
298  template <class LocalOrdinal, class GlobalOrdinal, class Node>
301  : out_ (importer.out_)
302  , debug_ (importer.debug_)
303  {
304  if(!importer.ImportData_.is_null()) ExportData_ = importer.ImportData_->reverseClone();
305  }
306 
307  template <class LocalOrdinal, class GlobalOrdinal, class Node>
309  {}
310 
311  template <class LocalOrdinal, class GlobalOrdinal, class Node>
313  return ExportData_->numSameIDs_;
314  }
315 
316  template <class LocalOrdinal, class GlobalOrdinal, class Node>
318  return ExportData_->permuteFromLIDs_.size();
319  }
320 
321  template <class LocalOrdinal, class GlobalOrdinal, class Node>
322  ArrayView<const LocalOrdinal>
324  return ExportData_->permuteFromLIDs_();
325  }
326 
327  template <class LocalOrdinal, class GlobalOrdinal, class Node>
328  ArrayView<const LocalOrdinal>
330  return ExportData_->permuteToLIDs_();
331  }
332 
333  template <class LocalOrdinal, class GlobalOrdinal, class Node>
335  return ExportData_->remoteLIDs_.size();
336  }
337 
338  template <class LocalOrdinal, class GlobalOrdinal, class Node>
339  ArrayView<const LocalOrdinal>
341  return ExportData_->remoteLIDs_();
342  }
343 
344  template <class LocalOrdinal, class GlobalOrdinal, class Node>
346  return ExportData_->exportLIDs_.size();
347  }
348 
349  template <class LocalOrdinal, class GlobalOrdinal, class Node>
350  ArrayView<const LocalOrdinal>
352  return ExportData_->exportLIDs_();
353  }
354 
355  template <class LocalOrdinal, class GlobalOrdinal, class Node>
356  ArrayView<const int>
358  return ExportData_->exportPIDs_();
359  }
360 
361  template <class LocalOrdinal, class GlobalOrdinal, class Node>
362  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
364  return ExportData_->source_;
365  }
366 
367  template <class LocalOrdinal, class GlobalOrdinal, class Node>
368  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
370  return ExportData_->target_;
371  }
372 
373  template <class LocalOrdinal, class GlobalOrdinal, class Node>
374  Distributor &
376  return ExportData_->distributor_;
377  }
378 
379  template <class LocalOrdinal, class GlobalOrdinal, class Node>
383  if (&rhs != this) {
384  ExportData_ = rhs.ExportData_;
385  }
386  return *this;
387  }
388 
389  template <class LocalOrdinal, class GlobalOrdinal, class Node>
391  print (std::ostream& os) const
392  {
393  using Teuchos::Comm;
394  using Teuchos::getFancyOStream;
395  using Teuchos::RCP;
396  using Teuchos::rcpFromRef;
397  using Teuchos::toString;
398  using std::endl;
399 
400  RCP<const Comm<int> > comm = getSourceMap ()->getComm ();
401  const int myImageID = comm->getRank ();
402  const int numImages = comm->getSize ();
403  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
404  if (myImageID == imageCtr) {
405  os << endl;
406  if (myImageID == 0) { // I'm the root node (only output this info once)
407  os << "Export Data Members:" << endl;
408  }
409  os << "Image ID : " << myImageID << endl;
410 
411  os << "permuteFromLIDs: " << toString (getPermuteFromLIDs ()) << endl;
412  os << "permuteToLIDs : " << toString (getPermuteToLIDs ()) << endl;
413  os << "remoteLIDs : " << toString (getRemoteLIDs ()) << endl;
414  os << "exportLIDs : " << toString (getExportLIDs ()) << endl;
415  os << "exportPIDs : " << toString (getExportPIDs ()) << endl;
416 
417  os << "numSameIDs : " << getNumSameIDs () << endl;
418  os << "numPermuteIDs : " << getNumPermuteIDs () << endl;
419  os << "numRemoteIDs : " << getNumRemoteIDs () << endl;
420  os << "numExportIDs : " << getNumExportIDs () << endl;
421  }
422  // A few global barriers give output a chance to complete.
423  comm->barrier();
424  comm->barrier();
425  comm->barrier();
426  }
427  if (myImageID == 0) {
428  os << endl << endl << "Source Map:" << endl << std::flush;
429  }
430  comm->barrier();
431  os << *getSourceMap();
432  comm->barrier();
433 
434  if (myImageID == 0) {
435  os << endl << endl << "Target Map:" << endl << std::flush;
436  }
437  comm->barrier();
438  os << *getTargetMap();
439  comm->barrier();
440 
441  // It's also helpful for debugging to print the Distributor
442  // object. Epetra_Export::Print() does this, so we can do a
443  // side-by-side comparison.
444  if (myImageID == 0) {
445  os << endl << endl << "Distributor:" << endl << std::flush;
446  }
447  comm->barrier();
448  getDistributor().describe (*(getFancyOStream (rcpFromRef (os))),
449  Teuchos::VERB_EXTREME);
450  }
451 
452 
453  template <class LocalOrdinal, class GlobalOrdinal, class Node>
454  void
456  setupSamePermuteExport (Teuchos::Array<GlobalOrdinal>& exportGIDs)
457  {
458  using Teuchos::arcp;
459  using Teuchos::Array;
460  using Teuchos::ArrayRCP;
461  using Teuchos::ArrayView;
462  using Teuchos::as;
463  using Teuchos::null;
464  typedef LocalOrdinal LO;
465  typedef GlobalOrdinal GO;
466  typedef typename ArrayView<const GO>::size_type size_type;
467  const Map<LO,GO,Node>& source = * (getSourceMap ());
468  const Map<LO,GO,Node>& target = * (getTargetMap ());
469  ArrayView<const GO> sourceGIDs = source.getNodeElementList ();
470  ArrayView<const GO> targetGIDs = target.getNodeElementList ();
471 
472 #ifdef HAVE_TPETRA_DEBUG
473  ArrayView<const GO> rawSrcGids = sourceGIDs;
474  ArrayView<const GO> rawTgtGids = targetGIDs;
475 #else
476  const GO* const rawSrcGids = sourceGIDs.getRawPtr ();
477  const GO* const rawTgtGids = targetGIDs.getRawPtr ();
478 #endif // HAVE_TPETRA_DEBUG
479  const size_type numSrcGids = sourceGIDs.size ();
480  const size_type numTgtGids = targetGIDs.size ();
481  const size_type numGids = std::min (numSrcGids, numTgtGids);
482 
483  // Compute numSameIDs_: the number of initial GIDs that are the
484  // same (and occur in the same order) in both Maps. The point of
485  // numSameIDs_ is for the common case of an Export where all the
486  // overlapping GIDs are at the end of the source Map, but
487  // otherwise the source and target Maps are the same. This allows
488  // a fast contiguous copy for the initial "same IDs."
489  size_type numSameGids = 0;
490  for ( ; numSameGids < numGids && rawSrcGids[numSameGids] == rawTgtGids[numSameGids]; ++numSameGids)
491  {} // third clause of 'for' does everything
492  ExportData_->numSameIDs_ = numSameGids;
493 
494  // Compute permuteToLIDs_, permuteFromLIDs_, exportGIDs, and
495  // exportLIDs_. The first two arrays are IDs to be permuted, and
496  // the latter two arrays are IDs to sent out ("exported"), called
497  // "export" IDs.
498  //
499  // IDs to permute are in both the source and target Maps, which
500  // means we don't have to send or receive them, but we do have to
501  // rearrange (permute) them in general. IDs to send are in the
502  // source Map, but not in the target Map.
503 
504  exportGIDs.resize (0);
505  Array<LO>& permuteToLIDs = ExportData_->permuteToLIDs_;
506  Array<LO>& permuteFromLIDs = ExportData_->permuteFromLIDs_;
507  Array<LO>& exportLIDs = ExportData_->exportLIDs_;
508  const LO LINVALID = Teuchos::OrdinalTraits<LO>::invalid ();
509  const LO numSrcLids = as<LO> (numSrcGids);
510  // Iterate over the source Map's LIDs, since we only need to do
511  // GID -> LID lookups for the target Map.
512  for (LO srcLid = numSameGids; srcLid < numSrcLids; ++srcLid) {
513  const GO curSrcGid = rawSrcGids[srcLid];
514  // getLocalElement() returns LINVALID if the GID isn't in the target Map.
515  // This saves us a lookup (which isNodeGlobalElement() would do).
516  const LO tgtLid = target.getLocalElement (curSrcGid);
517  if (tgtLid != LINVALID) { // if target.isNodeGlobalElement (curSrcGid)
518  permuteToLIDs.push_back (tgtLid);
519  permuteFromLIDs.push_back (srcLid);
520  } else {
521  exportGIDs.push_back (curSrcGid);
522  exportLIDs.push_back (srcLid);
523  }
524  }
525 
526  // exportLIDs_ is the list of this process' LIDs that it has to
527  // send out. Since this is an Export, and therefore the target
528  // Map is nonoverlapping, we know that each export LID only needs
529  // to be sent to one process. However, the source Map may be
530  // overlapping, so multiple processes might send to the same LID
531  // on a receiving process.
532 
534  getNumExportIDs() > 0 && ! source.isDistributed(),
535  std::runtime_error,
536  "::setupSamePermuteExport(): Source has export LIDs but Source is not "
537  "distributed globally." << std::endl
538  << "Exporting to a submap of the target map.");
539 
540  // Compute exportPIDs_ ("outgoing" process IDs).
541  //
542  // For each GID in exportGIDs (GIDs to which this process must
543  // send), find its corresponding owning process (a.k.a. "image")
544  // ID in the target Map. Store these process IDs in
545  // exportPIDs_. These are the process IDs to which the Export
546  // needs to send data.
547  //
548  // We only need to do this if the source Map is distributed;
549  // otherwise, the Export doesn't have to perform any
550  // communication.
551  if (source.isDistributed ()) {
552  ExportData_->exportPIDs_.resize(exportGIDs.size ());
553  // This call will assign any GID in the target Map with no
554  // corresponding process ID a fake process ID of -1. We'll use
555  // this below to remove exports for processses that don't exist.
556  const LookupStatus lookup =
557  target.getRemoteIndexList (exportGIDs(),
558  ExportData_->exportPIDs_ ());
559  TPETRA_ABUSE_WARNING( lookup == IDNotPresent, std::runtime_error,
560  "::setupSamePermuteExport(): The source Map has GIDs not found "
561  "in the target Map.");
562 
563  // Get rid of process IDs not in the target Map. This prevents
564  // exporting to GIDs which don't belong to any process in the
565  // target Map.
566  typedef typename ArrayRCP<int>::difference_type size_type;
567  if (lookup == IDNotPresent) {
568  const size_type numInvalidExports =
569  std::count_if (ExportData_->exportPIDs_().begin(),
570  ExportData_->exportPIDs_().end(),
571  std::bind1st (std::equal_to<int>(), -1));
572 
573  // count number of valid and total number of exports
574  const size_type totalNumExports = ExportData_->exportPIDs_.size();
575  if (numInvalidExports == totalNumExports) {
576  // all exports are invalid; we have no exports; we can delete all exports
577  exportGIDs.resize(0);
578  ExportData_->exportLIDs_.resize(0);
579  ExportData_->exportPIDs_.resize(0);
580  }
581  else {
582  // some exports are valid; we need to keep the valid exports
583  // pack and resize
584  size_type numValidExports = 0;
585  for (size_type e = 0; e < totalNumExports; ++e) {
586  if (ExportData_->exportPIDs_[e] != -1) {
587  exportGIDs[numValidExports] = exportGIDs[e];
588  ExportData_->exportLIDs_[numValidExports] = ExportData_->exportLIDs_[e];
589  ExportData_->exportPIDs_[numValidExports] = ExportData_->exportPIDs_[e];
590  ++numValidExports;
591  }
592  }
593  exportGIDs.resize (numValidExports);
594  ExportData_->exportLIDs_.resize (numValidExports);
595  ExportData_->exportPIDs_.resize (numValidExports);
596  }
597  }
598  }
599  } // setupSamePermuteExport()
600 
601  template <class LocalOrdinal, class GlobalOrdinal, class Node>
602  void
603  Export<LocalOrdinal,GlobalOrdinal,Node>::setupRemote(Teuchos::Array<GlobalOrdinal> & exportGIDs)
604  {
605  using std::endl;
606  const Map<LocalOrdinal,GlobalOrdinal,Node>& target = * (getTargetMap ());
607  const int myRank = target.getComm ()->getRank ();
608 
609  if (! out_.is_null ()) {
610  out_->pushTab ();
611  }
612  if (debug_) {
613  std::ostringstream os;
614  os << myRank << ": Export::setupRemote" << endl;
615  *out_ << os.str ();
616  }
617  if (! out_.is_null ()) {
618  out_->pushTab ();
619  }
620 
621  // Sort exportPIDs_ in ascending order, and apply the same
622  // permutation to exportGIDs_ and exportLIDs_. This ensures that
623  // exportPIDs_[i], exportGIDs_[i], and exportLIDs_[i] all
624  // refer to the same thing.
625  sort3 (ExportData_->exportPIDs_.begin(),
626  ExportData_->exportPIDs_.end(),
627  exportGIDs.begin(),
628  ExportData_->exportLIDs_.begin());
629 
630  if (debug_) {
631  std::ostringstream os;
632  os << myRank << ": Export::setupRemote: Calling createFromSends" << endl;
633  *out_ << os.str ();
634  }
635 
636  // Construct the list of entries that calling image needs to send
637  // as a result of everyone asking for what it needs to receive.
638  //
639  // mfh 05 Jan 2012: I understand the above comment as follows:
640  // Construct the communication plan from the list of image IDs to
641  // which we need to send.
642  size_t numRemoteIDs;
643  numRemoteIDs = ExportData_->distributor_.createFromSends (ExportData_->exportPIDs_ ());
644 
645  if (debug_) {
646  std::ostringstream os;
647  os << myRank << ": Export::setupRemote: Calling doPostsAndWaits" << endl;
648  *out_ << os.str ();
649  }
650 
651  // Use the communication plan with ExportGIDs to find out who is
652  // sending to us and get the proper ordering of GIDs for incoming
653  // remote entries (these will be converted to LIDs when done).
654  Array<GlobalOrdinal> remoteGIDs (numRemoteIDs);
655  ExportData_->distributor_.doPostsAndWaits (exportGIDs().getConst (), 1, remoteGIDs());
656 
657  // Remote (incoming) IDs come in as GIDs; convert to LIDs. LIDs
658  // tell this process where to store the incoming remote data.
659  ExportData_->remoteLIDs_.resize (numRemoteIDs);
660  {
661  typename Array<GlobalOrdinal>::const_iterator i = remoteGIDs.begin();
662  typename Array<LocalOrdinal>::iterator j = ExportData_->remoteLIDs_.begin();
663  while (i != remoteGIDs.end()) {
664  *j++ = target.getLocalElement(*i++);
665  }
666  }
667 
668  if (! out_.is_null ()) {
669  out_->popTab ();
670  }
671  if (debug_) {
672  std::ostringstream os;
673  os << myRank << ": Export::setupRemote: done" << endl;
674  *out_ << os.str ();
675  }
676  if (! out_.is_null ()) {
677  out_->popTab ();
678  }
679  }
680 } // namespace Tpetra
681 
682 // Explicit instantiation macro.
683 // Only invoke this when in the Tpetra namespace.
684 // Most users do not need to use this.
685 //
686 // LO: The local ordinal type.
687 // GO: The global ordinal type.
688 // NODE: The Kokkos Node type.
689 #define TPETRA_EXPORT_INSTANT(LO, GO, NODE) \
690  \
691  template class Export< LO , GO , NODE >;
692 
693 #endif // TPETRA_EXPORT_DEF_HPP
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
ArrayView< const int > getExportPIDs() const
List of processes to which entries will be sent.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getSourceMap() const
The source Map used to construct this Export.
virtual void print(std::ostream &os) const
Print the Export&#39;s data to the given output stream.
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
size_t getNumSameIDs() const
Number of initial identical IDs.
void sort3(const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT3 &first3)
Sort the first array, and apply the same permutation to the second and third arrays.
size_t getNumPermuteIDs() const
Number of IDs to permute but not to communicate.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
Export(const Teuchos::RCP< const map_type > &source, const Teuchos::RCP< const map_type > &target)
Construct a Export object from the source and target Map.
Export< LocalOrdinal, GlobalOrdinal, Node > & operator=(const Export< LocalOrdinal, GlobalOrdinal, Node > &rhs)
Assignment operator.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
size_t getNumExportIDs() const
Number of entries that must be sent by the calling process to other processes.
#define TPETRA_ABUSE_WARNING(throw_exception_test, Exception, msg)
Handle an abuse warning, according to HAVE_TPETRA_THROW_ABUSE_WARNINGS and HAVE_TPETRA_PRINT_ABUSE_WA...
Implementation detail of Import and Export.
Sets up and executes a communication plan for a Tpetra DistObject.
size_t getNumRemoteIDs() const
Number of entries not on the calling process.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process ranks and corresponding local indices for the given global indices.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
Describes a parallel distribution of objects over processes.
ArrayView< const LocalOrdinal > getRemoteLIDs() const
List of entries in the target Map to receive from other processes.
Stand-alone utility functions and macros.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getTargetMap() const
The target Map used to construct this Export.
Distributor & getDistributor() const
The Distributor that this Export object uses to move data.
~Export()
Destructor.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set parameters.