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 // SymmRCM Test routine 00030 #include <Epetra_ConfigDefs.h> 00031 #include "EpetraExt_Version.h" 00032 00033 #ifdef EPETRA_MPI 00034 #include "Epetra_MpiComm.h" 00035 #include <mpi.h> 00036 #endif 00037 #include "Epetra_SerialComm.h" 00038 #include "Epetra_Time.h" 00039 #include "Epetra_BlockMap.h" 00040 #include "Epetra_CrsGraph.h" 00041 #include "Epetra_CrsMatrix.h" 00042 #include "Epetra_Vector.h" 00043 00044 //#include "Trilinos_Util.h" 00045 00046 #include "EpetraExt_Zoltan_CrsGraph.h" 00047 //#include "EpetraExt_ZoltanOrder_CrsGraph.h" 00048 #include "EpetraExt_LPTrans_From_GraphTrans.h" 00049 #include "../epetra_test_err.h" 00050 00051 #define perror(str) { fprintf(stderr,"%s\n",str); exit(-1); } 00052 #define perror1(str,ierr) { fprintf(stderr,"%s %d\n",str,ierr); exit(ierr); } 00053 00054 int main(int argc, char *argv[]) { 00055 00056 int i, ierr=0, returnierr=0; 00057 00058 #ifdef EPETRA_MPI 00059 00060 // Initialize MPI 00061 00062 MPI_Init(&argc,&argv); 00063 int size, rank; // Number of MPI processes, My process ID 00064 00065 MPI_Comm_size(MPI_COMM_WORLD, &size); 00066 MPI_Comm_rank(MPI_COMM_WORLD, &rank); 00067 00068 #else 00069 00070 int size = 1; // Serial case (not using MPI) 00071 int rank = 0; 00072 00073 #endif 00074 00075 bool verbose = false; 00076 00077 // Check if we should print results to standard out 00078 // if (argc>2) if (argv[2][0]=='-' && argv[2][1]=='v') verbose = true; 00079 00080 #ifdef EPETRA_MPI 00081 Epetra_MpiComm Comm(MPI_COMM_WORLD); 00082 #else 00083 Epetra_SerialComm Comm; 00084 #endif 00085 if (!verbose) Comm.SetTracebackMode(0); // This should shut down any error traceback reporting 00086 00087 int MyPID = Comm.MyPID(); 00088 int NumProc = Comm.NumProc(); 00089 00090 bool verbose_all = verbose; 00091 00092 if (verbose) verbose = (MyPID==0); 00093 00094 if (verbose) cout << EpetraExt::EpetraExt_Version() << endl << endl; 00095 00096 Comm.Barrier(); 00097 00098 if (verbose_all) cout << Comm << endl << flush; 00099 00100 Comm.Barrier(); 00101 00102 /* 00103 //Read in Matrix File and distribute 00104 int NumGlobalEqs; 00105 int NumLocalEqs; 00106 int NumNZs; 00107 int *NumRowNZs; 00108 double *Values; 00109 double *Xprime; 00110 double *B; 00111 double *X; 00112 int *Bindx; 00113 int NUpdate; 00114 int *Update; 00115 00116 Trilinos_Util_read_hb(argv[1], Comm.MyPID(), &NumGlobalEqs, &NumNZs, &Values, &Bindx, &Xprime, &B, &X ); 00117 Trilinos_Util_distrib_msr_matrix( Comm, &NumGlobalEqs, &NumNZs, &NUpdate, &Update, &Values, &Bindx, &Xprime, &B, &X ); 00118 00119 NumLocalEqs = NUpdate; 00120 NumRowNZs = new int[NumLocalEqs]; 00121 for( int i = 0; i < NumLocalEqs; ++i ) NumRowNZs[i] = Bindx[i+1]-Bindx[i]+1; 00122 00123 Epetra_Map Map(NumGlobalEqs,NumLocalEqs,Update,0,Comm); 00124 00125 if( verbose ) cout << "Building Epetra_CrsMatrix" << endl; 00126 00127 Epetra_CrsMatrix A(Copy, Map, NumRowNZs ); 00128 00129 //Add individual rows 00130 double *RowVals; 00131 int *ColInds; 00132 for( int i = 0; i < NumLocalEqs; ++i ) 00133 { 00134 RowVals = Values + Bindx[i]; 00135 ColInds = Bindx + Bindx[i]; 00136 NumEntries = Bindx[i+1] - Bindx[i]; 00137 ierr = A.InsertGlobalValues( Update[i], NumEntries, RowVals, ColInds ); 00138 if( ierr ) { printf("Row %d:", Update[Row] ); perror1("Error Putting Row: ",ierr); } 00139 ierr = A.InsertGlobalValues( Update[i], 1, Values+i, Update+i); 00140 if( ierr ) { perror1("Error Putting Diag: ",ierr); } 00141 } 00142 00143 ierr = A.FillComplete(); 00144 if( ierr ) perror1("Error in FillComplete",ierr); 00145 00146 Epetra_Vector XX(Copy,Map,X); 00147 Epetra_Vector BB(Copy,Map,B); 00148 00149 Epetra_LinearProblem Prob(&A,&XX,&BB); 00150 00151 //Generate Zoltan Load Balanced Version of Linear Problem 00152 if( verbose ) cout << "Creating Zoltan Partitioning Transform!\n"; 00153 00154 EpetraExt::CrsGraph_Zoltan * ZoltanTrans = new EpetraExt::CrsGraph_Zoltan(); 00155 EpetraExt::LinearProblem_GraphTrans * ZoltanLPTrans = 00156 new EpetraExt::LinearProblem_GraphTrans( 00157 *(dynamic_cast<EpetraExt::StructuralSameTypeTransform<Epetra_CrsGraph>*>(ZoltanTrans)) ); 00158 00159 if( verbose ) cout << "Creating Load Balanced Linear Problem\n"; 00160 Epetra_LinearProblem &BalancedProb = (*ZoltanLPTrans)(Prob); 00161 00162 EpetraExt::CrsGraph_SymmRCM * RCMTrans = new EpetraExt::CrsGraph_SymmRCM(); 00163 EpetraExt::LinearProblem_GraphTrans * RCMLPTrans = 00164 new EpetraExt::LinearProblem_GraphTrans( 00165 *(dynamic_cast<EpetraExt::StructuralSameTypeTransform<Epetra_CrsGraph>*>(RCMTrans)) ); 00166 00167 if( verbose ) cout << "Creating SymmRCMed Linear Problem\n"; 00168 Epetra_LinearProblem &RCMProb = (*RCMLPTrans)(BalancedProb); 00169 */ 00170 00171 #ifdef EPETRA_MPI 00172 MPI_Finalize(); 00173 #endif 00174 00175 return returnierr; 00176 } 00177
1.3.9.1