Epetra_CrsGraph.h

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 /*
00004 ************************************************************************
00005 
00006               Epetra: Linear Algebra Services Package 
00007                 Copyright (2001) Sandia Corporation
00008 
00009 Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00010 license for use of this work by or on behalf of the U.S. Government.
00011 
00012 This library is free software; you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as
00014 published by the Free Software Foundation; either version 2.1 of the
00015 License, or (at your option) any later version.
00016  
00017 This library is distributed in the hope that it will be useful, but
00018 WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 Lesser General Public License for more details.
00021  
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with this library; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 USA
00026 Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00027 
00028 ************************************************************************
00029 */
00030 //@HEADER
00031 
00032 #ifndef EPETRA_CRSGRAPH_H
00033 #define EPETRA_CRSGRAPH_H
00034 
00035 #include "Epetra_DistObject.h" 
00036 #include "Epetra_CrsGraphData.h"
00037 class Epetra_BlockMap;
00038 class Epetra_Util;
00039 class Epetra_Time;
00040 class Epetra_Import;
00041 class Epetra_Export;
00042 class Epetra_Distributor;
00043 class Epetra_RowMatrix;
00044 
00046 
00200 class Epetra_CrsGraph: public Epetra_DistObject {
00201       
00202  public:
00203 
00205 
00206 
00207 
00219   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, const int* NumIndicesPerRow, bool StaticProfile = false);
00220   
00222 
00235   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, int NumIndicesPerRow, bool StaticProfile = false);
00236   
00238 
00252   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, 
00253       const Epetra_BlockMap& ColMap, const int* NumIndicesPerRow, bool StaticProfile = false);
00254   
00256 
00272   Epetra_CrsGraph(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, 
00273       const Epetra_BlockMap& ColMap, int NumIndicesPerRow, bool StaticProfile = false);
00274   
00276 
00279   Epetra_CrsGraph(const Epetra_CrsGraph& Graph);
00280 
00282   virtual ~Epetra_CrsGraph();
00284   
00286 
00287 
00288 
00302   int InsertGlobalIndices(int GlobalRow, int NumIndices, int* Indices);
00303   
00305 
00314   int RemoveGlobalIndices(int GlobalRow, int NumIndices, int* Indices);
00315   
00317 
00324   int RemoveGlobalIndices(int Row);
00325 
00326   
00328 
00343   int InsertMyIndices(int LocalRow, int NumIndices, int* Indices);
00344   
00346 
00355   int RemoveMyIndices(int LocalRow, int NumIndices, int* Indices);
00356   
00358 
00365   int RemoveMyIndices(int Row);
00367 
00369 
00370   
00372 
00379   int FillComplete();
00380 
00382 
00394   int FillComplete(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00395 
00397 
00411   int OptimizeStorage();
00412 
00414 
00416 
00417 
00419 
00427   int ExtractGlobalRowCopy(int GlobalRow, int LenOfIndices, int& NumIndices, int* Indices) const;
00428 
00430 
00440   int ExtractMyRowCopy(int LocalRow, int LenOfIndices, int& NumIndices, int* Indices) const;
00441 
00443 
00453   int ExtractGlobalRowView(int GlobalRow, int& NumIndices, int*& Indices) const;
00454 
00456 
00466   int ExtractMyRowView(int LocalRow, int& NumIndices, int*& Indices) const;
00468 
00470 
00471 
00472   bool Filled() const {return(CrsGraphData_->Filled_);}
00473   
00475   bool StorageOptimized() const {return(CrsGraphData_->StorageOptimized_);}
00476   
00478   bool IndicesAreGlobal() const {return(CrsGraphData_->IndicesAreGlobal_);}
00479   
00481   bool IndicesAreLocal() const {return(CrsGraphData_->IndicesAreLocal_);}
00482   
00484 
00487   bool LowerTriangular() const {return(CrsGraphData_->LowerTriangular_);}
00488   
00490 
00493   bool UpperTriangular() const {return(CrsGraphData_->UpperTriangular_);}
00494   
00496 
00499   bool NoDiagonal() const {return(CrsGraphData_->NoDiagonal_);}
00500   
00502   bool MyGlobalRow(int GID) const {return(RowMap().MyGID(GID));}
00503 
00505 
00509   bool HaveColMap() const {return(CrsGraphData_->HaveColMap_);}
00511   
00513 
00514     
00516   int NumMyRows() const {return(CrsGraphData_->NumMyRows_);}
00517   
00519   int NumGlobalRows() const {return(CrsGraphData_->NumGlobalRows_);}
00520   
00522 
00526   int NumMyCols() const {return(CrsGraphData_->NumMyCols_);}
00527   
00529 
00532   int NumGlobalCols() const {return(CrsGraphData_->NumGlobalCols_);}
00533   
00535 
00541   int NumGlobalNonzeros() const {return(CrsGraphData_->NumGlobalNonzeros_);}
00542   
00544 
00547   int NumGlobalDiagonals() const {return(CrsGraphData_->NumGlobalDiagonals_);}
00548   
00550 
00553   int NumMyDiagonals() const {return(CrsGraphData_->NumMyDiagonals_);}
00554   
00556   int NumMyBlockRows() const {return(CrsGraphData_->NumMyBlockRows_);}
00557   
00559   int NumGlobalBlockRows() const {return(CrsGraphData_->NumGlobalBlockRows_);}
00560   
00562 
00565   int NumMyBlockCols() const {return(CrsGraphData_->NumMyBlockCols_);}
00566   
00568 
00571   int NumGlobalBlockCols() const {return(CrsGraphData_->NumGlobalBlockCols_);}
00572   
00574 
00577   int NumMyBlockDiagonals() const {return(CrsGraphData_->NumMyBlockDiagonals_);}
00578   
00580 
00583   int NumGlobalBlockDiagonals() const {return(CrsGraphData_->NumGlobalBlockDiagonals_);}
00584   
00586 
00589   int NumGlobalEntries() const {return(CrsGraphData_->NumGlobalEntries_);}
00590   
00592 
00595   int NumMyEntries() const {return(CrsGraphData_->NumMyEntries_);}
00597 
00600   int MaxRowDim() const {return(CrsGraphData_->MaxRowDim_);}
00601   
00603 
00606   int GlobalMaxRowDim() const {return(CrsGraphData_->GlobalMaxRowDim_);}
00607   
00609 
00612   int MaxColDim() const {return(CrsGraphData_->MaxColDim_);}
00613   
00615 
00618   int GlobalMaxColDim() const {return(CrsGraphData_->GlobalMaxColDim_);}
00619   
00621 
00624   int NumMyNonzeros() const {return(CrsGraphData_->NumMyNonzeros_);}
00625   
00627   int NumGlobalIndices(int Row) const;
00628   
00630   int NumAllocatedGlobalIndices(int Row) const;
00631   
00633 
00636   int MaxNumIndices() const {return(CrsGraphData_->MaxNumIndices_);}
00637   
00639 
00642   int GlobalMaxNumIndices() const {return(CrsGraphData_->GlobalMaxNumIndices_);}
00643   
00645 
00654   int MaxNumNonzeros() const {return(CrsGraphData_->MaxNumNonzeros_);}
00655   
00657 
00661   int GlobalMaxNumNonzeros() const {return(CrsGraphData_->GlobalMaxNumNonzeros_);}
00662   
00664   int NumMyIndices(int Row) const {if (Row<0 || Row >= NumMyRows()) return(0);
00665     if (StorageOptimized()) return(CrsGraphData_->IndexOffset_[Row+1] - CrsGraphData_->IndexOffset_[Row]); 
00666     else return(CrsGraphData_->NumIndicesPerRow_[Row]);}
00667   
00669   int NumAllocatedMyIndices(int Row) const {if (Row<0 || Row >= NumMyRows()) return(0);
00670     if (StorageOptimized()) return(CrsGraphData_->IndexOffset_[Row+1] - CrsGraphData_->IndexOffset_[Row]); 
00671     else return(CrsGraphData_->NumAllocatedIndicesPerRow_[Row]);}
00672   
00674   int IndexBase() const {return(CrsGraphData_->IndexBase_);}
00675   
00677   const Epetra_BlockMap& RowMap() const {return(Epetra_DistObject::Map());}
00678     
00685   int ReplaceRowMap(const Epetra_BlockMap& newmap);
00686 
00693   int ReplaceColMap(const Epetra_BlockMap& newmap);
00694 
00696 
00699   const Epetra_BlockMap& ColMap() const {return(CrsGraphData_->ColMap_);}
00700   
00702 
00705   const Epetra_BlockMap& DomainMap() const {return(CrsGraphData_->DomainMap_);}
00706   
00708 
00711   const Epetra_BlockMap& RangeMap() const {return(CrsGraphData_->RangeMap_);}
00712   
00714   const Epetra_Import* Importer() const {return(CrsGraphData_->Importer_);}
00715   
00717   const Epetra_Export* Exporter() const {return(CrsGraphData_->Exporter_);}
00718   
00720   const Epetra_Comm& Comm() const {return(Epetra_DistObject::Comm());}
00722   
00724 
00725 
00727   int LRID(int GRID) const {return(RowMap().LID(GRID));}
00728   
00730   int GRID(int LRID) const {return(RowMap().GID(LRID));}
00731   
00733 
00736   int LCID(int GCID) const
00737     {
00738       return( CrsGraphData_->HaveColMap_ ? ColMap().LID(GCID) : -1 );
00739     }
00740   
00742 
00745   int GCID(int LCID) const
00746     {
00747       return( CrsGraphData_->HaveColMap_ ? ColMap().GID(LCID) : -1 );
00748     }
00749   
00751   bool MyGRID(int GRID) const {return(LRID(GRID) != -1);}
00752   
00754   bool MyLRID(int LRID) const {return(GRID(LRID) != IndexBase() - 1);}
00755   
00757 
00760   bool MyGCID(int GCID) const {return(LCID(GCID) != -1);}
00761   
00763 
00766   bool MyLCID(int LCID) const {return(GCID(LCID) != IndexBase() - 1);}
00768   
00770 
00771   
00773 
00779   inline int*  operator[]( int Loc ) { 
00780     if (StorageOptimized()){ return(CrsGraphData_->All_Indices_.Values() + CrsGraphData_->IndexOffset_[Loc]);}
00781     else return(CrsGraphData_->Indices_[Loc]); }
00782 
00783   inline int* operator[]( int Loc ) const { 
00784     if (StorageOptimized()) { return(CrsGraphData_->All_Indices_.Values() +CrsGraphData_->IndexOffset_[Loc]);}
00785     else return(CrsGraphData_->Indices_[Loc]); }
00786 
00788 
00790 
00793   Epetra_CrsGraph& operator = (const Epetra_CrsGraph& Source);
00794 
00796 
00797 
00799   virtual void Print(ostream& os) const;
00800 
00801   void PrintGraphData(ostream& os) const {CrsGraphData_->Print(os);}
00802   void PrintGraphData(ostream& os, int level) const {CrsGraphData_->Print(os, level);}
00804 
00806 
00807 
00809   const Epetra_BlockMap& ImportMap() const {return(CrsGraphData_->ColMap_);}
00810   
00812   int TransformToLocal();
00813   
00815   int TransformToLocal(const Epetra_BlockMap* DomainMap, const Epetra_BlockMap* RangeMap);
00816   
00818 
00820 
00821 
00823 
00824   int ReferenceCount() const {return(CrsGraphData_->ReferenceCount());}
00825 
00827 
00828   const Epetra_CrsGraphData* DataPtr() const {return(CrsGraphData_);}
00829 
00831 
00832   // functions listed in protected are the ones used by CrsMatrix and VbrMatrix.
00833   // functions listed in private are the ones that are really private.
00834   // (just pretend CrsMatrix and VbrMatrix derive from CrsGraph to understand the distinction.)
00835   friend class Epetra_CrsMatrix;
00836   friend class Epetra_VbrMatrix;
00837   friend class Epetra_FECrsGraph;
00838   friend class Epetra_FECrsMatrix;
00839   friend class Epetra_FEVbrMatrix;
00840   friend class Epetra_OffsetIndex;
00841 
00842  protected:
00843   int *All_Indices() const {
00844     if (!StorageOptimized()) throw ReportError("This method: int *All_Indices() cannot be called when StorageOptimized()==false", -1);
00845     else return(CrsGraphData_->All_Indices_.Values());}
00846   int *IndexOffset() const {
00847     if (!StorageOptimized()) throw ReportError("This method: int *IndexOffset()  cannot be called when StorageOptimized()==false", -1);
00848     else return(CrsGraphData_->IndexOffset_.Values());}
00849   int* NumIndicesPerRow() const {
00850     if (StorageOptimized()) throw ReportError("This method: int* NumIndicesPerRow() cannot be called when StorageOptimized()==true", -1);
00851     else return(CrsGraphData_->NumIndicesPerRow_.Values());}
00852   int* NumAllocatedIndicesPerRow() const {
00853     if (StorageOptimized()) throw ReportError("This method: int* NumAllocatedIndicesPerRow() cannot be called when StorageOptimized()==true", -1);
00854     else return(CrsGraphData_->NumAllocatedIndicesPerRow_.Values());}
00855   int** Indices() const {
00856     if (StorageOptimized()) throw ReportError("This method: int** Indices() cannot be called when StorageOptimized()==true", -1);
00857     else return(CrsGraphData_->Indices_);}
00858   int* Indices(int LocalRow) const {
00859     if (StorageOptimized()) return(CrsGraphData_->All_Indices_.Values()+CrsGraphData_->IndexOffset_[LocalRow]);
00860     else return(CrsGraphData_->Indices_[LocalRow]);}
00861   // If column indices are stored in one long array (via a call to OptimizeStorage), 
00862   // IndicesAreContiguous returns true, otherwise it returns false.
00863   bool IndicesAreContiguous() const {return(CrsGraphData_->IndicesAreContiguous_);}
00864   bool StaticProfile() const {return(CrsGraphData_->StaticProfile_);}
00865   bool GlobalConstantsComputed() const;
00866   bool FindGlobalIndexLoc(int LocalRow, int Index, int Start, int& Loc) const;
00867   bool FindGlobalIndexLoc(int NumIndices, const int* Indices, int Index, int Start, int& Loc) const;
00868   bool FindMyIndexLoc(int LocalRow, int Index, int Start, int& Loc) const;
00869   bool FindMyIndexLoc(int NumIndices, const int* Indices, int Index, int Start, int& Loc) const;
00870   int InsertIndices(int Row, int NumIndices, int* Indices);
00871   int MakeIndicesLocal(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00872   void SetIndicesAreLocal(bool Flag) {CrsGraphData_->IndicesAreLocal_ = Flag;}
00873   void SetIndicesAreGlobal(bool Flag) {CrsGraphData_->IndicesAreGlobal_ = Flag;}
00874   void SetSorted(bool Flag) {CrsGraphData_->Sorted_ = Flag;}
00875 
00877 
00880   int SortIndices();
00881 
00883   bool Sorted() const {return(CrsGraphData_->Sorted_);}
00884   
00886 
00889   int RemoveRedundantIndices();
00890 
00892   bool NoRedundancies() const {return(CrsGraphData_->NoRedundancies_);}
00893 
00894  private:
00895   void SetGlobalConstantsComputed(bool Flag) {CrsGraphData_->GlobalConstantsComputed_ = Flag;}
00896   void SetIndicesAreContiguous(bool Flag) {CrsGraphData_->IndicesAreContiguous_ = Flag;}
00897   void SetNoRedundancies(bool Flag) {CrsGraphData_->NoRedundancies_ = Flag;}
00898   void ComputeIndexState();
00899   int MakeColMap(const Epetra_BlockMap& DomainMap, const Epetra_BlockMap& RangeMap);
00900   int Allocate(const int* NumIndicesPerRow, int Inc, bool StaticProfile);
00901   //int ReAllocate();
00902   int ComputeGlobalConstants();
00903   void SetFilled(bool Flag) {CrsGraphData_->Filled_ = Flag;}
00904   bool Allocated() const {return(CrsGraphData_->Allocated_);}
00905   void SetAllocated(bool Flag) {CrsGraphData_->Allocated_ = Flag;}
00906   
00907   int CheckSizes(const Epetra_SrcDistObject& A);
00908 
00909   int CopyAndPermute(const Epetra_SrcDistObject& Source,
00910                            int NumSameIDs, 
00911                            int NumPermuteIDs,
00912                            int* PermuteToLIDs,
00913                            int* PermuteFromLIDs,
00914                            const Epetra_OffsetIndex * Indexor);
00915   int CopyAndPermuteRowMatrix(const Epetra_RowMatrix& A,
00916                                     int NumSameIDs, 
00917                                     int NumPermuteIDs,
00918                                     int* PermuteToLIDs,
00919                                     int* PermuteFromLIDs,
00920                                     const Epetra_OffsetIndex * Indexor);
00921   int CopyAndPermuteCrsGraph(const Epetra_CrsGraph& A,
00922                                    int NumSameIDs, 
00923                                    int NumPermuteIDs,
00924                                    int* PermuteToLIDs,
00925                                    int* PermuteFromLIDs,
00926                                    const Epetra_OffsetIndex * Indexor);
00927   
00928         int PackAndPrepare(const Epetra_SrcDistObject& Source,
00929                            int NumExportIDs,
00930                            int* ExportLIDs,
00931                            int& LenExports,
00932                            char*& Exports,
00933                            int& SizeOfPacket,
00934                            int * Sizes,
00935                            bool & VarSizes,
00936                            Epetra_Distributor& Distor);
00937         int PackAndPrepareCrsGraph(const Epetra_CrsGraph& A,
00938                                    int NumExportIDs,
00939                                    int* ExportLIDs,
00940                                    int& LenExports,
00941                                    char*& Exports,
00942                                    int& SizeOfPacket,
00943                                    int* Sizes,
00944                                    bool& VarSizes,
00945                                    Epetra_Distributor& Distor);
00946         int PackAndPrepareRowMatrix(const Epetra_RowMatrix& A,
00947                                     int NumExportIDs,
00948                                     int* ExportLIDs,
00949                                     int& LenExports,
00950                                     char*& Exports,
00951                                     int& SizeOfPacket,
00952                                     int* Sizes,
00953                                     bool& VarSizes,
00954                                     Epetra_Distributor& Distor);
00955 
00956         int UnpackAndCombine(const Epetra_SrcDistObject& Source,
00957                              int NumImportIDs,
00958                              int* ImportLIDs, 
00959                              int LenImports, 
00960                              char* Imports,
00961                              int& SizeOfPacket, 
00962                              Epetra_Distributor& Distor,
00963                              Epetra_CombineMode CombineMode,
00964                              const Epetra_OffsetIndex * Indexor);
00965 
00966   void CleanupData();
00967 
00968   Epetra_CrsGraphData* CrsGraphData_; 
00969 
00970 };
00971 #endif /* EPETRA_CRSGRAPH_H */

Generated on Thu Sep 18 12:37:57 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1