|
EpetraExt
Development
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2011) Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 //@HEADER 00041 00042 #ifndef EPETRAEXT_MMHELPERS_H 00043 #define EPETRAEXT_MMHELPERS_H 00044 00045 #include <EpetraExt_ConfigDefs.h> 00046 #include <Epetra_DistObject.h> 00047 #include <Epetra_Map.h> 00048 #include <vector> 00049 #include <set> 00050 #include <map> 00051 00052 class Epetra_CrsMatrix; 00053 00054 namespace EpetraExt { 00055 00056 //struct that holds views of the contents of a CrsMatrix. These 00057 //contents may be a mixture of local and remote rows of the 00058 //actual matrix. 00059 class CrsMatrixStruct { 00060 public: 00061 CrsMatrixStruct(); 00062 00063 virtual ~CrsMatrixStruct(); 00064 00065 void deleteContents(); 00066 00067 int numRows; 00068 int* numEntriesPerRow; 00069 int** indices; 00070 double** values; 00071 bool* remote; 00072 int numRemote; 00073 const Epetra_Map* origRowMap; 00074 const Epetra_Map* rowMap; 00075 const Epetra_Map* colMap; 00076 const Epetra_Map* domainMap; 00077 const Epetra_Map* importColMap; 00078 Epetra_CrsMatrix* importMatrix; 00079 }; 00080 00081 int dumpCrsMatrixStruct(const CrsMatrixStruct& M); 00082 00083 class CrsWrapper { 00084 public: 00085 virtual ~CrsWrapper(){} 00086 00087 virtual const Epetra_Map& RowMap() const = 0; 00088 00089 virtual bool Filled() = 0; 00090 00091 virtual int InsertGlobalValues(int GlobalRow, int NumEntries, double* Values, int* Indices) = 0; 00092 00093 virtual int SumIntoGlobalValues(int GlobalRow, int NumEntries, double* Values, int* Indices) = 0; 00094 }; 00095 00096 class CrsWrapper_Epetra_CrsMatrix : public CrsWrapper { 00097 public: 00098 CrsWrapper_Epetra_CrsMatrix(Epetra_CrsMatrix& epetracrsmatrix); 00099 virtual ~CrsWrapper_Epetra_CrsMatrix(); 00100 00101 const Epetra_Map& RowMap() const; 00102 00103 bool Filled(); 00104 00105 int InsertGlobalValues(int GlobalRow, int NumEntries, double* Values, int* Indices); 00106 int SumIntoGlobalValues(int GlobalRow, int NumEntries, double* Values, int* Indices); 00107 00108 private: 00109 Epetra_CrsMatrix& ecrsmat_; 00110 }; 00111 00112 class CrsWrapper_GraphBuilder : public CrsWrapper { 00113 public: 00114 CrsWrapper_GraphBuilder(const Epetra_Map& emap); 00115 virtual ~CrsWrapper_GraphBuilder(); 00116 00117 const Epetra_Map& RowMap() const {return rowmap_; } 00118 00119 bool Filled(); 00120 00121 int InsertGlobalValues(int GlobalRow, int NumEntries, double* Values, int* Indices); 00122 int SumIntoGlobalValues(int GlobalRow, int NumEntries, double* Values, int* Indices); 00123 00124 std::map<int,std::set<int>*>& get_graph(); 00125 00126 int get_max_row_length() { return max_row_length_; } 00127 00128 private: 00129 std::map<int,std::set<int>*> graph_; 00130 const Epetra_Map& rowmap_; 00131 int max_row_length_; 00132 }; 00133 00134 void insert_matrix_locations(CrsWrapper_GraphBuilder& graphbuilder, 00135 Epetra_CrsMatrix& C); 00136 00137 void pack_outgoing_rows(const Epetra_CrsMatrix& mtx, 00138 const std::vector<int>& proc_col_ranges, 00139 std::vector<int>& send_rows, 00140 std::vector<int>& rows_per_send_proc); 00141 00142 inline 00143 std::pair<int,int> get_col_range(const Epetra_Map& emap) 00144 { 00145 return std::make_pair(emap.MinMyGID(),emap.MaxMyGID()); 00146 } 00147 00148 std::pair<int,int> get_col_range(const Epetra_CrsMatrix& mtx); 00149 00150 }//namespace EpetraExt 00151 00152 #endif 00153
1.7.6.1