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 2001 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 
00706   int ReplaceColMap(const Epetra_BlockMap& newmap);
00707 
00709 
00712   const Epetra_BlockMap& ColMap() const {return(CrsGraphData_->ColMap_);}
00713   
00715 
00718   const Epetra_BlockMap& DomainMap() const {return(CrsGraphData_->DomainMap_);}
00719   
00721 
00724   const Epetra_BlockMap& RangeMap() const {return(CrsGraphData_->RangeMap_);}
00725   
00727   const Epetra_Import* Importer() const {return(CrsGraphData_->Importer_);}
00728   
00730   const Epetra_Export* Exporter() const {return(CrsGraphData_->Exporter_);}
00731   
00733   const Epetra_Comm& Comm() const {return(Epetra_DistObject::Comm());}
00735   
00737 
00738 
00740   int LRID(int GRID_in) const {return(RowMap().LID(GRID_in));}
00741   
00743   int GRID(int LRID_in) const {return(RowMap().GID(LRID_in));}
00744   
00746 
00749   int LCID(int GCID_in) const
00750     {
00751       return( CrsGraphData_->HaveColMap_ ? ColMap().LID(GCID_in) : -1 );
00752     }
00753   
00755 
00758   int GCID(int LCID_in) const
00759     {
00760       return( CrsGraphData_->HaveColMap_ ? ColMap().GID(LCID_in) : -1 );
00761     }
00762   
00764   bool MyGRID(int GRID_in) const {return(LRID(GRID_in) != -1);}
00765   
00767   bool MyLRID(int LRID_in) const {return(GRID(LRID_in) != IndexBase() - 1);}
00768   
00770 
00773   bool MyGCID(int GCID_in) const {return(LCID(GCID_in) != -1);}
00774   
00776 
00779   bool MyLCID(int LCID_in) const {return(GCID(LCID_in) != IndexBase() - 1);}
00781   
00783 
00784   
00786 
00792   inline int*  operator[]( int Loc ) { 
00793     if (StorageOptimized()){ return(CrsGraphData_->All_Indices_.Values() + CrsGraphData_->IndexOffset_[Loc]);}
00794     else return(CrsGraphData_->Indices_[Loc]); }
00795 
00796   inline int* operator[]( int Loc ) const { 
00797     if (StorageOptimized()) { return(CrsGraphData_->All_Indices_.Values() +CrsGraphData_->IndexOffset_[Loc]);}
00798     else return(CrsGraphData_->Indices_[Loc]); }
00799 
00801 
00803 
00806   Epetra_CrsGraph& operator = (const Epetra_CrsGraph& Source);
00807 
00809 
00810 
00812   virtual void Print(ostream& os) const;
00813 
00814   void PrintGraphData(ostream& os) const {CrsGraphData_->Print(os);}
00815   void PrintGraphData(ostream& os, int level) const {CrsGraphData_->Print(os, level);}
00817 
00819 
00820 
00822   const Epetra_BlockMap& ImportMap() const {return(CrsGraphData_->ColMap_);}
00823   
00825   int TransformToLocal();
00826   
00828   int TransformToLocal(const Epetra_BlockMap* DomainMap, const Epetra_BlockMap* RangeMap);
00829   
00831 
00833 
00834 
00836 
00837   int ReferenceCount() const {return(CrsGraphData_->ReferenceCount());}
00838 
00840 
00841   const Epetra_CrsGraphData* DataPtr() const {return(CrsGraphData_);}
00842 
00844 
00853         void SortGhostsAssociatedWithEachProcessor(bool Flag) {CrsGraphData_->SortGhostsAssociatedWithEachProcessor_ = Flag;}
00854 
00856 
00857   // functions listed in protected are the ones used by CrsMatrix and VbrMatrix.
00858   // functions listed in private are the ones that are really private.
00859   // (just pretend CrsMatrix and VbrMatrix derive from CrsGraph to understand the distinction.)
00860   friend class Epetra_CrsMatrix;
00861   friend class Epetra_VbrMatrix;
00862   friend class Epetra_FECrsGraph;
00863   friend class Epetra_FECrsMatrix;
00864   friend class Epetra_FEVbrMatrix;
00865   friend class Epetra_OffsetIndex;
00866 
00867  protected:
00868   int *All_Indices() const {
00869     if (!StorageOptimized()) throw ReportError("This method: int *All_Indices() cannot be called when StorageOptimized()==false", -1);
00870     else return(CrsGraphData_->All_Indices_.Values());}
00871   int *IndexOffset() const {
00872     if (!StorageOptimized()) throw ReportError("This method: int *IndexOffset()  cannot be called when StorageOptimized()==false", -1);
00873     else return(CrsGraphData_->IndexOffset_.Values());}
00874   int* NumIndicesPerRow() const {
00875     if (StorageOptimized()) throw ReportError("This method: int* NumIndicesPerRow() cannot be called when StorageOptimized()==true", -1);
00876     else return(CrsGraphData_->NumIndicesPerRow_.Values());}
00877   int* NumAllocatedIndicesPerRow() const {
00878     if (StorageOptimized()) throw ReportError("This method: int* NumAllocatedIndicesPerRow() cannot be called when StorageOptimized()==true", -1);
00879     else return(CrsGraphData_->NumAllocatedIndicesPerRow_.Values());}
00880   int** Indices() const {
00881     if (StorageOptimized()) throw ReportError("This method: int** Indices() cannot be called when StorageOptimized()==true", -1);
00882     else return(CrsGraphData_->Indices_);}
00883   int* Indices(int LocalRow) const {
00884     if (StorageOptimized()) return(CrsGraphData_->All_Indices_.Values()+CrsGraphData_->IndexOffset_[LocalRow]);
00885     else return(CrsGraphData_->Indices_[LocalRow]);}
00886   // If column indices are stored in one long array (via a call to OptimizeStorage), 
00887   // IndicesAreContiguous returns true, otherwise it returns false.
00888   bool IndicesAreContiguous() const {return(CrsGraphData_->IndicesAreContiguous_);}
00889   bool StaticProfile() const {return(CrsGraphData_->StaticProfile_);}
00890   bool GlobalConstantsComputed() const;
00891   bool FindGlobalIndexLoc(int LocalRow, int Index, int Start, int& Loc) const;
00892   bool FindGlobalIndexLoc(int NumIndices, const int* Indices, int Index, int Start, int& Loc) const;
00893   bool FindMyIndexLoc(int LocalRow, int Index, int Start, int& Loc) const;
00894   bool FindMyIndexLoc(int NumIndices, const int* Indices, int Index, int Start, int& Loc) const;
00895   int InsertIndices(int Row, int NumIndices, int* Indices);
00896   int InsertIndicesIntoSorted(int Row, int NumIndices, int* Indices);
00897   int MakeIndicesLocal(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00898   void SetIndicesAreLocal(bool Flag) {CrsGraphData_->IndicesAreLocal_ = Flag;}
00899   void SetIndicesAreGlobal(bool Flag) {CrsGraphData_->IndicesAreGlobal_ = Flag;}
00900   void SetSorted(bool Flag) {CrsGraphData_->Sorted_ = Flag;}
00901 
00902 
00904 
00907   int SortIndices();
00908 
00910   bool Sorted() const {return(CrsGraphData_->Sorted_);}
00911   
00913 
00916   int RemoveRedundantIndices();
00917   int DetermineTriangular();
00918 
00920   bool NoRedundancies() const {return(CrsGraphData_->NoRedundancies_);}
00921 
00922  private:
00923   void SetGlobalConstantsComputed(bool Flag) {CrsGraphData_->GlobalConstantsComputed_ = Flag;}
00924   void SetIndicesAreContiguous(bool Flag) {CrsGraphData_->IndicesAreContiguous_ = Flag;}
00925   void SetNoRedundancies(bool Flag) {CrsGraphData_->NoRedundancies_ = Flag;}
00926   void ComputeIndexState();
00927   int MakeColMap(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00928   int Allocate(const int* NumIndicesPerRow, int Inc, bool StaticProfile);
00929   //int ReAllocate();
00930   int ComputeGlobalConstants();
00931   void SetFilled(bool Flag) {CrsGraphData_->Filled_ = Flag;}
00932   bool Allocated() const {return(CrsGraphData_->Allocated_);}
00933   void SetAllocated(bool Flag) {CrsGraphData_->Allocated_ = Flag;}
00934   
00935   int CheckSizes(const Epetra_SrcDistObject& A);
00936 
00937   int CopyAndPermute(const Epetra_SrcDistObject& Source,
00938                            int NumSameIDs, 
00939                            int NumPermuteIDs,
00940                            int* PermuteToLIDs,
00941                            int* PermuteFromLIDs,
00942                            const Epetra_OffsetIndex * Indexor);
00943   int CopyAndPermuteRowMatrix(const Epetra_RowMatrix& A,
00944                                     int NumSameIDs, 
00945                                     int NumPermuteIDs,
00946                                     int* PermuteToLIDs,
00947                                     int* PermuteFromLIDs,
00948                                     const Epetra_OffsetIndex * Indexor);
00949   int CopyAndPermuteCrsGraph(const Epetra_CrsGraph& A,
00950                                    int NumSameIDs, 
00951                                    int NumPermuteIDs,
00952                                    int* PermuteToLIDs,
00953                                    int* PermuteFromLIDs,
00954                                    const Epetra_OffsetIndex * Indexor);
00955   
00956         int PackAndPrepare(const Epetra_SrcDistObject& Source,
00957                            int NumExportIDs,
00958                            int* ExportLIDs,
00959                            int& LenExports,
00960                            char*& Exports,
00961                            int& SizeOfPacket,
00962                            int * Sizes,
00963                            bool & VarSizes,
00964                            Epetra_Distributor& Distor);
00965         int PackAndPrepareCrsGraph(const Epetra_CrsGraph& A,
00966                                    int NumExportIDs,
00967                                    int* ExportLIDs,
00968                                    int& LenExports,
00969                                    char*& Exports,
00970                                    int& SizeOfPacket,
00971                                    int* Sizes,
00972                                    bool& VarSizes,
00973                                    Epetra_Distributor& Distor);
00974         int PackAndPrepareRowMatrix(const Epetra_RowMatrix& A,
00975                                     int NumExportIDs,
00976                                     int* ExportLIDs,
00977                                     int& LenExports,
00978                                     char*& Exports,
00979                                     int& SizeOfPacket,
00980                                     int* Sizes,
00981                                     bool& VarSizes,
00982                                     Epetra_Distributor& Distor);
00983 
00984         int UnpackAndCombine(const Epetra_SrcDistObject& Source,
00985                              int NumImportIDs,
00986                              int* ImportLIDs, 
00987                              int LenImports, 
00988                              char* Imports,
00989                              int& SizeOfPacket, 
00990                              Epetra_Distributor& Distor,
00991                              Epetra_CombineMode CombineMode,
00992                              const Epetra_OffsetIndex * Indexor);
00993 
00994   void CleanupData();
00995 
00996   Epetra_CrsGraphData* CrsGraphData_; 
00997 
00998 };
00999 #endif /* EPETRA_CRSGRAPH_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines