Tpetra parallel linear algebra  Version of the Day
Tpetra_Import_decl.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_IMPORT_DECL_HPP
43 #define TPETRA_IMPORT_DECL_HPP
44 
45 #include "Tpetra_Details_Transfer.hpp"
46 #include "Tpetra_Import_fwd.hpp"
47 #include "Tpetra_Export_fwd.hpp"
49 
50 namespace Tpetra {
51 namespace Classes {
112  template<class LocalOrdinal = ::Tpetra::Details::DefaultTypes::local_ordinal_type,
113  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
115  class Import:
116  public ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>
117  {
118  private:
119  friend class Export<LocalOrdinal,GlobalOrdinal,Node>;
120  public:
122  //typedef typename ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>::map_type map_type;
123  typedef ::Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
124 
126 
127 
135  Import (const Teuchos::RCP<const map_type>& source,
136  const Teuchos::RCP<const map_type>& target);
137 
148  Import (const Teuchos::RCP<const map_type>& source,
149  const Teuchos::RCP<const map_type>& target,
150  const Teuchos::RCP<Teuchos::FancyOStream>& out);
151 
164  Import (const Teuchos::RCP<const map_type>& source,
165  const Teuchos::RCP<const map_type>& target,
166  const Teuchos::RCP<Teuchos::ParameterList>& plist);
167 
183  Import (const Teuchos::RCP<const map_type>& source,
184  const Teuchos::RCP<const map_type>& target,
185  const Teuchos::RCP<Teuchos::FancyOStream>& out,
186  const Teuchos::RCP<Teuchos::ParameterList>& plist);
187 
199  Import (const Teuchos::RCP<const map_type>& source,
200  const Teuchos::RCP<const map_type>& target,
201  Teuchos::Array<int> & remotePIDs);
202 
208 
216 
247  Import (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& sourceMap,
248  const GlobalOrdinal targetMapRemoteOrPermuteGlobalIndices[],
249  const int targetMapRemoteOrPermuteProcessRanks[],
250  const LocalOrdinal numTargetMapRemoteOrPermuteGlobalIndices,
251  const bool mayReorderTargetMapIndicesLocally,
252  const Teuchos::RCP<Teuchos::ParameterList>& plist = Teuchos::null,
253  const Teuchos::RCP<Teuchos::FancyOStream>& out = Teuchos::null);
254 
261  Import (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& source,
262  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& target,
263  Teuchos::Array<int> & userRemotePIDs,
264  Teuchos::Array<GlobalOrdinal>& remoteGIDs,
265  const Teuchos::ArrayView<const LocalOrdinal> & userExportLIDs,
266  const Teuchos::ArrayView<const int> & userExportPIDs,
267  const bool useRemotePIDs,
268  const Teuchos::RCP<Teuchos::ParameterList>& plist = Teuchos::null,
269  const Teuchos::RCP<Teuchos::FancyOStream>& out = Teuchos::null);
270 
272  virtual ~Import ();
273 
278  void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& plist);
279 
281 
283 
288  size_t getNumSameIDs() const;
289 
296  size_t getNumPermuteIDs() const;
297 
299  Teuchos::ArrayView<const LocalOrdinal> getPermuteFromLIDs() const;
300 
302  Teuchos::ArrayView<const LocalOrdinal> getPermuteToLIDs() const;
303 
305  size_t getNumRemoteIDs() const;
306 
308  Teuchos::ArrayView<const LocalOrdinal> getRemoteLIDs() const;
309 
311  size_t getNumExportIDs() const;
312 
314  Teuchos::ArrayView<const LocalOrdinal> getExportLIDs() const;
315 
320  Teuchos::ArrayView<const int> getExportPIDs() const;
321 
323  Teuchos::RCP<const map_type> getSourceMap () const;
324 
326  Teuchos::RCP<const map_type> getTargetMap () const;
327 
329  Distributor & getDistributor() const;
330 
341  bool isLocallyComplete () const;
342 
346 
355  void
356  findUnionTargetGIDs(Teuchos::Array<GlobalOrdinal>& unionTgtGIDs,
357  Teuchos::Array<std::pair<int,GlobalOrdinal>>& remotePGIDs,
358  typename Teuchos::Array<GlobalOrdinal>::size_type& numSameGIDs,
359  typename Teuchos::Array<GlobalOrdinal>::size_type& numPermuteGIDs,
360  typename Teuchos::Array<GlobalOrdinal>::size_type& numRemoteGIDs,
361  const Teuchos::ArrayView<const GlobalOrdinal>& sameGIDs1,
362  const Teuchos::ArrayView<const GlobalOrdinal>& sameGIDs2,
363  Teuchos::Array<GlobalOrdinal>& permuteGIDs1,
364  Teuchos::Array<GlobalOrdinal>& permuteGIDs2,
365  Teuchos::Array<GlobalOrdinal>& remoteGIDs1,
366  Teuchos::Array<GlobalOrdinal>& remoteGIDs2,
367  Teuchos::Array<int>& remotePIDs1,
368  Teuchos::Array<int>& remotePIDs2) const;
369 
403  Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
405 
422  Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
423  setUnion () const;
424 
425 
430  Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
431  createRemoteOnlyImport (const Teuchos::RCP<const map_type>& remoteTarget) const;
432 
433 
435 
437 
460  virtual void
461  describe (Teuchos::FancyOStream& out,
462  const Teuchos::EVerbosityLevel verbLevel =
463  Teuchos::Describable::verbLevel_default) const;
464 
480  virtual void print (std::ostream& os) const;
481 
483  private:
485  Teuchos::RCP<ImportExportData<LocalOrdinal,GlobalOrdinal,Node> > ImportData_;
487  Teuchos::RCP<Teuchos::FancyOStream> out_;
489  bool debug_;
490 
492 
493 
510  void
511  init (const Teuchos::RCP<const map_type>& source,
512  const Teuchos::RCP<const map_type>& target,
513  bool useRemotePIDs,
514  Teuchos::Array<int> & remotePIDs,
515  const Teuchos::RCP<Teuchos::ParameterList>& plist);
516 
548  void setupSamePermuteRemote (Teuchos::Array<GlobalOrdinal>& remoteGIDs);
549 
578  void
579  setupExport (Teuchos::Array<GlobalOrdinal>& remoteGIDs, bool useRemotePIDs, Teuchos::Array<int> & remotePIDs);
581 
589  Import (const Teuchos::RCP<const map_type>& source,
590  const Teuchos::RCP<const map_type>& target,
591  const size_t numSameID,
592  Teuchos::Array<LocalOrdinal>& permuteToLIDs,
593  Teuchos::Array<LocalOrdinal>& permuteFromLIDs,
594  Teuchos::Array<LocalOrdinal>& remoteLIDs,
595  Teuchos::Array<LocalOrdinal>& exportLIDs,
596  Teuchos::Array<int>& exportPIDs,
597  Distributor& distributor,
598  const Teuchos::RCP<Teuchos::FancyOStream>& out = Teuchos::null,
599  const Teuchos::RCP<Teuchos::ParameterList>& plist = Teuchos::null);
600 
601 
602  }; // class Import
603 
604 } // namespace Classes
605 
615  template<class LocalOrdinal, class GlobalOrdinal, class Node>
616  Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
617  createImport (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& src,
618  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& tgt)
619  {
620  if (src == tgt) {
621  return Teuchos::null;
622  }
623 #ifdef HAVE_TPETRA_DEBUG
624  TEUCHOS_TEST_FOR_EXCEPTION(
625  src == Teuchos::null || tgt == Teuchos::null, std::runtime_error,
626  "Tpetra::createImport(): neither source nor target map may be null:"
627  << std::endl << "source: " << src << std::endl << "target: " << tgt
628  << std::endl);
629 #endif // HAVE_TPETRA_DEBUG
630  typedef Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
631  return Teuchos::rcp (new import_type (src, tgt));
632  }
633 
644  template<class LocalOrdinal, class GlobalOrdinal, class Node>
645  Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
646  createImport (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& src,
647  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& tgt,
648  const Teuchos::RCP<Teuchos::ParameterList>& plist)
649  {
650  if (src == tgt) {
651  return Teuchos::null;
652  }
653 #ifdef HAVE_TPETRA_DEBUG
654  TEUCHOS_TEST_FOR_EXCEPTION(
655  src == Teuchos::null || tgt == Teuchos::null, std::runtime_error,
656  "Tpetra::createImport(): neither source nor target map may be null:"
657  << std::endl << "source: " << src << std::endl << "target: " << tgt
658  << std::endl);
659 #endif // HAVE_TPETRA_DEBUG
660  typedef Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
661  return Teuchos::rcp (new import_type (src, tgt, plist));
662  }
663 
664 } // namespace Tpetra
665 
666 #endif // TPETRA_IMPORT_DECL_HPP
Teuchos::ArrayView< const LocalOrdinal > getPermuteFromLIDs() const
List of local IDs in the source Map that are permuted.
size_t getNumRemoteIDs() const
Number of entries not on the calling process.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Teuchos::RCP< const map_type > getTargetMap() const
The Target Map used to construct this Import object.
Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > createImport(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &src, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &tgt)
Nonmember constructor for Import.
Import< LocalOrdinal, GlobalOrdinal, Node > & operator=(const Import< LocalOrdinal, GlobalOrdinal, Node > &Source)
Assignment operator.
Forward declaration of Tpetra::ImportExportData.
Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > setUnion() const
Return the union of this Import this->getSourceMap()
Teuchos::ArrayView< const LocalOrdinal > getPermuteToLIDs() const
List of local IDs in the target Map that are permuted.
Teuchos::ArrayView< const int > getExportPIDs() const
List of processes to which entries will be sent.
Teuchos::RCP< const map_type > getSourceMap() const
The Source Map used to construct this Import object.
Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > createRemoteOnlyImport(const Teuchos::RCP< const map_type > &remoteTarget) const
Returns an importer that contains only the remote entries of this.
void findUnionTargetGIDs(Teuchos::Array< GlobalOrdinal > &unionTgtGIDs, Teuchos::Array< std::pair< int, GlobalOrdinal >> &remotePGIDs, typename Teuchos::Array< GlobalOrdinal >::size_type &numSameGIDs, typename Teuchos::Array< GlobalOrdinal >::size_type &numPermuteGIDs, typename Teuchos::Array< GlobalOrdinal >::size_type &numRemoteGIDs, const Teuchos::ArrayView< const GlobalOrdinal > &sameGIDs1, const Teuchos::ArrayView< const GlobalOrdinal > &sameGIDs2, Teuchos::Array< GlobalOrdinal > &permuteGIDs1, Teuchos::Array< GlobalOrdinal > &permuteGIDs2, Teuchos::Array< GlobalOrdinal > &remoteGIDs1, Teuchos::Array< GlobalOrdinal > &remoteGIDs2, Teuchos::Array< int > &remotePIDs1, Teuchos::Array< int > &remotePIDs2) const
Find the union of the target IDs from two Import objects.
int local_ordinal_type
Default value of Scalar template parameter.
::Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The specialization of Map used by this class.
Forward declaration of Tpetra::Export.
Common base class of Import and Export.
Forward declaration of Tpetra::Import.
Sets up and executes a communication plan for a Tpetra DistObject.
Teuchos::ArrayView< const LocalOrdinal > getExportLIDs() const
List of entries in the source Map that will be sent to other processes.
bool isLocallyComplete() const
Do all target Map indices on the calling process exist on at least one process (not necessarily this ...
size_t getNumPermuteIDs() const
Number of IDs to permute but not to communicate.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Set parameters.
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
Teuchos::ArrayView< const LocalOrdinal > getRemoteLIDs() const
List of entries in the target Map to receive from other processes.
Import(const Teuchos::RCP< const map_type > &source, const Teuchos::RCP< const map_type > &target)
Construct an Import from the source and target Maps.
size_t getNumExportIDs() const
Number of entries that must be sent by the calling process to other processes.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
virtual 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.
Distributor & getDistributor() const
The Distributor that this Import object uses to move data.
virtual ~Import()
Destructor.
A parallel distribution of indices over processes.
virtual void print(std::ostream &os) const
Print the Import&#39;s data to the given output stream.
size_t getNumSameIDs() const
Number of initial identical IDs.