Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
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_Details_Transfer.hpp>
00046 
00047 namespace Tpetra {
00048   //
00049   // Forward declarations.  The "doxygen" bit simply tells Doxygen
00050   // (our automatic documentation generation system) to skip forward
00051   // declarations.
00052   //
00053 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00054   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00055   class ImportExportData;
00056 
00057   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00058   class Export;
00059 #endif // DOXYGEN_SHOULD_SKIP_THIS
00060 
00121   template <class LocalOrdinal = Map<>::local_ordinal_type,
00122             class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
00123             class Node = typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
00124   class Import:
00125     public ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>
00126   {
00127   private:
00128     friend class Export<LocalOrdinal,GlobalOrdinal,Node>;
00129   public:
00131     //typedef typename ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>::map_type map_type;
00132     typedef ::Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
00133 
00135 
00136 
00144     Import (const Teuchos::RCP<const map_type>& source,
00145             const Teuchos::RCP<const map_type>& target);
00146 
00157     Import (const Teuchos::RCP<const map_type>& source,
00158             const Teuchos::RCP<const map_type>& target,
00159             const RCP<Teuchos::FancyOStream>& out);
00160 
00173     Import (const Teuchos::RCP<const map_type>& source,
00174             const Teuchos::RCP<const map_type>& target,
00175             const Teuchos::RCP<Teuchos::ParameterList>& plist);
00176 
00192     Import (const Teuchos::RCP<const map_type>& source,
00193             const Teuchos::RCP<const map_type>& target,
00194             const RCP<Teuchos::FancyOStream>& out,
00195             const Teuchos::RCP<Teuchos::ParameterList>& plist);
00196 
00208     Import (const Teuchos::RCP<const map_type>& source,
00209             const Teuchos::RCP<const map_type>& target,
00210             Teuchos::Array<int> & remotePIDs);
00211 
00216     Import (const Import<LocalOrdinal,GlobalOrdinal,Node>& importer);
00217 
00224     Import (const Export<LocalOrdinal,GlobalOrdinal,Node>& exporter);
00225 
00227     virtual ~Import ();
00228 
00233     void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& plist);
00234 
00236 
00237 
00238 
00243     size_t getNumSameIDs() const;
00244 
00251     size_t getNumPermuteIDs() const;
00252 
00254     ArrayView<const LocalOrdinal> getPermuteFromLIDs() const;
00255 
00257     ArrayView<const LocalOrdinal> getPermuteToLIDs() const;
00258 
00260     size_t getNumRemoteIDs() const;
00261 
00263     ArrayView<const LocalOrdinal> getRemoteLIDs() const;
00264 
00266     size_t getNumExportIDs() const;
00267 
00269     ArrayView<const LocalOrdinal> getExportLIDs() const;
00270 
00275     ArrayView<const int> getExportPIDs() const;
00276 
00278     Teuchos::RCP<const map_type> getSourceMap () const;
00279 
00281     Teuchos::RCP<const map_type> getTargetMap () const;
00282 
00284     Distributor & getDistributor() const;
00285 
00287     Import<LocalOrdinal,GlobalOrdinal,Node>&
00288     operator= (const Import<LocalOrdinal,GlobalOrdinal,Node>& Source);
00289 
00323     Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00324     setUnion (const Import<LocalOrdinal, GlobalOrdinal, Node>& rhs) const;
00325 
00342     Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00343     setUnion () const;
00344 
00345 
00350     Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00351     createRemoteOnlyImport (const Teuchos::RCP<const map_type>& remoteTarget) const;
00352 
00353 
00355 
00356 
00357 
00373     virtual void print (std::ostream& os) const;
00374 
00376 
00377   private:
00379     RCP<ImportExportData<LocalOrdinal,GlobalOrdinal,Node> > ImportData_;
00381     RCP<Teuchos::FancyOStream> out_;
00383     bool debug_;
00384 
00386 
00387 
00404     void
00405     init (const Teuchos::RCP<const map_type>& source,
00406           const Teuchos::RCP<const map_type>& target,
00407           bool useRemotePIDs,
00408           Teuchos::Array<int> & remotePIDs,
00409           const Teuchos::RCP<Teuchos::ParameterList>& plist);
00410 
00442     void setupSamePermuteRemote (Teuchos::Array<GlobalOrdinal>& remoteGIDs);
00443 
00472     void
00473     setupExport (Teuchos::Array<GlobalOrdinal>& remoteGIDs, bool useRemotePIDs, Teuchos::Array<int> & remotePIDs);
00475 
00476 
00484     Import (const Teuchos::RCP<const map_type>& source,
00485             const Teuchos::RCP<const map_type>& target,
00486             const size_t numSameIDs,
00487             Teuchos::Array<LocalOrdinal>& permuteToLIDs,
00488             Teuchos::Array<LocalOrdinal>& permuteFromLIDs,
00489             Teuchos::Array<LocalOrdinal>& remoteLIDs,
00490             Teuchos::Array<LocalOrdinal>& exportLIDs,
00491             Teuchos::Array<int>& exportPIDs,
00492             Distributor& distributor,
00493             const Teuchos::RCP<Teuchos::FancyOStream>& out = Teuchos::null,
00494             const Teuchos::RCP<Teuchos::ParameterList>& plist = Teuchos::null);
00495 
00496 
00497   }; // class Import
00498 
00509   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00510   Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00511   createImport (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& src,
00512                 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& tgt)
00513   {
00514     if (src == tgt) {
00515       return Teuchos::null;
00516     }
00517 #ifdef HAVE_TPETRA_DEBUG
00518     TEUCHOS_TEST_FOR_EXCEPTION(
00519       src == null || tgt == null, std::runtime_error,
00520       "Tpetra::createImport(): neither source nor target map may be null:"
00521       << std::endl << "source: " << src << std::endl << "target: " << tgt
00522       << std::endl);
00523 #endif // HAVE_TPETRA_DEBUG
00524     typedef Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
00525     return Teuchos::rcp (new import_type (src, tgt));
00526   }
00527 
00539   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00540   Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> >
00541   createImport (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& src,
00542                 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& tgt,
00543                 const Teuchos::RCP<Teuchos::ParameterList>& plist)
00544   {
00545     if (src == tgt) {
00546       return Teuchos::null;
00547     }
00548 #ifdef HAVE_TPETRA_DEBUG
00549     TEUCHOS_TEST_FOR_EXCEPTION(
00550       src == null || tgt == null, std::runtime_error,
00551       "Tpetra::createImport(): neither source nor target map may be null:"
00552       << std::endl << "source: " << src << std::endl << "target: " << tgt
00553       << std::endl);
00554 #endif // HAVE_TPETRA_DEBUG
00555     typedef Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
00556     return Teuchos::rcp (new import_type (src, tgt, plist));
00557   }
00558 
00559 } // namespace Tpetra
00560 
00561 #endif // TPETRA_IMPORT_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines