Epetra Package Browser (Single Doxygen Collection) Development
Epetra_CrsMatrix.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_CRSMATRIX_H
00045 #define EPETRA_CRSMATRIX_H
00046 
00047 #include "Epetra_ConfigDefs.h"
00048 #include "Epetra_DistObject.h"
00049 #include "Epetra_CompObject.h"
00050 #include "Epetra_BLAS.h"
00051 #include "Epetra_RowMatrix.h"
00052 #include "Epetra_Operator.h"
00053 #include "Epetra_CrsGraph.h"
00054 #include "Epetra_Map.h"
00055 
00056 #ifdef Epetra_ENABLE_CASK
00057 #include "cask.h"
00058 #endif
00059 
00060 class Epetra_Map;
00061 class Epetra_Import;
00062 class Epetra_Export;
00063 class Epetra_Vector;
00064 class Epetra_MultiVector;
00065 class Epetra_IntSerialDenseVector;
00066 
00067 
00068 // Define this to see a complete dump a an Epetra_CrsMatrix::Multiply(...) call
00069 //#define EPETRA_CRS_MATRIX_TRACE_DUMP_MULTIPLY
00070 
00071 #ifdef EPETRA_CRS_MATRIX_TRACE_DUMP_MULTIPLY
00072 extern bool Epetra_CrsMatrixTraceDumpMultiply;
00073 #endif // EPETRA_CRS_MATRIX_TRACE_DUMP_MULTIPLY
00074 
00076 
00173 class EPETRA_LIB_DLL_EXPORT Epetra_CrsMatrix: public Epetra_DistObject, public Epetra_CompObject, public Epetra_BLAS, public virtual Epetra_RowMatrix {
00174  public:
00175 
00177 
00178 
00179 
00190   Epetra_CrsMatrix(Epetra_DataAccess CV, const Epetra_Map& RowMap, const int* NumEntriesPerRow, bool StaticProfile = false);
00191 
00193 
00205   Epetra_CrsMatrix(Epetra_DataAccess CV, const Epetra_Map& RowMap, int NumEntriesPerRow, bool StaticProfile = false);
00206 
00208 
00221   Epetra_CrsMatrix(Epetra_DataAccess CV, const Epetra_Map& RowMap, const Epetra_Map& ColMap, const int* NumEntriesPerRow, bool StaticProfile = false);
00222 
00224 
00238   Epetra_CrsMatrix(Epetra_DataAccess CV, const Epetra_Map& RowMap, const Epetra_Map& ColMap, int NumEntriesPerRow, bool StaticProfile = false);
00239 
00241 
00247   Epetra_CrsMatrix(Epetra_DataAccess CV, const Epetra_CrsGraph& Graph);
00248 
00250 
00287   Epetra_CrsMatrix(const Epetra_CrsMatrix & SourceMatrix, const Epetra_Import & RowImporter, const Epetra_Map * DomainMap=0, const Epetra_Map * RangeMap=0, bool RestrictCommunicator = false);
00288 
00290 
00327   Epetra_CrsMatrix(const Epetra_CrsMatrix & SourceMatrix, const Epetra_Export & RowExporter, const Epetra_Map * DomainMap=0, const Epetra_Map * RangeMap=0, bool RestrictCommunicator = false);
00328 
00329 
00331   Epetra_CrsMatrix(const Epetra_CrsMatrix& Matrix);
00332 
00334   virtual ~Epetra_CrsMatrix();
00336 
00338 
00339 
00341   Epetra_CrsMatrix& operator=(const Epetra_CrsMatrix& src);
00342 
00344 
00351   int PutScalar(double ScalarConstant);
00352 
00354 
00361   int Scale(double ScalarConstant);
00362 
00364 
00390 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00391   virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double* Values, const int* Indices);
00392 #endif
00393 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00394   virtual int InsertGlobalValues(long long GlobalRow, int NumEntries, const double* Values, const long long* Indices);
00395 #endif
00396 
00398 
00424 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00425   virtual int InsertGlobalValues(int GlobalRow, int NumEntries, double* Values, int* Indices);
00426 #endif
00427 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00428   virtual int InsertGlobalValues(long long GlobalRow, int NumEntries, double* Values, long long* Indices);
00429 #endif
00430 
00432 
00444 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00445   virtual int ReplaceGlobalValues(int GlobalRow, int NumEntries, const double* Values, const int* Indices);
00446 #endif
00447 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00448   virtual int ReplaceGlobalValues(long long GlobalRow, int NumEntries, const double* Values, const long long* Indices);
00449 #endif
00450 
00452 
00464 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00465   virtual int SumIntoGlobalValues(int GlobalRow, int NumEntries, const double* Values, const int* Indices);
00466 #endif
00467 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00468   virtual int SumIntoGlobalValues(long long GlobalRow, int NumEntries, const double* Values, const long long* Indices);
00469 #endif
00470 
00472 
00485   int InsertMyValues(int MyRow, int NumEntries, const double* Values, const int* Indices);
00486 
00488 
00501   int InsertMyValues(int MyRow, int NumEntries, double* Values, int* Indices);
00502 
00504 
00516   int ReplaceMyValues(int MyRow, int NumEntries, const double* Values, const int* Indices);
00517 
00519 
00532   int SumIntoMyValues(int MyRow, int NumEntries, const double* Values, const int* Indices);
00533 
00535 
00548   int ReplaceDiagonalValues(const Epetra_Vector& Diagonal);
00549 
00551 
00553 
00554 
00555 
00557   /* This version of FillComplete assumes that the domain and range
00558      distributions are identical to the matrix row distributions.
00559     \param OptimizeDataStorage - (In) If true, storage will be packed for optimal performance.  Depending
00560            on how the matrix was constructed, optimizing the storage may have no impact on performance
00561      or one-time memory use, or may have a large impact.  If the user was careful in allocating memory
00562      for the matrix by setting StaticProfile to true in the matrix constructor, then no extra storage
00563      will be allocated in attempting to optimize storage.  If the user did not set StaticProfile to true,
00564      then optimizing the storage will temporarily use additional memory, will have a noticeable impact
00565      on performance and ultimately reduce the storage associated with the matrix.
00566 
00567      By default storage will be optimized.  If you cannot tolerate the increased temporary memory use,
00568      should set this value to false.
00569 
00570      \return error code, 0 if successful. Returns a positive warning code of 3
00571         if the matrix is rectangular (meaning that the other overloading of
00572         FillComplete should have been called, with differen domain-map and
00573         range-map specified).
00574   */
00575   int FillComplete(bool OptimizeDataStorage = true);
00576 
00578   /* This version of FillComplete requires the explicit specification of the domain
00579      and range distribution maps.  These maps are used for importing and exporting vector
00580      and multi-vector elements that are needed for distributed matrix computations.  For
00581      example, to compute y = Ax in parallel, we would specify the DomainMap as the distribution
00582      of the vector x and the RangeMap as the distribution of the vector y.
00583     \param DomainMap - (In) Map that describes the distribution of vector and multi-vectors in the
00584     matrix domain.
00585     \param RangeMap - (In) Map that describes the distribution of vector and multi-vectors in the
00586     matrix range.
00587 
00588     \param OptimizeDataStorage - (In) If true, storage will be packed for optimal performance.  Depending
00589            on how the matrix was constructed, optimizing the storage may have no impact on performance
00590      or one-time memory use, or may have a large impact.  If the user was careful in allocating memory
00591      for the matrix by setting StaticProfile to true in the matrix constructor, then no extra storage
00592      will be allocated in attempting to optimize storage.  If the user did not set StaticProfile to true,
00593      then optimizing the storage will temporarily use additional memory, will have a noticeable impact
00594      on performance and ultimately reduce the storage associated with the matrix.
00595 
00596      By default storage will be optimized.  If you cannot tolerate the increased temporary memory use,
00597      should set this value to false.
00598 
00599     \return error code, 0 if successful. positive warning code of 2 if it is detected that the
00600     matrix-graph got out of sync since this matrix was constructed (for instance if
00601     graph.FillComplete() was called by another matrix that shares the graph)
00602 
00603     \post IndicesAreLocal()==true
00604     */
00605   int FillComplete(const Epetra_Map& DomainMap, const Epetra_Map& RangeMap, bool OptimizeDataStorage = true);
00606 
00608 
00628   int OptimizeStorage();
00629 
00630 
00632   int MakeDataContiguous() {EPETRA_CHK_ERR(OptimizeStorage()); return(0);}
00634 
00636 
00637 
00639 
00649 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00650   int ExtractGlobalRowCopy(int GlobalRow, int Length, int& NumEntries, double* Values, int* Indices) const;
00651 #endif
00652 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00653   int ExtractGlobalRowCopy(long long GlobalRow, int Length, int& NumEntries, double* Values, long long* Indices) const;
00654 #endif
00655 
00657 
00668   int ExtractMyRowCopy(int MyRow, int Length, int& NumEntries, double* Values, int* Indices) const;
00669 
00671 
00679 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00680   int ExtractGlobalRowCopy(int GlobalRow, int Length, int& NumEntries, double* Values) const;
00681 #endif
00682 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00683   int ExtractGlobalRowCopy(long long GlobalRow, int Length, int& NumEntries, double* Values) const;
00684 #endif
00685 
00687 
00695   int ExtractMyRowCopy(int MyRow, int Length, int& NumEntries, double* Values) const;
00696 
00698 
00705   int ExtractDiagonalCopy(Epetra_Vector& Diagonal) const;
00706 
00708 
00719 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00720   int ExtractGlobalRowView(int GlobalRow, int& NumEntries, double*& Values, int*& Indices) const;
00721 #endif
00722 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00723   int ExtractGlobalRowView(long long GlobalRow, int& NumEntries, double*& Values, long long*& Indices) const;
00724 #endif
00725 
00727 
00738   int ExtractMyRowView(int MyRow, int& NumEntries, double*& Values, int*& Indices) const;
00739 
00741 
00748 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00749   int ExtractGlobalRowView(int GlobalRow, int& NumEntries, double*& Values) const;
00750 #endif
00751 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00752   int ExtractGlobalRowView(long long GlobalRow, int& NumEntries, double*& Values) const;
00753 #endif
00754 
00756 
00763   int ExtractMyRowView(int MyRow, int& NumEntries, double*& Values) const;
00765 
00767 
00768 
00770 
00779   int Multiply(bool TransA, const Epetra_Vector& x, Epetra_Vector& y) const;
00780   int Multiply1(bool TransA, const Epetra_Vector& x, Epetra_Vector& y) const;
00781 
00782 
00784 
00793   int Multiply(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00794   int Multiply1(bool TransA, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00795 
00797 
00808   int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_Vector& x, Epetra_Vector& y) const;
00809 
00811 
00822   int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00823 
00825 
00841   int InvRowSums(Epetra_Vector& x) const;
00842 
00844 
00856   int InvRowMaxs(Epetra_Vector& x) const;
00857 
00859 
00867   int LeftScale(const Epetra_Vector& x);
00868 
00870 
00887   int InvColSums(Epetra_Vector& x) const;
00888 
00890 
00902   int InvColMaxs(Epetra_Vector& x) const;
00903 
00905 
00913   int RightScale(const Epetra_Vector& x);
00915 
00917 
00918 
00919 
00921   bool Filled() const {return(Graph_.Filled());}
00922 
00924   bool StorageOptimized() const {return(StorageOptimized_);}
00925 
00927   bool IndicesAreGlobal() const {return(Graph_.IndicesAreGlobal());}
00928 
00930   bool IndicesAreLocal() const {return(Graph_.IndicesAreLocal());}
00931 
00933   bool IndicesAreContiguous() const {return(Graph_.IndicesAreContiguous());}
00934 
00936   bool LowerTriangular() const {return(Graph_.LowerTriangular());}
00937 
00939   bool UpperTriangular() const {return(Graph_.UpperTriangular());}
00940 
00942   bool NoDiagonal() const {return(Graph_.NoDiagonal());}
00943 
00945 
00947 
00948 
00950   /* Returns the quantity \f$ \| A \|_\infty\f$ such that
00951      \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f]
00952      \warning The NormInf() method will not properly calculate the infinity norm for a matrix that has entries that are
00953      replicated on multiple processors.  */
00954   double NormInf() const;
00955 
00957   /* Returns the quantity \f$ \| A \|_1\f$ such that
00958      \f[\| A \|_1= \max_{1\lej\len} \sum_{i=1}^m |a_{ij}| \f].
00959      \warning The NormOne() method will not properly calculate the one norm for a matrix that has entries that are
00960      replicated on multiple processors.
00961   */
00962   double NormOne() const;
00963 
00965   /* Returns the quantity \f[ \| A \|_{Frobenius} = \sqrt{\sum_{i=1}^m \sum_{j=1}^n\|a_{ij}\|^2}\f]
00966      \warning the NormFrobenius() method will not properly calculate the frobenius norm for a matrix that
00967      has entries which are replicated on multiple processors. In that case, the returned
00968      norm will be larger than the true norm.
00969    */
00970   double NormFrobenius() const;
00971 
00973   /*
00974     Note that if maps are defined such that some nonzeros appear on
00975     multiple processors, then those nonzeros will be counted multiple times.
00976     If the user wishes to assemble a matrix from overlapping submatrices,
00977     they can use Epetra_FECrsMatrix.
00978   */
00979 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00980   int  NumGlobalNonzeros() const {
00981       if(RowMap().GlobalIndicesInt())
00982         return (int) NumGlobalNonzeros64();
00983       throw "Epetra_CrsMatrix::NumGlobalNonzeros: GlobalIndices not int.";
00984     }
00985 #endif
00986   long long NumGlobalNonzeros64() const {return(Graph_.NumGlobalNonzeros64());}
00987 
00989 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00990   int  NumGlobalRows() const {
00991       if(RowMap().GlobalIndicesInt())
00992         return (int) NumGlobalRows64();
00993       throw "Epetra_CrsMatrix::NumGlobalRows: GlobalIndices not int.";
00994     }
00995 #endif
00996   long long NumGlobalRows64() const {return(Graph_.NumGlobalRows64());}
00997 
00999 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01000   int  NumGlobalCols() const {
01001       if(RowMap().GlobalIndicesInt())
01002         return (int) NumGlobalCols64();
01003       throw "Epetra_CrsMatrix::NumGlobalCols: GlobalIndices not int.";
01004     }
01005 #endif
01006   long long NumGlobalCols64() const {return(Graph_.NumGlobalCols64());}
01007 
01009 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01010   int  NumGlobalDiagonals() const {
01011       if(RowMap().GlobalIndicesInt())
01012         return (int) NumGlobalDiagonals64();
01013       throw "Epetra_CrsMatrix::NumGlobalDiagonals: GlobalIndices not int.";
01014     }
01015 #endif
01016   long long NumGlobalDiagonals64() const {return(Graph_.NumGlobalDiagonals64());}
01017 
01019   int NumMyNonzeros() const {return(Graph_.NumMyNonzeros());}
01020 
01022   int NumMyRows() const {return(Graph_.NumMyRows());}
01023 
01025 
01029   int NumMyCols() const {return(Graph_.NumMyCols());}
01030 
01032 
01035   int NumMyDiagonals() const {return(Graph_.NumMyDiagonals());}
01036 
01038   int NumGlobalEntries(long long Row) const {return(Graph_.NumGlobalIndices(Row));}
01039 
01041   int NumAllocatedGlobalEntries(int Row) const{return(Graph_.NumAllocatedGlobalIndices(Row));}
01042 
01044 
01047   int MaxNumEntries() const {return(Graph_.MaxNumIndices());}
01048 
01050 
01053   int GlobalMaxNumEntries() const {return(Graph_.GlobalMaxNumIndices());}
01054 
01056   int NumMyEntries(int Row) const {return(Graph_.NumMyIndices(Row));}
01057 
01059   int NumAllocatedMyEntries(int Row) const {return(Graph_.NumAllocatedMyIndices(Row));}
01060 
01062 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01063 
01064   int  IndexBase() const {
01065     if(RowMap().GlobalIndicesInt())
01066       return (int) IndexBase64();
01067     throw "Epetra_CrsMatrix::IndexBase: GlobalIndices not int.";
01068   }
01069 #endif
01070   long long  IndexBase64() const {return(Graph_.IndexBase64());};
01071 
01072 
01074   bool StaticGraph() {return(StaticGraph_);}
01075 
01077   const Epetra_CrsGraph& Graph() const {return(Graph_);}
01078 
01080   const Epetra_Map& RowMap() const {return((Epetra_Map &)Graph_.RowMap());}
01081 
01083 
01089   int ReplaceRowMap(const Epetra_BlockMap& newmap);
01090 
01092 
01096   bool HaveColMap() const {return(Graph_.HaveColMap());}
01097 
01099 
01107   int ReplaceColMap(const Epetra_BlockMap& newmap);
01108 
01110 
01120   int ReplaceDomainMapAndImporter(const Epetra_Map & NewDomainMap, const Epetra_Import * NewImporter);
01121 
01123 
01134   int RemoveEmptyProcessesInPlace(const Epetra_BlockMap * NewMap);
01135 
01137 
01144   const Epetra_Map& ColMap() const {return((Epetra_Map &) Graph_.ColMap());}
01145 
01147 
01150   const Epetra_Map& DomainMap() const {return((Epetra_Map &)Graph_.DomainMap());}
01151 
01153 
01156   const Epetra_Map& RangeMap() const  {return((Epetra_Map &)Graph_.RangeMap());}
01157 
01159   const Epetra_Import* Importer() const {return(Graph_.Importer());}
01160 
01162   const Epetra_Export* Exporter() const {return(Graph_.Exporter());}
01163 
01165   const Epetra_Comm& Comm() const {return(Epetra_DistObject::Comm());}
01167 
01169 
01170 
01171 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01172   int LRID( int GRID_in) const {return(Graph_.LRID(GRID_in));}
01173 #endif
01174 
01175 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
01176   int LRID( long long GRID_in) const {return(Graph_.LRID(GRID_in));}
01177 #endif
01178 
01179 #if defined(EPETRA_NO_32BIT_GLOBAL_INDICES) && defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
01180   // default implementation so that no compiler/linker error in case neither 32 nor 64
01181   // bit indices present.
01182   int LRID(long long GRID_in) const {return(Graph_.LRID(GRID_in));}
01183 #endif
01184 
01186 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01187     int  GRID(int LRID_in) const {
01188       if(RowMap().GlobalIndicesInt())
01189         return (int) GRID64(LRID_in);
01190       throw "Epetra_CrsMatrix::GRID: GlobalIndices not int.";
01191     }
01192 #endif
01193   long long GRID64( int LRID_in) const {return(Graph_.GRID64(LRID_in));}
01194 
01196 
01199 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01200   int LCID( int GCID_in) const {return(Graph_.LCID(GCID_in));}
01201 #endif
01202 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
01203   int LCID( long long GCID_in) const {return(Graph_.LCID(GCID_in));}
01204 #endif
01205 
01207 
01210 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01211     int  GCID(int LCID_in) const {
01212       if(RowMap().GlobalIndicesInt())
01213         return (int) GCID64(LCID_in);
01214       throw "Epetra_CrsMatrix::GCID: GlobalIndices not int.";
01215     }
01216 #endif
01217   long long GCID64( int LCID_in) const {return(Graph_.GCID64(LCID_in));}
01218 
01220 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01221   bool MyGRID(int GRID_in) const {return(Graph_.MyGRID(GRID_in));}
01222 #endif
01223 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
01224   bool MyGRID(long long GRID_in) const {return(Graph_.MyGRID(GRID_in));}
01225 #endif
01226 
01228   bool MyLRID(int LRID_in) const {return(Graph_.MyLRID(LRID_in));}
01229 
01231 
01234 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01235   bool MyGCID(int GCID_in) const {return(Graph_.MyGCID(GCID_in));}
01236 #endif
01237 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
01238   bool MyGCID(long long GCID_in) const {return(Graph_.MyGCID(GCID_in));}
01239 #endif
01240 
01242 
01245   bool MyLCID(int LCID_in) const {return(Graph_.MyLCID(LCID_in));}
01246 
01248 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01249   bool MyGlobalRow(int GID) const {return(Graph_.MyGlobalRow(GID));}
01250 #endif
01251 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
01252   bool MyGlobalRow(long long GID) const {return(Graph_.MyGlobalRow(GID));}
01253 #endif
01254 
01255 
01256 
01258 
01259 
01261   virtual void Print(std::ostream& os) const;
01263 
01265 
01266 
01268   const char* Label() const {return(Epetra_Object::Label());}
01269 
01271 
01279   int SetUseTranspose(bool UseTranspose_in) {UseTranspose_ = UseTranspose_in; return(0);}
01280 
01282 
01290   int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
01291     return(Epetra_CrsMatrix::Multiply(Epetra_CrsMatrix::UseTranspose(), X, Y));}
01292 
01294 
01307   int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
01308     return(Solve(UpperTriangular(), Epetra_CrsMatrix::UseTranspose(), NoDiagonal(), X, Y));}
01309 
01311   bool HasNormInf() const {return(true);}
01312 
01314   bool UseTranspose() const {return(UseTranspose_);}
01315 
01317   const Epetra_Map& OperatorDomainMap() const
01318         {
01319           if (UseTranspose()) return(RangeMap());
01320           else return(DomainMap());
01321         }
01322 
01324   const Epetra_Map& OperatorRangeMap() const
01325         {
01326           if (UseTranspose()) return(DomainMap());
01327           else return(RangeMap());
01328         }
01329 
01331 
01332 
01333 
01335 
01344   int NumMyRowEntries(int MyRow, int& NumEntries) const;
01345 
01347   const Epetra_BlockMap& Map() const { return Epetra_DistObject::Map(); }
01348 
01350   const Epetra_Map& RowMatrixRowMap() const {return(RowMap());}
01351 
01353   const Epetra_Map& RowMatrixColMap() const {return(ColMap());}
01354 
01356   const Epetra_Import* RowMatrixImporter() const {return(Importer());}
01357 
01359 
01361 
01362 
01364 
01369   inline double* operator[] (int Loc) {
01370     if (StorageOptimized()){ int * ind = Graph().IndexOffset(); return(All_Values_+ind[Loc]);}
01371     else return Values_[Loc];}
01372   inline double* operator[] (int Loc) const {
01373     if (StorageOptimized()){ int * ind = Graph().IndexOffset(); return(All_Values_+ind[Loc]);}
01374     else return Values_[Loc];}
01376 
01378 
01379 
01380 
01393   int ExtractCrsDataPointers(int *& IndexOffset, int *& Indices, double *& Values_in) const {
01394     if (StorageOptimized()) {
01395       IndexOffset = Graph().IndexOffset();
01396       Indices = Graph().All_Indices();
01397       Values_in  = All_Values();
01398       return (0);
01399     }
01400     else { IndexOffset = 0; Indices = 0; Values_in  = 0; return (-1);} }
01401 
01402 
01404 
01407     Epetra_IntSerialDenseVector& ExpertExtractIndexOffset();
01408 
01410 
01413     Epetra_IntSerialDenseVector& ExpertExtractIndices();
01414 
01416 
01419     double *& ExpertExtractValues() {return All_Values_;}
01420 
01421 
01423 
01428     int ExpertStaticFillComplete(const Epetra_Map & DomainMap,const Epetra_Map & RangeMap, const Epetra_Import * Importer=0, const Epetra_Export * Exporter=0, int NumMyDiagonals=-1);
01429 
01430 
01432 
01435     int ExpertMakeUniqueCrsGraphData();
01436 
01438 
01448   int SortGhostsAssociatedWithEachProcessor(bool Flag)  {Graph_.SortGhostsAssociatedWithEachProcessor(Flag); return(0);}
01450 
01452 
01453 
01455   const Epetra_Map& ImportMap() const {return((Epetra_Map&) Graph_.ImportMap());}
01456 
01458   int TransformToLocal();
01459 
01461   int TransformToLocal(const Epetra_Map* DomainMap, const Epetra_Map* RangeMap);
01462 
01464 
01465 
01466  protected:
01467   bool Allocated() const {return(Allocated_);}
01468   int SetAllocated(bool Flag) {Allocated_ = Flag; return(0);}
01469   double** Values() const {
01470     if (StorageOptimized()) throw ReportError("This method: double** Values() cannot be called when StorageOptimized()==true", -1);
01471     else return(Values_);}
01472   double* All_Values() const {
01473     if (!StorageOptimized()) throw ReportError("This method: double* All_Values()cannot be called when StorageOptimized()==false", -1);
01474     else return(All_Values_);}
01475   double* Values(int LocalRow) const {
01476     if (StorageOptimized())
01477       if (Graph().StorageOptimized())
01478   return(All_Values_+Graph().IndexOffset()[LocalRow]);
01479       else throw ReportError("This method: double* Values()cannot be called when StorageOptimized()==true and Graph().StorageOptimized()==false", -1);
01480     else return(Values_[LocalRow]);}
01481 
01482   void InitializeDefaults();
01483   int Allocate();
01484 
01485 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
01486   int InsertValues(int LocalRow, int NumEntries, double* Values, int* Indices);
01487   int InsertValues(int LocalRow, int NumEntries, const double* Values, const int* Indices);
01488 #endif
01489 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
01490   int InsertValues(int LocalRow, int NumEntries, double* Values, long long* Indices);
01491   int InsertValues(int LocalRow, int NumEntries, const double* Values, const long long* Indices);
01492 #endif
01493 
01494   int InsertOffsetValues(long long GlobalRow, int NumEntries, double *Values, int *Indices);
01495   int InsertOffsetValues(long long GlobalRow, int NumEntries, const double *Values, const int *Indices);
01496   int ReplaceOffsetValues(long long GlobalRow, int NumEntries, const double *Values, const int *Indices);
01497   int SumIntoOffsetValues(long long GlobalRow, int NumEntries, const double *Values, const int *Indices);
01498   void UpdateImportVector(int NumVectors) const;
01499   void UpdateExportVector(int NumVectors) const;
01500   void GeneralMV(double * x, double * y) const;
01501   void GeneralMTV(double * x, double * y) const;
01502   void GeneralMM(double ** X, int LDX, double ** Y, int LDY, int NumVectors) const;
01503   void GeneralMTM(double ** X, int LDX, double ** Y, int LDY, int NumVectors) const;
01504   void GeneralSV(bool Upper, bool Trans, bool UnitDiagonal, double * x, double * y) const;
01505   void GeneralSM(bool Upper, bool Trans, bool UnitDiagonal, double ** X, int LDX, double ** Y, int LDY, int NumVectors) const;
01506 
01507   void SetStaticGraph(bool Flag) {StaticGraph_ = Flag;}
01508 
01509   int CheckSizes(const Epetra_SrcDistObject& A);
01510 
01511   int CopyAndPermute(const Epetra_SrcDistObject& Source,
01512                      int NumSameIDs,
01513                      int NumPermuteIDs,
01514                      int* PermuteToLIDs,
01515                      int* PermuteFromLIDs,
01516                      const Epetra_OffsetIndex * Indexor,
01517                      Epetra_CombineMode CombineMode = Zero);
01518   int CopyAndPermuteCrsMatrix(const Epetra_CrsMatrix& A,
01519                               int NumSameIDs,
01520                               int NumPermuteIDs,
01521                               int* PermuteToLIDs,
01522                               int* PermuteFromLIDs,
01523                               const Epetra_OffsetIndex * Indexor,
01524                               Epetra_CombineMode CombineMode);
01525   int CopyAndPermuteRowMatrix(const Epetra_RowMatrix& A,
01526                               int NumSameIDs,
01527                               int NumPermuteIDs,
01528                               int* PermuteToLIDs,
01529                               int* PermuteFromLIDs,
01530                               const Epetra_OffsetIndex * Indexor,
01531                               Epetra_CombineMode CombineMode);
01532 
01533   int PackAndPrepare(const Epetra_SrcDistObject& Source,
01534                      int NumExportIDs,
01535                      int* ExportLIDs,
01536                      int& LenExports,
01537                      char*& Exports,
01538                      int& SizeOfPacket,
01539                      int* Sizes,
01540                      bool& VarSizes,
01541                      Epetra_Distributor& Distor);
01542 
01543   int UnpackAndCombine(const Epetra_SrcDistObject& Source,
01544                        int NumImportIDs,
01545                        int* ImportLIDs,
01546                        int LenImports,
01547                        char* Imports,
01548                        int& SizeOfPacket,
01549                        Epetra_Distributor& Distor,
01550                        Epetra_CombineMode CombineMode,
01551                        const Epetra_OffsetIndex * Indexor);
01552 
01554   int SortEntries();
01555 
01557   bool Sorted() const {return(Graph_.Sorted());}
01558 
01560   int MergeRedundantEntries();
01561 
01563   bool NoRedundancies() const {return(Graph_.NoRedundancies());}
01564 
01565   void DeleteMemory();
01566 
01567   Epetra_CrsGraph Graph_;
01568   bool Allocated_;
01569   bool StaticGraph_;
01570   bool UseTranspose_;
01571   bool constructedWithFilledGraph_;
01572   bool matrixFillCompleteCalled_;
01573   bool StorageOptimized_;
01574 
01575   double** Values_;
01576   int* Values_alloc_lengths_;
01577   double* All_Values_;
01578   mutable double NormInf_;
01579   mutable double NormOne_;
01580   mutable double NormFrob_;
01581 
01582   int NumMyRows_;
01583   mutable Epetra_MultiVector* ImportVector_;
01584   mutable Epetra_MultiVector* ExportVector_;
01585 
01586   Epetra_DataAccess CV_;
01587 
01588   bool squareFillCompleteCalled_;
01589 #ifdef Epetra_ENABLE_CASK
01590   caskHandle_t cask;
01591 #endif
01592  private:
01593 
01594   // These are the pre-5.0 versions of solve.  They are still faster that generic 5.0 solves, so we keep them around
01595   int Solve1(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_Vector& x, Epetra_Vector& y) const;
01596   int Solve1(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
01597 
01598 private:
01599 
01600   template<typename int_type>
01601   int TInsertGlobalValues(int_type Row, int NumEntries, const double* values, const int_type* Indices);
01602 
01603   template<typename int_type>
01604   int TInsertGlobalValues(int_type Row, int NumEntries, double* values, int_type* Indices);
01605 
01606   template<typename int_type>
01607   int InsertValues(int Row, int NumEntries, const double* values, const int_type* Indices);
01608 
01609   template<typename int_type>
01610   int InsertValues(int Row, int NumEntries, double* values, int_type* Indices);
01611 
01612   template<typename int_type>
01613   int TReplaceGlobalValues(int_type Row, int NumEntries, const double * srcValues, const int_type *Indices);
01614 
01615   template<typename int_type>
01616   int TSumIntoGlobalValues(int_type Row, int NumEntries, const double * srcValues, const int_type *Indices);
01617 
01618   template<typename int_type>
01619   int ExtractGlobalRowCopy(int_type Row, int Length, int & NumEntries, double * values, int_type * Indices) const;
01620 
01621   template<typename int_type>
01622   int ExtractGlobalRowCopy(int_type Row, int Length, int & NumEntries, double * values) const;
01623 
01624   template<typename int_type>
01625   int ExtractGlobalRowView(int_type Row, int & NumEntries, double *& values, int_type *& Indices) const;
01626 
01627   template<typename int_type>
01628   int ExtractGlobalRowView(int_type Row, int & NumEntries, double *& values) const;
01629 
01630   template<typename int_type>
01631     int TCopyAndPermuteCrsMatrix(const Epetra_CrsMatrix& A,
01632                               int NumSameIDs,
01633                               int NumPermuteIDs,
01634                               int* PermuteToLIDs,
01635                               int* PermuteFromLIDs,
01636                               const Epetra_OffsetIndex * Indexor,
01637                               Epetra_CombineMode CombineMode);
01638 
01639   template<typename int_type>
01640     int TCopyAndPermuteRowMatrix(const Epetra_RowMatrix& A,
01641                               int NumSameIDs,
01642                               int NumPermuteIDs,
01643                               int* PermuteToLIDs,
01644                               int* PermuteFromLIDs,
01645                               const Epetra_OffsetIndex * Indexor,
01646                               Epetra_CombineMode CombineMode);
01647 
01648   template<typename int_type>
01649     int TUnpackAndCombine(const Epetra_SrcDistObject& Source,
01650                        int NumImportIDs,
01651                        int* ImportLIDs,
01652                        int LenImports,
01653                        char* Imports,
01654                        int& SizeOfPacket,
01655                        Epetra_Distributor& Distor,
01656                        Epetra_CombineMode CombineMode,
01657                        const Epetra_OffsetIndex * Indexor);
01658 
01659   // Used for fused[import|export] constructors
01660   template<class TransferType>
01661   void FusedTransfer(const Epetra_CrsMatrix & SourceMatrix,
01662          const TransferType & RowTransfer,
01663          const Epetra_Map * DomainMap,
01664          const Epetra_Map * RangeMap,
01665          bool RestrictCommunicator);
01666 
01667  public:
01668 
01669   void FusedImport(const Epetra_CrsMatrix & SourceMatrix,
01670        const Epetra_Import & RowImporter,
01671        const Epetra_Map * DomainMap,
01672        const Epetra_Map * RangeMap,
01673        bool RestrictCommunicator);
01674 
01675   void FusedExport(const Epetra_CrsMatrix & SourceMatrix,
01676        const Epetra_Export & RowExporter,
01677        const Epetra_Map * DomainMap,
01678        const Epetra_Map * RangeMap,
01679        bool RestrictCommunicator);
01680 
01681 
01682 };
01683 #endif /* EPETRA_CRSMATRIX_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines