Amesos Package Browser (Single Doxygen Collection) Development
cxx_memleak_main.cpp
Go to the documentation of this file.
00001 #include "Amesos_ConfigDefs.h"
00002 
00003 #ifdef HAVE_MPI
00004 #include "mpi.h"
00005 #include "Epetra_MpiComm.h"
00006 #else
00007 #include "Epetra_SerialComm.h"
00008 #endif
00009 #include "Epetra_Map.h"
00010 #include "Epetra_Vector.h"
00011 #include "Epetra_Util.h"
00012 #include "Amesos_Klu.h"
00013 #include "Amesos_TestRowMatrix.h"
00014 #include "Teuchos_ParameterList.hpp"
00015 #include "Galeri_Maps.h"
00016 #include "Galeri_CrsMatrices.h"
00017 #include "Galeri_Utils.h"
00018 
00019 #include "Teuchos_ParameterList.hpp"
00020 
00021 #include <vector>
00022 
00023 using namespace Galeri;
00024 
00025 //============ //
00026 // main driver //
00027 //============ //
00028 
00029 
00030 Teuchos::RCP<Epetra_Map> buildMap(Epetra_Comm & Comm)
00031 {
00032    std::vector<int> vec(4);
00033    int data[] = {0, 1 , 3 , 4};
00034   
00035    for(int i=0;i<4;i++)
00036       vec[i] = 6*Comm.MyPID()+data[i];
00037 
00038    return Teuchos::rcp(new Epetra_Map(-1,4,&vec[0],0,Comm));
00039 }
00040 
00041 Teuchos::RCP<Epetra_CrsMatrix> buildMatrix(Epetra_Map & map)
00042 {
00043    Teuchos::RCP<Epetra_CrsMatrix> A = Teuchos::rcp(new Epetra_CrsMatrix(Copy,map,3));
00044 
00045    int ind[] = {0,0,0};
00046    double values[] = {-1,2,-1};
00047 
00048    int * indPtr;
00049    double * valuesPtr;
00050    int entries = 3;
00051 
00052    for(int i=0;i<4;i++) {
00053       int gid = map.GID(i);
00054       ind[0] = map.GID(i-1);
00055       ind[1] = map.GID(i);
00056       ind[2] = map.GID(i+1);
00057 
00058       indPtr = ind;
00059       valuesPtr = values;
00060       entries = 3;
00061       if(i==0) {
00062          entries = 2;
00063          indPtr = ind+1;
00064          valuesPtr = values+1;
00065       }
00066       else if(i==3) {
00067          entries = 2;
00068       }
00069       A->InsertGlobalValues(gid,entries,valuesPtr,indPtr);
00070    }
00071    A->FillComplete();
00072 
00073    return A;
00074 }
00075 
00076 int main(int argc, char *argv[]) 
00077 {
00078 #ifdef HAVE_MPI
00079   MPI_Init(&argc, &argv);
00080   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00081 #else
00082   Epetra_SerialComm Comm;
00083 #endif
00084 
00085   Teuchos::ParameterList GaleriList;
00086 
00087   Teuchos::RCP<Epetra_Map> Map = buildMap(Comm);
00088   Teuchos::RCP<Epetra_CrsMatrix> Matrix = buildMatrix(*Map);
00089  
00090   int NumVectors = 2;
00091   Epetra_MultiVector x(*Map,NumVectors);
00092   Epetra_MultiVector x_exact(*Map,NumVectors);
00093   Epetra_MultiVector b(*Map,NumVectors);
00094   x_exact.Random();
00095   Matrix->Apply(x_exact,b);
00096 
00097   // =========== //
00098   // AMESOS PART //
00099   // =========== //
00100 
00101   Epetra_LinearProblem Problem(&*Matrix, &x, &b);
00102   Amesos_Klu Solver(Problem);
00103 
00104   Teuchos::ParameterList List;
00105   List.set("Reindex", true);
00106 
00107   Solver.SetParameters(List); 
00108 
00109   AMESOS_CHK_ERR(Solver.Solve());
00110   AMESOS_CHK_ERR(Solver.Solve());
00111 
00112   double norm = ComputeNorm(&*Matrix, &x_exact, &b);
00113   if (Comm.MyPID() == 0)
00114     std::cout << "norm = " << norm << std::endl;
00115 
00116   if (norm > 1e-5)
00117     exit(EXIT_FAILURE);
00118 
00119 #ifdef HAVE_MPI
00120   MPI_Finalize();
00121 #endif
00122 
00123   return(EXIT_SUCCESS);
00124 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines