00001 #include "AnasaziConfigDefs.hpp"
00002 #include "AnasaziEpetraAdapter.hpp"
00003 #include "AnasaziMVOPTester.hpp"
00004 #include "AnasaziBasicOutputManager.hpp"
00005
00006 #include "Epetra_Map.h"
00007 #include "Epetra_CrsMatrix.h"
00008 #include "Epetra_Comm.h"
00009
00010 #ifdef HAVE_MPI
00011 #include "mpi.h"
00012 #include "Epetra_MpiComm.h"
00013 #else
00014 #include "Epetra_SerialComm.h"
00015 #endif
00016
00017 int main(int argc, char *argv[])
00018 {
00019
00020 #ifdef HAVE_MPI
00021
00022 MPI_Init(&argc,&argv);
00023 Epetra_MpiComm Comm(MPI_COMM_WORLD);
00024 #else
00025
00026 Epetra_SerialComm Comm;
00027 #endif
00028
00029
00030 Teuchos::RCP<Anasazi::OutputManager<double> > MyOM = Teuchos::rcp( new Anasazi::BasicOutputManager<double>() );
00031 MyOM->setVerbosity( Anasazi::Warnings );
00032 MyOM->stream(Anasazi::Errors) << Anasazi::Anasazi_Version() << endl << endl;
00033
00034
00035 int dim = 100;
00036 int blockSize = 5;
00037
00038
00039
00040 Epetra_Map Map(dim, 0, Comm);
00041
00042
00043 int NumMyElements = Map.NumMyElements();
00044 int * MyGlobalElements = new int[NumMyElements];
00045 Map.MyGlobalElements(MyGlobalElements);
00046
00047
00048
00049
00050 int * NumNz = new int[NumMyElements];
00051
00052
00053
00054 for (int i=0; i<NumMyElements; i++) {
00055 if (MyGlobalElements[i]==0 || MyGlobalElements[i] == dim-1) {
00056 NumNz[i] = 2;
00057 }
00058 else {
00059 NumNz[i] = 3;
00060 }
00061 }
00062
00063
00064 Teuchos::RCP<Epetra_CrsMatrix> A
00065 = Teuchos::rcp( new Epetra_CrsMatrix(Copy, Map, NumNz) );
00066
00067
00068
00069
00070 double *Values = new double[2];
00071 Values[0] = -1.0; Values[1] = -1.0;
00072 int *Indices = new int[2];
00073 double two = 2.0;
00074 int NumEntries;
00075 for (int i=0; i<NumMyElements; i++) {
00076 if (MyGlobalElements[i]==0) {
00077 Indices[0] = 1;
00078 NumEntries = 1;
00079 }
00080 else if (MyGlobalElements[i] == dim-1) {
00081 Indices[0] = dim-2;
00082 NumEntries = 1;
00083 }
00084 else {
00085 Indices[0] = MyGlobalElements[i]-1;
00086 Indices[1] = MyGlobalElements[i]+1;
00087 NumEntries = 2;
00088 }
00089 int ierr = A->InsertGlobalValues(MyGlobalElements[i],NumEntries,Values,Indices);
00090 assert(ierr==0);
00091
00092 ierr = A->InsertGlobalValues(MyGlobalElements[i],1,&two,MyGlobalElements+i);
00093 assert(ierr==0);
00094 }
00095
00096
00097 int ierr = A->FillComplete();
00098 assert(ierr==0);
00099
00100
00101
00102 typedef Epetra_MultiVector MV;
00103 typedef Epetra_Operator OP;
00104 typedef Anasazi::OperatorTraits<double, MV, OP> OPT;
00105
00106
00107
00108 Teuchos::RCP<MV> ivec
00109 = Teuchos::rcp( new MV(Map, blockSize) );
00110 ivec->Random();
00111
00112
00113 bool testret;
00114 testret = Anasazi::TestMultiVecTraits<double,MV>(MyOM,ivec);
00115 if (testret) {
00116 MyOM->print(Anasazi::Warnings,"*** PASSED TestMultiVecTraits() ***\n");
00117 }
00118 else {
00119 MyOM->print(Anasazi::Warnings,"*** FAILED TestMultiVecTraits() ***\n");
00120 }
00121
00122
00123
00124 testret = Anasazi::TestOperatorTraits<double,MV,OP>(MyOM,ivec,A);
00125 if (testret) {
00126 MyOM->print(Anasazi::Warnings,"*** PASSED TestOperatorTraits() ***\n");
00127 }
00128 else {
00129 MyOM->print(Anasazi::Warnings,"*** FAILED TestOperatorTraits() ***\n");
00130 }
00131
00132
00133 delete [] NumNz;
00134 delete [] Values;
00135 delete [] Indices;
00136 delete [] MyGlobalElements;
00137
00138 #ifdef HAVE_MPI
00139 MPI_Finalize();
00140 #endif
00141
00142 return 0;
00143 }