Tpetra Matrix/Vector Services Version of the Day
Tpetra_ImportExportData_def.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_IMPORTEXPORTDATA_DEF_HPP
00043 #define TPETRA_IMPORTEXPORTDATA_DEF_HPP
00044 
00045 #ifdef DOXYGEN_USE_ONLY
00046 #  include <Tpetra_ImportExportData_decl.hpp>
00047 #endif // DOXYGEN_USE_ONLY
00048 
00049 #include <Tpetra_Map.hpp>
00050 
00051 namespace Tpetra {
00052   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00053   ImportExportData<LocalOrdinal,GlobalOrdinal,Node>::
00054   ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
00055                     const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target)
00056     : out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr)))
00057     , numSameIDs_ (0)
00058     , source_ (source)
00059     , target_ (target)
00060     , comm_ (source->getComm())
00061     , distributor_ (comm_, out_)
00062   {}
00063 
00064   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00065   ImportExportData<LocalOrdinal,GlobalOrdinal,Node>::
00066   ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
00067                     const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
00068                     const Teuchos::RCP<Teuchos::FancyOStream>& out)
00069     : out_ (out)
00070     , numSameIDs_ (0)
00071     , source_ (source)
00072     , target_ (target)
00073     , comm_ (source->getComm())
00074     , distributor_ (comm_, out_)
00075   {}
00076 
00077   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00078   ImportExportData<LocalOrdinal,GlobalOrdinal,Node>::
00079   ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
00080                     const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
00081                     const Teuchos::RCP<Teuchos::ParameterList>& plist)
00082     : out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr)))
00083     , numSameIDs_ (0)
00084     , source_ (source)
00085     , target_ (target)
00086     , comm_ (source->getComm())
00087     , distributor_ (comm_, out_, plist)
00088   {}
00089 
00090   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00091   ImportExportData<LocalOrdinal,GlobalOrdinal,Node>::
00092   ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
00093                     const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
00094                     const Teuchos::RCP<Teuchos::FancyOStream>& out,
00095                     const Teuchos::RCP<Teuchos::ParameterList>& plist)
00096     : out_ (out)
00097     , numSameIDs_ (0)
00098     , source_ (source)
00099     , target_ (target)
00100     , comm_ (source->getComm())
00101     , distributor_ (comm_, out_, plist)
00102   {}
00103 
00104   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00105   RCP<ImportExportData<LocalOrdinal, GlobalOrdinal, Node> >
00106   ImportExportData<LocalOrdinal,GlobalOrdinal,Node>::reverseClone()
00107   {
00108     Teuchos::RCP<ImportExportData<LocalOrdinal,GlobalOrdinal,Node> > tData =
00109       rcp (new ImportExportData<LocalOrdinal,GlobalOrdinal,Node> (target_,source_));
00110 
00111     // Things that stay the same
00112     tData->comm_             = comm_;
00113     tData->numSameIDs_       = numSameIDs_;
00114 
00115     // Things that reverse
00116     tData->distributor_      = *distributor_.getReverse();
00117     tData->permuteToLIDs_    = permuteFromLIDs_;
00118     tData->permuteFromLIDs_  = permuteToLIDs_;
00119 
00120     // Remotes / exports (easy part)
00121     tData->exportLIDs_       = remoteLIDs_;
00122     tData->remoteLIDs_       = exportLIDs_;
00123     tData->exportPIDs_.resize(tData->exportLIDs_.size());
00124 
00125     // Remotes / exports (hard part) - extract the exportPIDs from the remotes of my distributor
00126     size_t NumReceives                  = distributor_.getNumReceives();
00127     ArrayView<const int> ProcsFrom      = distributor_.getImagesFrom();
00128     ArrayView<const size_t> LengthsFrom = distributor_.getLengthsFrom();
00129 
00130     for (size_t i = 0, j = 0; i < NumReceives; ++i) {
00131       const int pid = ProcsFrom[i];
00132       for (size_t k = 0; k < LengthsFrom[i]; ++k) {
00133         tData->exportPIDs_[j] = pid;
00134         ++j;
00135       }
00136     }
00137     return tData;
00138   }
00139 
00140 
00141   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00142   ImportExportData<LocalOrdinal,GlobalOrdinal,Node>::~ImportExportData()
00143   {}
00144 
00145 } // namespace Tpetra
00146 
00147 // Explicit instantiation macro.
00148 // Only invoke this when in the Tpetra namespace.
00149 // Most users do not need to use this.
00150 //
00151 // LO: The local ordinal type.
00152 // GO: The global ordinal type.
00153 // NODE: The Kokkos Node type.
00154 #define TPETRA_IMPORTEXPORTDATA_INSTANT(LO, GO, NODE) \
00155   \
00156   template class ImportExportData< LO , GO , NODE >;
00157 
00158 #endif // TPETRA_IMPORTEXPORTDATA_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines