Tpetra Matrix/Vector Services Version of the Day
Tpetra_Import_decl.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //          Tpetra: Templated Linear Algebra Services Package
00005 //                 Copyright (2008) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 
00042 #ifndef TPETRA_IMPORT_DECL_HPP
00043 #define TPETRA_IMPORT_DECL_HPP
00044 
00045 #include <Tpetra_ConfigDefs.hpp>
00046 #include <Kokkos_DefaultNode.hpp>
00047 #include <Teuchos_Describable.hpp>
00048 
00049 namespace Tpetra {
00050   //
00051   // Forward declarations.  The "doxygen" bit simply tells Doxygen
00052   // (our automatic documentation generation system) to skip forward
00053   // declarations.
00054   //
00055 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00056   class Distributor;
00057 
00058   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00059   class ImportExportData;
00060 
00061   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00062   class Export;
00063 
00064   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00065   class Map;
00066 #endif // DOXYGEN_SHOULD_SKIP_THIS
00067 
00121   template <class LocalOrdinal,
00122             class GlobalOrdinal = LocalOrdinal,
00123             class Node = KokkosClassic::DefaultNode::DefaultNodeType>
00124   class Import: public Teuchos::Describable {
00125     friend class Export<LocalOrdinal,GlobalOrdinal,Node>;
00126   public:
00128     typedef Map<LocalOrdinal,GlobalOrdinal,Node> map_type;
00129 
00131 
00132 
00140     Import (const Teuchos::RCP<const map_type>& source,
00141             const Teuchos::RCP<const map_type>& target);
00142 
00153     Import (const Teuchos::RCP<const map_type>& source,
00154             const Teuchos::RCP<const map_type>& target,
00155             const RCP<Teuchos::FancyOStream>& out);
00156 
00169     Import (const Teuchos::RCP<const map_type>& source,
00170             const Teuchos::RCP<const map_type>& target,
00171             const Teuchos::RCP<Teuchos::ParameterList>& plist);
00172 
00188     Import (const Teuchos::RCP<const map_type>& source,
00189             const Teuchos::RCP<const map_type>& target,
00190             const RCP<Teuchos::FancyOStream>& out,
00191             const Teuchos::RCP<Teuchos::ParameterList>& plist);
00192 
00204     Import (const Teuchos::RCP<const map_type>& source,
00205             const Teuchos::RCP<const map_type>& target,
00206             Teuchos::Array<int> & remotePIDs);
00207 
00212     Import (const Import<LocalOrdinal,GlobalOrdinal,Node>& importer);
00213 
00220     Import (const Export<LocalOrdinal,GlobalOrdinal,Node>& exporter);
00221 
00223     ~Import();
00224 
00229     void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& plist);
00230 
00232 
00233 
00234 
00239     size_t getNumSameIDs() const;
00240 
00247     size_t getNumPermuteIDs() const;
00248 
00250     ArrayView<const LocalOrdinal> getPermuteFromLIDs() const;
00251 
00253     ArrayView<const LocalOrdinal> getPermuteToLIDs() const;
00254 
00256     size_t getNumRemoteIDs() const;
00257 
00259     ArrayView<const LocalOrdinal> getRemoteLIDs() const;
00260 
00262     size_t getNumExportIDs() const;
00263 
00265     ArrayView<const LocalOrdinal> getExportLIDs() const;
00266 
00271     ArrayView<const int> getExportPIDs() const;
00272 
00274     Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
00275     getSourceMap () const;
00276 
00278     Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
00279     getTargetMap () const;
00280 
00282     Distributor & getDistributor() const;
00283 
00285     Import<LocalOrdinal,GlobalOrdinal,Node>&
00286     operator= (const Import<LocalOrdinal,GlobalOrdinal,Node>& Source);
00287 
00321     Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00322     setUnion (const Import<LocalOrdinal, GlobalOrdinal, Node>& rhs) const;
00323 
00340     Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00341     setUnion () const;
00342     
00343 
00348     Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00349     createRemoteOnlyImport (const Teuchos::RCP<const map_type>& remoteTarget) const;
00350 
00351 
00353 
00354 
00355 
00371     virtual void print (std::ostream& os) const;
00372 
00374 
00375   private:
00377     RCP<ImportExportData<LocalOrdinal,GlobalOrdinal,Node> > ImportData_;
00379     RCP<Teuchos::FancyOStream> out_;
00381     bool debug_;
00382 
00384 
00385 
00402     void
00403     init (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
00404           const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
00405           bool useRemotePIDs,
00406           Teuchos::Array<int> & remotePIDs,
00407           const Teuchos::RCP<Teuchos::ParameterList>& plist);
00408 
00440     void setupSamePermuteRemote (Teuchos::Array<GlobalOrdinal>& remoteGIDs);
00441 
00470     void
00471     setupExport (Teuchos::Array<GlobalOrdinal>& remoteGIDs, bool useRemotePIDs, Teuchos::Array<int> & remotePIDs);
00473 
00474 
00482     Import (const Teuchos::RCP<const map_type>& source,
00483             const Teuchos::RCP<const map_type>& target,
00484             const size_t numSameIDs,
00485             Teuchos::Array<LocalOrdinal>& permuteToLIDs,
00486             Teuchos::Array<LocalOrdinal>& permuteFromLIDs,
00487             Teuchos::Array<LocalOrdinal>& remoteLIDs,
00488             Teuchos::Array<LocalOrdinal>& exportLIDs,
00489             Teuchos::Array<int>& exportPIDs,
00490             Distributor& distributor,
00491             const Teuchos::RCP<Teuchos::FancyOStream>& out = Teuchos::null,
00492             const Teuchos::RCP<Teuchos::ParameterList>& plist = Teuchos::null);
00493 
00494 
00495   }; // class Import
00496 
00507   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00508   Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00509   createImport (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& src,
00510                 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& tgt)
00511   {
00512     if (src == tgt) {
00513       return Teuchos::null;
00514     }
00515 #ifdef HAVE_TPETRA_DEBUG
00516     TEUCHOS_TEST_FOR_EXCEPTION(
00517       src == null || tgt == null, std::runtime_error,
00518       "Tpetra::createImport(): neither source nor target map may be null:"
00519       << std::endl << "source: " << src << std::endl << "target: " << tgt
00520       << std::endl);
00521 #endif // HAVE_TPETRA_DEBUG
00522     return Teuchos::rcp (new Import<LocalOrdinal, GlobalOrdinal, Node> (src, tgt));
00523   }
00524 
00536   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00537   Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00538   createImport (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& src,
00539                 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& tgt,
00540                 const Teuchos::RCP<Teuchos::ParameterList>& plist)
00541   {
00542     if (src == tgt) {
00543       return Teuchos::null;
00544     }
00545 #ifdef HAVE_TPETRA_DEBUG
00546     TEUCHOS_TEST_FOR_EXCEPTION(
00547       src == null || tgt == null, std::runtime_error,
00548       "Tpetra::createImport(): neither source nor target map may be null:"
00549       << std::endl << "source: " << src << std::endl << "target: " << tgt
00550       << std::endl);
00551 #endif // HAVE_TPETRA_DEBUG
00552     typedef Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
00553     return Teuchos::rcp (new import_type (src, tgt, plist));
00554   }
00555 } // namespace Tpetra
00556 
00557 #endif // TPETRA_IMPORT_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines