Epetra Package Browser (Single Doxygen Collection) Development
Epetra_CrsGraph.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2011 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_CRSGRAPH_H
00045 #define EPETRA_CRSGRAPH_H
00046 
00047 #include "Epetra_ConfigDefs.h"
00048 #include "Epetra_DistObject.h" 
00049 #include "Epetra_CrsGraphData.h"
00050 class Epetra_BlockMap;
00051 class Epetra_Util;
00052 class Epetra_Time;
00053 class Epetra_Import;
00054 class Epetra_Export;
00055 class Epetra_Distributor;
00056 class Epetra_RowMatrix;
00057 
00059 
00213 class EPETRA_LIB_DLL_EXPORT Epetra_CrsGraph: public Epetra_DistObject {
00214       
00215  public:
00216 
00218 
00219 
00220 
00232   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, const int* NumIndicesPerRow, bool StaticProfile = false);
00233   
00235 
00248   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, int NumIndicesPerRow, bool StaticProfile = false);
00249   
00251 
00265   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, 
00266       const Epetra_BlockMap& ColMap, const int* NumIndicesPerRow, bool StaticProfile = false);
00267   
00269 
00285   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, 
00286       const Epetra_BlockMap& ColMap, int NumIndicesPerRow, bool StaticProfile = false);
00287   
00289 
00292   Epetra_CrsGraph(const Epetra_CrsGraph& Graph);
00293 
00295   virtual ~Epetra_CrsGraph();
00297   
00299 
00300 
00301 
00315   int InsertGlobalIndices(int GlobalRow, int NumIndices, int* Indices);
00316   
00318 
00327   int RemoveGlobalIndices(int GlobalRow, int NumIndices, int* Indices);
00328   
00330 
00337   int RemoveGlobalIndices(int Row);
00338 
00339   
00341 
00356   int InsertMyIndices(int LocalRow, int NumIndices, int* Indices);
00357   
00359 
00368   int RemoveMyIndices(int LocalRow, int NumIndices, int* Indices);
00369   
00371 
00378   int RemoveMyIndices(int Row);
00380 
00382 
00383   
00385 
00392   int FillComplete();
00393 
00395 
00407   int FillComplete(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00408 
00410 
00424   int OptimizeStorage();
00425 
00427 
00429 
00430 
00432 
00440   int ExtractGlobalRowCopy(int GlobalRow, int LenOfIndices, int& NumIndices, int* Indices) const;
00441 
00443 
00453   int ExtractMyRowCopy(int LocalRow, int LenOfIndices, int& NumIndices, int* Indices) const;
00454 
00456 
00466   int ExtractGlobalRowView(int GlobalRow, int& NumIndices, int*& Indices) const;
00467 
00469 
00479   int ExtractMyRowView(int LocalRow, int& NumIndices, int*& Indices) const;
00481 
00483 
00484 
00485   bool Filled() const {return(CrsGraphData_->Filled_);}
00486   
00488   bool StorageOptimized() const {return(CrsGraphData_->StorageOptimized_);}
00489   
00491   bool IndicesAreGlobal() const {return(CrsGraphData_->IndicesAreGlobal_);}
00492   
00494   bool IndicesAreLocal() const {return(CrsGraphData_->IndicesAreLocal_);}
00495   
00497 
00500   bool LowerTriangular() const {return(CrsGraphData_->LowerTriangular_);}
00501   
00503 
00506   bool UpperTriangular() const {return(CrsGraphData_->UpperTriangular_);}
00507   
00509 
00512   bool NoDiagonal() const {return(CrsGraphData_->NoDiagonal_);}
00513   
00515   bool MyGlobalRow(int GID) const {return(RowMap().MyGID(GID));}
00516 
00518 
00522   bool HaveColMap() const {return(CrsGraphData_->HaveColMap_);}
00524   
00526 
00527     
00529   int NumMyRows() const {return(CrsGraphData_->NumMyRows_);}
00530   
00532   int NumGlobalRows() const {return(CrsGraphData_->NumGlobalRows_);}
00533   
00535 
00539   int NumMyCols() const {return(CrsGraphData_->NumMyCols_);}
00540   
00542 
00545   int NumGlobalCols() const {return(CrsGraphData_->NumGlobalCols_);}
00546   
00548 
00554   int NumGlobalNonzeros() const {return(CrsGraphData_->NumGlobalNonzeros_);}
00555   
00557 
00560   int NumGlobalDiagonals() const {return(CrsGraphData_->NumGlobalDiagonals_);}
00561   
00563 
00566   int NumMyDiagonals() const {return(CrsGraphData_->NumMyDiagonals_);}
00567   
00569   int NumMyBlockRows() const {return(CrsGraphData_->NumMyBlockRows_);}
00570   
00572   int NumGlobalBlockRows() const {return(CrsGraphData_->NumGlobalBlockRows_);}
00573   
00575 
00578   int NumMyBlockCols() const {return(CrsGraphData_->NumMyBlockCols_);}
00579   
00581 
00584   int NumGlobalBlockCols() const {return(CrsGraphData_->NumGlobalBlockCols_);}
00585   
00587 
00590   int NumMyBlockDiagonals() const {return(CrsGraphData_->NumMyBlockDiagonals_);}
00591   
00593 
00596   int NumGlobalBlockDiagonals() const {return(CrsGraphData_->NumGlobalBlockDiagonals_);}
00597   
00599 
00602   int NumGlobalEntries() const {return(CrsGraphData_->NumGlobalEntries_);}
00603   
00605 
00608   int NumMyEntries() const {return(CrsGraphData_->NumMyEntries_);}
00610 
00613   int MaxRowDim() const {return(CrsGraphData_->MaxRowDim_);}
00614   
00616 
00619   int GlobalMaxRowDim() const {return(CrsGraphData_->GlobalMaxRowDim_);}
00620   
00622 
00625   int MaxColDim() const {return(CrsGraphData_->MaxColDim_);}
00626   
00628 
00631   int GlobalMaxColDim() const {return(CrsGraphData_->GlobalMaxColDim_);}
00632   
00634 
00637   int NumMyNonzeros() const {return(CrsGraphData_->NumMyNonzeros_);}
00638   
00640   int NumGlobalIndices(int Row) const;
00641   
00643   int NumAllocatedGlobalIndices(int Row) const;
00644   
00646 
00649   int MaxNumIndices() const {return(CrsGraphData_->MaxNumIndices_);}
00650   
00652 
00655   int GlobalMaxNumIndices() const {return(CrsGraphData_->GlobalMaxNumIndices_);}
00656   
00658 
00667   int MaxNumNonzeros() const {return(CrsGraphData_->MaxNumNonzeros_);}
00668   
00670 
00674   int GlobalMaxNumNonzeros() const {return(CrsGraphData_->GlobalMaxNumNonzeros_);}
00675   
00677   int NumMyIndices(int Row) const {if (Row<0 || Row >= NumMyRows()) return(0);
00678     if (StorageOptimized()) return(CrsGraphData_->IndexOffset_[Row+1] - CrsGraphData_->IndexOffset_[Row]); 
00679     else return(CrsGraphData_->NumIndicesPerRow_[Row]);}
00680   
00682   int NumAllocatedMyIndices(int Row) const {if (Row<0 || Row >= NumMyRows()) return(0);
00683     if (StorageOptimized()) return(CrsGraphData_->IndexOffset_[Row+1] - CrsGraphData_->IndexOffset_[Row]); 
00684     else return(CrsGraphData_->NumAllocatedIndicesPerRow_[Row]);}
00685   
00687   int IndexBase() const {return(CrsGraphData_->IndexBase_);}
00688   
00690   const Epetra_BlockMap& RowMap() const {return(Epetra_DistObject::Map());}
00691     
00698   int ReplaceRowMap(const Epetra_BlockMap& newmap);
00699 
00708   int ReplaceColMap(const Epetra_BlockMap& newmap);
00709 
00711 
00714   const Epetra_BlockMap& ColMap() const {return(CrsGraphData_->ColMap_);}
00715   
00717 
00720   const Epetra_BlockMap& DomainMap() const {return(CrsGraphData_->DomainMap_);}
00721   
00723 
00726   const Epetra_BlockMap& RangeMap() const {return(CrsGraphData_->RangeMap_);}
00727   
00729   const Epetra_Import* Importer() const {return(CrsGraphData_->Importer_);}
00730   
00732   const Epetra_Export* Exporter() const {return(CrsGraphData_->Exporter_);}
00733   
00735   const Epetra_Comm& Comm() const {return(Epetra_DistObject::Comm());}
00737   
00739 
00740 
00742   int LRID(int GRID_in) const {return(RowMap().LID(GRID_in));}
00743   
00745   int GRID(int LRID_in) const {return(RowMap().GID(LRID_in));}
00746   
00748 
00751   int LCID(int GCID_in) const
00752     {
00753       return( CrsGraphData_->HaveColMap_ ? ColMap().LID(GCID_in) : -1 );
00754     }
00755   
00757 
00760   int GCID(int LCID_in) const
00761     {
00762       return( CrsGraphData_->HaveColMap_ ? ColMap().GID(LCID_in) : -1 );
00763     }
00764   
00766   bool MyGRID(int GRID_in) const {return(LRID(GRID_in) != -1);}
00767   
00769   bool MyLRID(int LRID_in) const {return(GRID(LRID_in) != IndexBase() - 1);}
00770   
00772 
00775   bool MyGCID(int GCID_in) const {return(LCID(GCID_in) != -1);}
00776   
00778 
00781   bool MyLCID(int LCID_in) const {return(GCID(LCID_in) != IndexBase() - 1);}
00783   
00785 
00786   
00788 
00794   inline int*  operator[]( int Loc ) { 
00795     if (StorageOptimized()){ return(CrsGraphData_->All_Indices_.Values() + CrsGraphData_->IndexOffset_[Loc]);}
00796     else return(CrsGraphData_->Indices_[Loc]); }
00797 
00798   inline int* operator[]( int Loc ) const { 
00799     if (StorageOptimized()) { return(CrsGraphData_->All_Indices_.Values() +CrsGraphData_->IndexOffset_[Loc]);}
00800     else return(CrsGraphData_->Indices_[Loc]); }
00801 
00803 
00805 
00808   Epetra_CrsGraph& operator = (const Epetra_CrsGraph& Source);
00809 
00811 
00812 
00814   virtual void Print(ostream& os) const;
00815 
00816   void PrintGraphData(ostream& os) const {CrsGraphData_->Print(os);}
00817   void PrintGraphData(ostream& os, int level) const {CrsGraphData_->Print(os, level);}
00819 
00821 
00822 
00824   const Epetra_BlockMap& ImportMap() const {return(CrsGraphData_->ColMap_);}
00825   
00827   int TransformToLocal();
00828   
00830   int TransformToLocal(const Epetra_BlockMap* DomainMap, const Epetra_BlockMap* RangeMap);
00831   
00833 
00835 
00836 
00838 
00839   int ReferenceCount() const {return(CrsGraphData_->ReferenceCount());}
00840 
00842 
00843   const Epetra_CrsGraphData* DataPtr() const {return(CrsGraphData_);}
00844 
00846 
00855         void SortGhostsAssociatedWithEachProcessor(bool Flag) {CrsGraphData_->SortGhostsAssociatedWithEachProcessor_ = Flag;}
00856 
00858 
00859   // functions listed in protected are the ones used by CrsMatrix and VbrMatrix.
00860   // functions listed in private are the ones that are really private.
00861   // (just pretend CrsMatrix and VbrMatrix derive from CrsGraph to understand the distinction.)
00862   friend class Epetra_CrsMatrix;
00863   friend class Epetra_VbrMatrix;
00864   friend class Epetra_FECrsGraph;
00865   friend class Epetra_FECrsMatrix;
00866   friend class Epetra_FEVbrMatrix;
00867   friend class Epetra_OffsetIndex;
00868 
00869  protected:
00870   int *All_Indices() const {
00871     if (!StorageOptimized()) throw ReportError("This method: int *All_Indices() cannot be called when StorageOptimized()==false", -1);
00872     else return(CrsGraphData_->All_Indices_.Values());}
00873   int *IndexOffset() const {
00874     if (!StorageOptimized()) throw ReportError("This method: int *IndexOffset()  cannot be called when StorageOptimized()==false", -1);
00875     else return(CrsGraphData_->IndexOffset_.Values());}
00876   int* NumIndicesPerRow() const {
00877     if (StorageOptimized()) throw ReportError("This method: int* NumIndicesPerRow() cannot be called when StorageOptimized()==true", -1);
00878     else return(CrsGraphData_->NumIndicesPerRow_.Values());}
00879   int* NumAllocatedIndicesPerRow() const {
00880     if (StorageOptimized()) throw ReportError("This method: int* NumAllocatedIndicesPerRow() cannot be called when StorageOptimized()==true", -1);
00881     else return(CrsGraphData_->NumAllocatedIndicesPerRow_.Values());}
00882   int** Indices() const {
00883     if (StorageOptimized()) throw ReportError("This method: int** Indices() cannot be called when StorageOptimized()==true", -1);
00884     else return(CrsGraphData_->Indices_);}
00885   int* Indices(int LocalRow) const {
00886     if (StorageOptimized()) return(CrsGraphData_->All_Indices_.Values()+CrsGraphData_->IndexOffset_[LocalRow]);
00887     else return(CrsGraphData_->Indices_[LocalRow]);}
00888   // If column indices are stored in one long array (via a call to OptimizeStorage), 
00889   // IndicesAreContiguous returns true, otherwise it returns false.
00890   bool IndicesAreContiguous() const {return(CrsGraphData_->IndicesAreContiguous_);}
00891   bool StaticProfile() const {return(CrsGraphData_->StaticProfile_);}
00892   bool GlobalConstantsComputed() const;
00893   bool FindGlobalIndexLoc(int LocalRow, int Index, int Start, int& Loc) const;
00894   bool FindGlobalIndexLoc(int NumIndices, const int* Indices, int Index, int Start, int& Loc) const;
00895   bool FindMyIndexLoc(int LocalRow, int Index, int Start, int& Loc) const;
00896   bool FindMyIndexLoc(int NumIndices, const int* Indices, int Index, int Start, int& Loc) const;
00897   int InsertIndices(int Row, int NumIndices, int* Indices);
00898   int InsertIndicesIntoSorted(int Row, int NumIndices, int* Indices);
00899   int MakeIndicesLocal(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00900   void SetIndicesAreLocal(bool Flag) {CrsGraphData_->IndicesAreLocal_ = Flag;}
00901   void SetIndicesAreGlobal(bool Flag) {CrsGraphData_->IndicesAreGlobal_ = Flag;}
00902   void SetSorted(bool Flag) {CrsGraphData_->Sorted_ = Flag;}
00903 
00904 
00906 
00909   int SortIndices();
00910 
00912   bool Sorted() const {return(CrsGraphData_->Sorted_);}
00913   
00915 
00918   int RemoveRedundantIndices();
00919   int DetermineTriangular();
00920 
00922   bool NoRedundancies() const {return(CrsGraphData_->NoRedundancies_);}
00923 
00924  private:
00925   void SetGlobalConstantsComputed(bool Flag) {CrsGraphData_->GlobalConstantsComputed_ = Flag;}
00926   void SetIndicesAreContiguous(bool Flag) {CrsGraphData_->IndicesAreContiguous_ = Flag;}
00927   void SetNoRedundancies(bool Flag) {CrsGraphData_->NoRedundancies_ = Flag;}
00928   void ComputeIndexState();
00929   int MakeColMap(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00930   int Allocate(const int* NumIndicesPerRow, int Inc, bool StaticProfile);
00931   //int ReAllocate();
00932   int ComputeGlobalConstants();
00933   void SetFilled(bool Flag) {CrsGraphData_->Filled_ = Flag;}
00934   bool Allocated() const {return(CrsGraphData_->Allocated_);}
00935   void SetAllocated(bool Flag) {CrsGraphData_->Allocated_ = Flag;}
00936   
00937   int CheckSizes(const Epetra_SrcDistObject& A);
00938 
00939   int CopyAndPermute(const Epetra_SrcDistObject& Source,
00940                            int NumSameIDs, 
00941                            int NumPermuteIDs,
00942                            int* PermuteToLIDs,
00943                            int* PermuteFromLIDs,
00944                            const Epetra_OffsetIndex * Indexor);
00945   int CopyAndPermuteRowMatrix(const Epetra_RowMatrix& A,
00946                                     int NumSameIDs, 
00947                                     int NumPermuteIDs,
00948                                     int* PermuteToLIDs,
00949                                     int* PermuteFromLIDs,
00950                                     const Epetra_OffsetIndex * Indexor);
00951   int CopyAndPermuteCrsGraph(const Epetra_CrsGraph& A,
00952                                    int NumSameIDs, 
00953                                    int NumPermuteIDs,
00954                                    int* PermuteToLIDs,
00955                                    int* PermuteFromLIDs,
00956                                    const Epetra_OffsetIndex * Indexor);
00957   
00958         int PackAndPrepare(const Epetra_SrcDistObject& Source,
00959                            int NumExportIDs,
00960                            int* ExportLIDs,
00961                            int& LenExports,
00962                            char*& Exports,
00963                            int& SizeOfPacket,
00964                            int * Sizes,
00965                            bool & VarSizes,
00966                            Epetra_Distributor& Distor);
00967         int PackAndPrepareCrsGraph(const Epetra_CrsGraph& A,
00968                                    int NumExportIDs,
00969                                    int* ExportLIDs,
00970                                    int& LenExports,
00971                                    char*& Exports,
00972                                    int& SizeOfPacket,
00973                                    int* Sizes,
00974                                    bool& VarSizes,
00975                                    Epetra_Distributor& Distor);
00976         int PackAndPrepareRowMatrix(const Epetra_RowMatrix& A,
00977                                     int NumExportIDs,
00978                                     int* ExportLIDs,
00979                                     int& LenExports,
00980                                     char*& Exports,
00981                                     int& SizeOfPacket,
00982                                     int* Sizes,
00983                                     bool& VarSizes,
00984                                     Epetra_Distributor& Distor);
00985 
00986         int UnpackAndCombine(const Epetra_SrcDistObject& Source,
00987                              int NumImportIDs,
00988                              int* ImportLIDs, 
00989                              int LenImports, 
00990                              char* Imports,
00991                              int& SizeOfPacket, 
00992                              Epetra_Distributor& Distor,
00993                              Epetra_CombineMode CombineMode,
00994                              const Epetra_OffsetIndex * Indexor);
00995 
00996   void CleanupData();
00997 
00998   Epetra_CrsGraphData* CrsGraphData_; 
00999 
01000 };
01001 #endif /* EPETRA_CRSGRAPH_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines