Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Tpetra_KokkosRefactor_CrsGraph_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_KOKKOSREFACTOR_CRSGRAPH_DECL_HPP
00043 #define TPETRA_KOKKOSREFACTOR_CRSGRAPH_DECL_HPP
00044 
00045 #include <KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
00046 #include <Kokkos_DualView.hpp>
00047 #include <Kokkos_StaticCrsGraph.hpp>
00048 
00049 namespace Tpetra {
00050 
00051 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00052   // forward declaration (needed for "friend" inside CrsGraph)
00053   template <class S, class LO, class GO, class N>
00054   class CrsMatrix;
00055 
00056   namespace Experimental {
00057     // forward declaration (needed for "friend" inside CrsGraph)
00058     template <class S, class LO, class GO, class N>
00059     class BlockCrsMatrix;
00060   } // namespace Experimental
00061 #endif // DOXYGEN_SHOULD_SKIP_THIS
00062 
00063   namespace Details {
00103     enum EStorageStatus {
00104       STORAGE_2D, //<! 2-D storage
00105       STORAGE_1D_UNPACKED, //<! 1-D "unpacked" storage
00106       STORAGE_1D_PACKED, //<! 1-D "packed" storage
00107       STORAGE_UB //<! Invalid value; upper bound on enum values
00108     };
00109   } // namespace Details
00110 
00115   template <class LocalOrdinal,
00116             class GlobalOrdinal,
00117             class DeviceType>
00118   class CrsGraph<
00119     LocalOrdinal, // the type of local indices
00120     GlobalOrdinal, // the type of global indices
00121     Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> > // the Kokkos Node type
00122       : public RowGraph<
00123         LocalOrdinal,
00124         GlobalOrdinal,
00125         Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >,
00126         public DistObject<
00127         GlobalOrdinal,
00128         LocalOrdinal,
00129         GlobalOrdinal,
00130         Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >,
00131         public Teuchos::ParameterListAcceptorDefaultBase
00132   {
00133     template <class S, class LO, class GO, class N>
00134     friend class CrsMatrix;
00135     template <class LO2, class GO2, class N2>
00136     friend class CrsGraph;
00137     template <class S, class LO, class GO, class N>
00138     friend class ::Tpetra::Experimental::BlockCrsMatrix;
00139 
00141     typedef DistObject<GlobalOrdinal, LocalOrdinal, GlobalOrdinal,
00142       Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> > dist_object_type;
00143 
00144   public:
00146     typedef LocalOrdinal local_ordinal_type;
00148     typedef GlobalOrdinal global_ordinal_type;
00150     typedef DeviceType device_type;
00156     typedef Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> node_type;
00157 
00158     typedef Kokkos::StaticCrsGraph<LocalOrdinal,
00159                                    Kokkos::LayoutLeft,
00160                                    device_type, size_t> LocalStaticCrsGraphType;
00161     typedef Kokkos::View<const size_t*, device_type> t_RowPtrs;
00162     typedef Kokkos::View<      size_t*, device_type> t_RowPtrsNC;
00163     typedef Kokkos::View<LocalOrdinal*, device_type> t_LocalOrdinal_1D;
00164 
00166     typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, node_type> map_type;
00168     typedef Tpetra::Import<LocalOrdinal, GlobalOrdinal, node_type> import_type;
00170     typedef Tpetra::Export<LocalOrdinal, GlobalOrdinal, node_type> export_type;
00171 
00173 
00174 
00193     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00194               size_t maxNumEntriesPerRow,
00195               ProfileType pftype = DynamicProfile,
00196               const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
00197 
00215     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00216               const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
00217               const ProfileType pftype = DynamicProfile,
00218               const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
00219 
00238     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00239               const Teuchos::ArrayRCP<const size_t>& numEntPerRow,
00240               const ProfileType pftype = DynamicProfile,
00241               const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
00242 
00264     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00265               const Teuchos::RCP<const map_type>& colMap,
00266               const size_t maxNumEntriesPerRow,
00267               const ProfileType pftype = DynamicProfile,
00268               const Teuchos::RCP<Teuchos::ParameterList>& params = null);
00269 
00288     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00289               const Teuchos::RCP<const map_type>& colMap,
00290               const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
00291               ProfileType pftype = DynamicProfile,
00292               const Teuchos::RCP<Teuchos::ParameterList>& params = null);
00293 
00313     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00314               const Teuchos::RCP<const map_type>& colMap,
00315               const Teuchos::ArrayRCP<const size_t>& numEntPerRow,
00316               ProfileType pftype = DynamicProfile,
00317               const Teuchos::RCP<Teuchos::ParameterList>& params = null);
00318 
00338     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00339               const Teuchos::RCP<const map_type>& colMap,
00340               const t_RowPtrs & rowPointers,
00341               const t_LocalOrdinal_1D & columnIndices,
00342               const Teuchos::RCP<Teuchos::ParameterList>& params = null);
00343 
00363     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00364               const Teuchos::RCP<const map_type>& colMap,
00365               const Teuchos::ArrayRCP<size_t> & rowPointers,
00366               const Teuchos::ArrayRCP<LocalOrdinal> & columnIndices,
00367               const Teuchos::RCP<Teuchos::ParameterList>& params = null);
00368 
00387     CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
00388               const Teuchos::RCP<const map_type>& colMap,
00389               const LocalStaticCrsGraphType& lclGraph,
00390               const Teuchos::RCP<Teuchos::ParameterList>& params);
00391 
00419     template<class Node2>
00420     Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node2> >
00421     clone (const Teuchos::RCP<Node2> &node2,
00422            const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const
00423     {
00424       typedef CrsGraph<LocalOrdinal, GlobalOrdinal, Node2> output_crs_graph_type;
00425       typedef CrsGraph<LocalOrdinal, GlobalOrdinal, node_type> input_crs_graph_type;
00426       typedef Details::CrsGraphCopier<output_crs_graph_type, input_crs_graph_type> copier_type;
00427       return copier_type::clone (*this, node2, params);
00428     }
00429 
00431     virtual ~CrsGraph();
00432 
00434 
00435 
00436 
00438     void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params);
00439 
00441     Teuchos::RCP<const ParameterList> getValidParameters () const;
00442 
00444 
00445 
00446 
00468     void
00469     insertGlobalIndices (GlobalOrdinal globalRow,
00470                          const Teuchos::ArrayView<const GlobalOrdinal>& indices);
00471 
00473 
00487     void
00488     insertLocalIndices (const LocalOrdinal localRow,
00489                         const Teuchos::ArrayView<const LocalOrdinal> &indices);
00490 
00492 
00501     void removeLocalIndices (LocalOrdinal localRow);
00502 
00504 
00505 
00511 
00517     void globalAssemble ();
00518 
00527     void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
00528 
00546     void
00547     fillComplete (const Teuchos::RCP<const map_type> &domainMap,
00548                   const Teuchos::RCP<const map_type> &rangeMap,
00549                   const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
00550 
00557     void fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
00558 
00569     void
00570     expertStaticFillComplete (const Teuchos::RCP<const map_type> & domainMap,
00571                               const Teuchos::RCP<const map_type> & rangeMap,
00572                               const Teuchos::RCP<const import_type> &importer=Teuchos::null,
00573                               const Teuchos::RCP<const export_type> &exporter=Teuchos::null,
00574                               const Teuchos::RCP<Teuchos::ParameterList> &params=Teuchos::null);
00576 
00577 
00578 
00580     Teuchos::RCP<const Comm<int> > getComm() const;
00581 
00583     Teuchos::RCP<node_type> getNode() const;
00584 
00586     Teuchos::RCP<const map_type> getRowMap () const;
00587 
00589     Teuchos::RCP<const map_type> getColMap () const;
00590 
00592     Teuchos::RCP<const map_type> getDomainMap () const;
00593 
00595     Teuchos::RCP<const map_type> getRangeMap () const;
00596 
00598     Teuchos::RCP<const import_type> getImporter () const;
00599 
00601     Teuchos::RCP<const export_type> getExporter () const;
00602 
00604 
00606     global_size_t getGlobalNumRows() const;
00607 
00609 
00612     global_size_t getGlobalNumCols() const;
00613 
00615     size_t getNodeNumRows() const;
00616 
00618 
00620     size_t getNodeNumCols() const;
00621 
00623     GlobalOrdinal getIndexBase() const;
00624 
00626 
00628     global_size_t getGlobalNumEntries() const;
00629 
00631     size_t getNodeNumEntries() const;
00632 
00634 
00635     size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const;
00636 
00638 
00639     size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const;
00640 
00642 
00649     size_t getNodeAllocationSize() const;
00650 
00652 
00653     size_t getNumAllocatedEntriesInGlobalRow(GlobalOrdinal globalRow) const;
00654 
00656 
00657     size_t getNumAllocatedEntriesInLocalRow(LocalOrdinal localRow) const;
00658 
00660 
00662     global_size_t getGlobalNumDiags() const;
00663 
00665 
00667     size_t getNodeNumDiags() const;
00668 
00681     size_t getGlobalMaxNumRowEntries() const;
00682 
00684 
00686     size_t getNodeMaxNumRowEntries() const;
00687 
00702     bool hasColMap() const;
00703 
00711     bool isLowerTriangular() const;
00712 
00720     bool isUpperTriangular() const;
00721 
00723     bool isLocallyIndexed() const;
00724 
00726     bool isGloballyIndexed() const;
00727 
00729     bool isFillComplete() const;
00730 
00732     bool isFillActive() const;
00733 
00741     bool isSorted() const;
00742 
00744 
00750     bool isStorageOptimized() const;
00751 
00753     ProfileType getProfileType() const;
00754 
00760     void
00761     getGlobalRowCopy (GlobalOrdinal GlobalRow,
00762                       const Teuchos::ArrayView<GlobalOrdinal>& Indices,
00763                       size_t& NumIndices) const;
00764 
00772     void
00773     getLocalRowCopy (LocalOrdinal LocalRow,
00774                      const Teuchos::ArrayView<LocalOrdinal>& indices,
00775                      size_t& NumIndices) const;
00776 
00778 
00786     void
00787     getGlobalRowView (GlobalOrdinal GlobalRow,
00788                       Teuchos::ArrayView<const GlobalOrdinal>& Indices) const;
00789 
00791 
00799     void
00800     getLocalRowView (LocalOrdinal LocalRow,
00801                      Teuchos::ArrayView<const LocalOrdinal>& indices) const;
00802 
00804 
00805 
00806 
00808     std::string description() const;
00809 
00811     void
00812     describe (Teuchos::FancyOStream& out,
00813               const Teuchos::EVerbosityLevel verbLevel =
00814               Teuchos::Describable::verbLevel_default) const;
00815 
00817 
00818 
00819 
00820     virtual bool
00821     checkSizes (const SrcDistObject& source);
00822 
00823     virtual void
00824     copyAndPermute (const SrcDistObject& source,
00825                     size_t numSameIDs,
00826                     const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
00827                     const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs);
00828 
00829     virtual void
00830     packAndPrepare (const SrcDistObject& source,
00831                     const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
00832                     Teuchos::Array<GlobalOrdinal> &exports,
00833                     const Teuchos::ArrayView<size_t> & numPacketsPerLID,
00834                     size_t& constantNumPackets,
00835                     Distributor &distor);
00836 
00837     virtual void
00838     pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
00839           Teuchos::Array<GlobalOrdinal>& exports,
00840           const Teuchos::ArrayView<size_t>& numPacketsPerLID,
00841           size_t& constantNumPackets,
00842           Distributor& distor) const;
00843 
00844     virtual void
00845     unpackAndCombine (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
00846                       const Teuchos::ArrayView<const GlobalOrdinal> &imports,
00847                       const Teuchos::ArrayView<size_t> &numPacketsPerLID,
00848                       size_t constantNumPackets,
00849                       Distributor &distor,
00850                       CombineMode CM);
00852 
00853 
00854 
00877     void
00878     getNumEntriesPerLocalRowUpperBound (Teuchos::ArrayRCP<const size_t>& boundPerLocalRow,
00879                                         size_t& boundForAllLocalRows,
00880                                         bool& boundSameForAllLocalRows) const;
00881 
00890     void
00891     setAllIndices (const t_RowPtrs & rowPointers,
00892                    const t_LocalOrdinal_1D & columnIndices);
00893 
00902     void
00903     setAllIndices (const Teuchos::ArrayRCP<size_t> & rowPointers,
00904                    const Teuchos::ArrayRCP<LocalOrdinal> & columnIndices);
00905 
00907 
00910     Teuchos::ArrayRCP<const size_t> getNodeRowPtrs() const;
00911 
00913 
00915     Teuchos::ArrayRCP<const LocalOrdinal> getNodePackedIndices() const;
00916 
00927     void replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
00928 
00948     void
00949     reindexColumns (const Teuchos::RCP<const map_type>& newColMap,
00950                     const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
00951                     const bool sortIndicesInEachRow = true);
00952 
00965     void
00966     replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
00967                                  const Teuchos::RCP<const import_type>& newImporter);
00968 
00996     virtual void
00997     removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
00999 
01000     template<class ViewType, class OffsetViewType >
01001     struct pack_functor {
01002       typedef typename ViewType::device_type device_type;
01003       ViewType src;
01004       ViewType dest;
01005       OffsetViewType src_offset;
01006       OffsetViewType dest_offset;
01007       typedef typename OffsetViewType::non_const_value_type ScalarIndx;
01008 
01009       pack_functor(ViewType dest_, ViewType src_, OffsetViewType dest_offset_, OffsetViewType src_offset_):
01010         src(src_),dest(dest_),src_offset(src_offset_),dest_offset(dest_offset_) {};
01011 
01012       KOKKOS_INLINE_FUNCTION
01013       void operator() (size_t row) const {
01014         ScalarIndx i = src_offset(row);
01015         ScalarIndx j = dest_offset(row);
01016         const ScalarIndx k = dest_offset(row+1);
01017         for(;j<k;j++,i++) {
01018           dest(j) = src(i);
01019         }
01020       }
01021     };
01022 
01023   protected:
01024     // these structs are conveniences, to cut down on the number of
01025     // arguments to some of the methods below.
01026     struct SLocalGlobalViews {
01027       Teuchos::ArrayView<const GlobalOrdinal> ginds;
01028       Teuchos::ArrayView<const LocalOrdinal>  linds;
01029     };
01030     struct SLocalGlobalNCViews {
01031       Teuchos::ArrayView<GlobalOrdinal>       ginds;
01032       Teuchos::ArrayView<LocalOrdinal>        linds;
01033     };
01034 
01035     bool indicesAreAllocated () const;
01036     void allocateIndices (const ELocalGlobal lg);
01037 
01038     template <class T>
01039     Teuchos::ArrayRCP<T> allocateValues1D () const {
01040       // FIXME (mfh 05 Aug 2014) This method only exists here to
01041       // placate the ETI macros for Kokkos classic.
01042       return Teuchos::null;
01043     }
01044 
01045     template <class T>
01046     Teuchos::ArrayRCP<Teuchos::Array<T> > allocateValues2D () const;
01047 
01048     template <class T>
01049     RowInfo updateLocalAllocAndValues (const RowInfo rowInfo,
01050                                        const size_t newAllocSize,
01051                                        Teuchos::Array<T>& rowVals)
01052     {
01053 #ifdef HAVE_TPETRA_DEBUG
01054       TEUCHOS_TEST_FOR_EXCEPT( ! isLocallyIndexed () );
01055       TEUCHOS_TEST_FOR_EXCEPT( ! indicesAreAllocated() );
01056       TEUCHOS_TEST_FOR_EXCEPT( newAllocSize == 0 );
01057       TEUCHOS_TEST_FOR_EXCEPT( newAllocSize < rowInfo.allocSize );
01058       TEUCHOS_TEST_FOR_EXCEPT( ! rowMap_->isNodeLocalElement (rowInfo.localRow) );
01059 #endif // HAVE_TPETRA_DEBUG
01060 
01061       // Teuchos::ArrayRCP::resize automatically copies over values on reallocation.
01062       lclInds2D_[rowInfo.localRow].resize (newAllocSize);
01063       rowVals.resize (newAllocSize);
01064       nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
01065 
01066       RowInfo rowInfoOut = rowInfo;
01067       rowInfoOut.allocSize = newAllocSize;
01068       return rowInfoOut;
01069     }
01070 
01071     template <class T>
01072     RowInfo
01073     updateGlobalAllocAndValues (const RowInfo rowInfo,
01074                                 const size_t newAllocSize,
01075                                 Teuchos::Array<T>& rowVals)
01076     {
01077 #ifdef HAVE_TPETRA_DEBUG
01078       TEUCHOS_TEST_FOR_EXCEPT( ! isGloballyIndexed () );
01079       TEUCHOS_TEST_FOR_EXCEPT( ! indicesAreAllocated () );
01080       TEUCHOS_TEST_FOR_EXCEPT( newAllocSize == 0 );
01081       TEUCHOS_TEST_FOR_EXCEPT( newAllocSize < rowInfo.allocSize );
01082       TEUCHOS_TEST_FOR_EXCEPT( ! rowMap_->isNodeLocalElement (rowInfo.localRow) );
01083 #endif // HAVE_TPETRA_DEBUG
01084 
01085       // Teuchos::ArrayRCP::resize automatically copies over values on reallocation.
01086       gblInds2D_[rowInfo.localRow].resize (newAllocSize);
01087       rowVals.resize (newAllocSize);
01088       nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
01089 
01090       RowInfo rowInfoOut = rowInfo;
01091       rowInfoOut.allocSize = newAllocSize;
01092       return rowInfoOut;
01093     }
01094 
01096 
01097 
01099     void makeColMap ();
01100     void makeIndicesLocal ();
01101     void makeImportExport ();
01102 
01104 
01105 
01106 
01107     template<ELocalGlobal lg>
01108     size_t filterIndices (const SLocalGlobalNCViews& inds) const
01109     {
01110       using Teuchos::ArrayView;
01111       Teuchos::CompileTimeAssert<lg != GlobalIndices && lg != LocalIndices> cta_lg;
01112       (void)cta_lg;
01113 
01114       const map_type& cmap = *colMap_;
01115       size_t numFiltered = 0;
01116 #ifdef HAVE_TPETRA_DEBUG
01117       size_t numFiltered_debug = 0;
01118 #endif
01119       if (lg == GlobalIndices) {
01120         ArrayView<GlobalOrdinal> ginds = inds.ginds;
01121         typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin();
01122         typename ArrayView<GlobalOrdinal>::iterator cptr = ginds.begin();
01123         while (cptr != ginds.end()) {
01124           if (cmap.isNodeGlobalElement(*cptr)) {
01125             *fend++ = *cptr;
01126 #ifdef HAVE_TPETRA_DEBUG
01127             ++numFiltered_debug;
01128 #endif
01129           }
01130           ++cptr;
01131         }
01132         numFiltered = fend - ginds.begin();
01133       }
01134       else if (lg == LocalIndices) {
01135         ArrayView<LocalOrdinal> linds = inds.linds;
01136         typename ArrayView<LocalOrdinal>::iterator fend = linds.begin();
01137         typename ArrayView<LocalOrdinal>::iterator cptr = linds.begin();
01138         while (cptr != linds.end()) {
01139           if (cmap.isNodeLocalElement(*cptr)) {
01140             *fend++ = *cptr;
01141 #ifdef HAVE_TPETRA_DEBUG
01142             ++numFiltered_debug;
01143 #endif
01144           }
01145           ++cptr;
01146         }
01147         numFiltered = fend - linds.begin();
01148       }
01149 #ifdef HAVE_TPETRA_DEBUG
01150       TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
01151 #endif
01152       return numFiltered;
01153     }
01154 
01155 
01156     template<class T>
01157     size_t
01158     filterGlobalIndicesAndValues (const Teuchos::ArrayView<GlobalOrdinal>& ginds,
01159                                   const Teuchos::ArrayView<T>& vals) const
01160     {
01161       using Teuchos::ArrayView;
01162       const map_type& cmap = *colMap_;
01163       size_t numFiltered = 0;
01164       typename ArrayView<T>::iterator fvalsend = vals.begin();
01165       typename ArrayView<T>::iterator valscptr = vals.begin();
01166 #ifdef HAVE_TPETRA_DEBUG
01167       size_t numFiltered_debug = 0;
01168 #endif
01169       typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin();
01170       typename ArrayView<GlobalOrdinal>::iterator cptr = ginds.begin();
01171       while (cptr != ginds.end()) {
01172         if (cmap.isNodeGlobalElement (*cptr)) {
01173           *fend++ = *cptr;
01174           *fvalsend++ = *valscptr;
01175 #ifdef HAVE_TPETRA_DEBUG
01176           ++numFiltered_debug;
01177 #endif
01178         }
01179         ++cptr;
01180         ++valscptr;
01181       }
01182       numFiltered = fend - ginds.begin();
01183 #ifdef HAVE_TPETRA_DEBUG
01184       TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
01185       TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
01186       const size_t numFilteredActual =
01187         static_cast<size_t> (fvalsend - vals.begin ());
01188       TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
01189 #endif // HAVE_TPETRA_DEBUG
01190       return numFiltered;
01191     }
01192 
01193     template<class T>
01194     size_t
01195     filterLocalIndicesAndValues (const Teuchos::ArrayView<LocalOrdinal>& linds,
01196                                  const Teuchos::ArrayView<T>& vals) const
01197     {
01198       using Teuchos::ArrayView;
01199       const map_type& cmap = *colMap_;
01200       size_t numFiltered = 0;
01201       typename ArrayView<T>::iterator fvalsend = vals.begin();
01202       typename ArrayView<T>::iterator valscptr = vals.begin();
01203 #ifdef HAVE_TPETRA_DEBUG
01204       size_t numFiltered_debug = 0;
01205 #endif
01206       typename ArrayView<LocalOrdinal>::iterator fend = linds.begin();
01207       typename ArrayView<LocalOrdinal>::iterator cptr = linds.begin();
01208       while (cptr != linds.end()) {
01209         if (cmap.isNodeLocalElement (*cptr)) {
01210           *fend++ = *cptr;
01211           *fvalsend++ = *valscptr;
01212 #ifdef HAVE_TPETRA_DEBUG
01213           ++numFiltered_debug;
01214 #endif
01215         }
01216         ++cptr;
01217         ++valscptr;
01218       }
01219       numFiltered = fend - linds.begin();
01220 #ifdef HAVE_TPETRA_DEBUG
01221       TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
01222       TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
01223       const size_t numFilteredActual =
01224         Teuchos::as<size_t> (fvalsend - vals.begin ());
01225       TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
01226 #endif
01227       return numFiltered;
01228     }
01229 
01259     size_t
01260     insertIndices (const RowInfo& rowInfo,
01261                    const SLocalGlobalViews& newInds,
01262                    const ELocalGlobal lg,
01263                    const ELocalGlobal I);
01264 
01304     template<class Scalar>
01305     void
01306     insertIndicesAndValues (const RowInfo& rowInfo,
01307                             const SLocalGlobalViews& newInds,
01308                             const Teuchos::ArrayView<Scalar>& oldRowVals,
01309                             const Teuchos::ArrayView<const Scalar>& newRowVals,
01310                             const ELocalGlobal lg,
01311                             const ELocalGlobal I);
01312     void
01313     insertGlobalIndicesImpl (const LocalOrdinal myRow,
01314                              const Teuchos::ArrayView<const GlobalOrdinal> &indices);
01315     void
01316     insertLocalIndicesImpl (const LocalOrdinal myRow,
01317                             const Teuchos::ArrayView<const LocalOrdinal> &indices);
01319     void
01320     insertLocalIndicesFiltered (const LocalOrdinal localRow,
01321                                 const Teuchos::ArrayView<const LocalOrdinal> &indices);
01322 
01324     void
01325     insertGlobalIndicesFiltered (const GlobalOrdinal localRow,
01326                                  const Teuchos::ArrayView<const GlobalOrdinal> &indices);
01327 
01355     template<class Scalar, class BinaryFunction>
01356     LocalOrdinal
01357     transformLocalValues (RowInfo rowInfo,
01358                           const Teuchos::ArrayView<Scalar>& rowVals,
01359                           const Teuchos::ArrayView<const LocalOrdinal>& inds,
01360                           const Teuchos::ArrayView<const Scalar>& newVals,
01361                           BinaryFunction f) const
01362     {
01363       typedef typename Teuchos::ArrayView<Scalar>::size_type size_type;
01364       const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid ();
01365       const size_type numElts = inds.size ();
01366       size_t hint = 0; // Guess for the current index k into rowVals
01367 
01368       // Get a view of the column indices in the row.  This amortizes
01369       // the cost of getting the view over all the entries of inds.
01370       Teuchos::ArrayView<const LocalOrdinal> colInds = getLocalView (rowInfo);
01371 
01372       LocalOrdinal numValid = 0; // number of valid local column indices
01373       for (size_type j = 0; j < numElts; ++j) {
01374         const size_t k = findLocalIndex (rowInfo, inds[j], colInds, hint);
01375         if (k != STINV) {
01376           rowVals[k] = f (rowVals[k], newVals[j]); // use binary function f
01377           hint = k+1;
01378           ++numValid;
01379         }
01380       }
01381       return numValid;
01382     }
01383 
01403     template<class Scalar, class BinaryFunction>
01404     LocalOrdinal
01405     transformGlobalValues (RowInfo rowInfo,
01406                            const Teuchos::ArrayView<Scalar>& rowVals,
01407                            const Teuchos::ArrayView<const GlobalOrdinal>& inds,
01408                            const Teuchos::ArrayView<const Scalar>& newVals,
01409                            BinaryFunction f) const
01410     {
01411       typedef typename Teuchos::ArrayView<Scalar>::size_type size_type;
01412       const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid ();
01413       const size_type numElts = inds.size ();
01414       size_t hint = 0; // guess at the index's relative offset in the row
01415 
01416       LocalOrdinal numValid = 0; // number of valid local column indices
01417       for (size_type j = 0; j < numElts; ++j) {
01418         const size_t k = findGlobalIndex (rowInfo, inds[j], hint);
01419         if (k != STINV) {
01420           rowVals[k] = f (rowVals[k], newVals[j]); // use binary function f
01421           hint = k+1;
01422           numValid++;
01423         }
01424       }
01425       return numValid;
01426     }
01427 
01429 
01430 
01431 
01433     bool isMerged () const;
01434 
01440     void setLocallyModified ();
01441 
01443     void sortAllIndices ();
01444 
01446     void sortRowIndices (const RowInfo rowinfo);
01447 
01462     template <class Scalar>
01463     void sortRowIndicesAndValues (const RowInfo rowinfo,
01464                                   const Teuchos::ArrayView<Scalar>& values);
01465 
01474     void mergeAllIndices ();
01475 
01480     void mergeRowIndices (RowInfo rowinfo);
01481 
01492     template<class Scalar>
01493     void
01494     mergeRowIndicesAndValues (RowInfo rowinfo,
01495                               const Teuchos::ArrayView<Scalar>& rowValues);
01497 
01507     void
01508     setDomainRangeMaps (const Teuchos::RCP<const map_type>& domainMap,
01509                         const Teuchos::RCP<const map_type>& rangeMap);
01510 
01511     void staticAssertions() const;
01512     void clearGlobalConstants();
01513     void computeGlobalConstants();
01514 
01517     RowInfo getRowInfo (const size_t myRow) const;
01518 
01522     Teuchos::ArrayView<const LocalOrdinal>
01523     getLocalView (const RowInfo rowinfo) const;
01524 
01528     Teuchos::ArrayView<LocalOrdinal>
01529     getLocalViewNonConst (const RowInfo rowinfo);
01530 
01534     Teuchos::ArrayView<const GlobalOrdinal>
01535     getGlobalView (const RowInfo rowinfo) const;
01536 
01540     Teuchos::ArrayView<GlobalOrdinal>
01541     getGlobalViewNonConst (const RowInfo rowinfo);
01542 
01577     size_t
01578     findLocalIndex (RowInfo rowinfo,
01579                     LocalOrdinal ind,
01580                     size_t hint = 0) const;
01581 
01610     size_t
01611     findLocalIndex (RowInfo rowinfo,
01612                     LocalOrdinal ind,
01613                     Teuchos::ArrayView<const LocalOrdinal> colInds,
01614                     size_t hint = 0) const;
01615 
01624     size_t findGlobalIndex (RowInfo rowinfo, GlobalOrdinal ind, size_t hint = 0) const;
01625 
01630     LocalStaticCrsGraphType getLocalGraph_Kokkos () const;
01631 
01632     void fillLocalGraph (const Teuchos::RCP<Teuchos::ParameterList>& params);
01633 
01635     bool hasRowInfo () const;
01636 
01638     void checkInternalState () const;
01639 
01641     Teuchos::RCP<const map_type> rowMap_;
01643     Teuchos::RCP<const map_type> colMap_;
01645     Teuchos::RCP<const map_type> rangeMap_;
01647     Teuchos::RCP<const map_type> domainMap_;
01648 
01655     Teuchos::RCP<const import_type> importer_;
01656 
01662     Teuchos::RCP<const export_type> exporter_;
01663 
01665     LocalStaticCrsGraphType k_lclGraph_;
01666 
01667     // Local and Global Counts
01668     // nodeNumEntries_ and nodeNumAllocated_ are required to be always consistent
01669     // nodeMaxNumEntries_, nodeNumDiags_ and the global quantities are computed during fillComplete() and only valid when isFillComplete()
01670     global_size_t globalNumEntries_, globalNumDiags_, globalMaxNumRowEntries_;
01671     size_t          nodeNumEntries_,   nodeNumDiags_,   nodeMaxNumRowEntries_, nodeNumAllocated_;
01672 
01674     ProfileType pftype_;
01675 
01695     Kokkos::DualView<const size_t*, Kokkos::LayoutLeft, device_type> k_numAllocPerRow_;
01696 
01703     Teuchos::ArrayRCP<const size_t> numAllocPerRow_;
01704 
01715     size_t numAllocForAllRows_;
01716 
01718 
01719 
01727     t_LocalOrdinal_1D k_lclInds1D_;
01728 
01730     typedef Kokkos::View<GlobalOrdinal*, device_type> t_GlobalOrdinal_1D;
01731 
01739     t_GlobalOrdinal_1D k_gblInds1D_;
01740 
01746     Teuchos::ArrayRCP<GlobalOrdinal> gblInds1D_;
01747 
01775     t_RowPtrs k_rowPtrs_;
01776 
01778 
01779 
01780 
01781 
01782 
01783 
01784 
01785 
01786 
01787 
01788 
01789 
01790 
01802     Teuchos::ArrayRCP<Teuchos::Array<LocalOrdinal> > lclInds2D_;
01803 
01815     Teuchos::ArrayRCP<Teuchos::Array<GlobalOrdinal> > gblInds2D_;
01816 
01817     typedef Kokkos::DualView<size_t*, Kokkos::LayoutLeft, device_type> t_numRowEntries_;
01818 
01825     t_numRowEntries_ k_numRowEntries_;
01826 
01835     Teuchos::ArrayRCP<size_t> numRowEntries_;
01836 
01838 
01848     Details::EStorageStatus storageStatus_;
01849 
01850     bool indicesAreAllocated_;
01851     bool indicesAreLocal_;
01852     bool indicesAreGlobal_;
01853     bool fillComplete_;
01854 
01856     bool lowerTriangular_;
01858     bool upperTriangular_;
01860     bool indicesAreSorted_;
01863     bool noRedundancies_;
01865     bool haveLocalConstants_;
01867     bool haveGlobalConstants_;
01868 
01870     std::map<GlobalOrdinal, std::vector<GlobalOrdinal> > nonlocals_;
01871 
01886     bool sortGhostsAssociatedWithEachProcessor_;
01887 
01888   }; // class CrsGraph
01889 
01890 } // namespace Tpetra
01891 
01892 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines