|
EpetraExt Development
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2001) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include <EpetraExt_Transpose_CrsGraph.h> 00030 00031 #include <Epetra_Export.h> 00032 #include <Epetra_CrsGraph.h> 00033 #include <Epetra_Map.h> 00034 00035 #include <vector> 00036 00037 namespace EpetraExt { 00038 00039 CrsGraph_Transpose:: 00040 ~CrsGraph_Transpose() 00041 { 00042 delete newObj_; 00043 } 00044 00045 CrsGraph_Transpose::NewTypeRef 00046 CrsGraph_Transpose:: 00047 operator()( OriginalTypeRef orig ) 00048 { 00049 origObj_ = &orig; 00050 00051 int nRows = orig.NumMyRows(); 00052 int nCols = orig.NumMyCols(); 00053 00054 const Epetra_BlockMap & RowMap = orig.RowMap(); 00055 00056 int numIndices; 00057 int * Indices; 00058 00059 Epetra_CrsGraph * TransposeGraph = 0; 00060 00061 if( !ignoreNonLocalCols_ && orig.DistributedGlobal() ) 00062 { 00063 std::vector<int> TransNumNZ( nCols, 0 ); 00064 for( int i = 0; i < nRows; ++i ) 00065 { 00066 orig.ExtractMyRowView( i, numIndices, Indices ); 00067 for( int j = 0; j < numIndices; ++j ) ++TransNumNZ[ Indices[j] ]; 00068 } 00069 00070 std::vector< std::vector<int> > TransIndices( nCols ); 00071 for( int i = 0; i < nCols; ++i ) 00072 if( TransNumNZ[i] ) 00073 { 00074 TransIndices[i].resize( TransNumNZ[i] ); 00075 TransNumNZ[i] = 0; 00076 } 00077 00078 for( int i = 0; i < nRows; ++i ) 00079 { 00080 orig.ExtractMyRowView( i, numIndices, Indices ); 00081 for( int j = 0; j < numIndices; ++j ) 00082 TransIndices[ Indices[j] ][ TransNumNZ[ Indices[j] ]++ ] = i; 00083 } 00084 00085 Epetra_CrsGraph SharedTransGraph( View, orig.ImportMap(), RowMap, &TransNumNZ[0] ); 00086 for( int i = 0; i < nCols; ++i ) 00087 if( TransNumNZ[i] ) SharedTransGraph.InsertMyIndices( i, TransNumNZ[i], &TransIndices[i][0] ); 00088 SharedTransGraph.FillComplete(); 00089 00090 TransposeGraph = new Epetra_CrsGraph( Copy, RowMap, 0 ); 00091 Epetra_Export Exporter( orig.ImportMap(), RowMap ); 00092 TransposeGraph->Export( SharedTransGraph, Exporter, Add ); 00093 TransposeGraph->FillComplete(); 00094 } 00095 else 00096 { 00097 std::vector<int> TransNumNZ( nRows, 0 ); 00098 for( int i = 0; i < nRows; ++i ) 00099 { 00100 orig.ExtractMyRowView( i, numIndices, Indices ); 00101 for( int j = 0; j < numIndices; ++j ) 00102 if( Indices[j] < nRows ) ++TransNumNZ[ Indices[j] ]; 00103 } 00104 00105 std::vector< std::vector<int> > TransIndices( nRows ); 00106 for( int i = 0; i < nRows; ++i ) 00107 if( TransNumNZ[i] ) 00108 { 00109 TransIndices[i].resize( TransNumNZ[i] ); 00110 TransNumNZ[i] = 0; 00111 } 00112 00113 for( int i = 0; i < nRows; ++i ) 00114 { 00115 orig.ExtractMyRowView( i, numIndices, Indices ); 00116 for( int j = 0; j < numIndices; ++j ) 00117 if( Indices[j] < nRows ) TransIndices[ Indices[j] ][ TransNumNZ[ Indices[j] ]++ ] = i; 00118 } 00119 00120 TransposeGraph = new Epetra_CrsGraph( Copy, RowMap, RowMap, &TransNumNZ[0] ); 00121 00122 for( int i = 0; i < nRows; ++i ) 00123 if( TransNumNZ[i] ) TransposeGraph->InsertMyIndices( i, TransNumNZ[i], &TransIndices[i][0] ); 00124 00125 TransposeGraph->FillComplete(); 00126 } 00127 00128 newObj_ = TransposeGraph; 00129 00130 return *TransposeGraph; 00131 } 00132 00133 } // namespace EpetraExt 00134
1.7.4