46 #include "Epetra_CrsMatrix.h" 47 #include "Epetra_VbrMatrix.h" 48 #include "Epetra_Vector.h" 49 #include "Epetra_MultiVector.h" 50 #include "Epetra_LocalMap.h" 51 #include "Epetra_IntVector.h" 52 #include "Epetra_Map.h" 55 #include "Epetra_MpiComm.h" 58 #include "Epetra_SerialComm.h" 61 #include "Epetra_Time.h" 63 #include "Trilinos_Util.h" 65 int checkResults(Epetra_RowMatrix *
A, Epetra_CrsMatrix * transA,
66 Epetra_Vector * xexact,
bool verbose);
68 int main(
int argc,
char *argv[])
74 MPI_Init(&argc,&argv);
75 Epetra_MpiComm comm(MPI_COMM_WORLD);
77 Epetra_SerialComm comm;
85 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
87 if (!verbose) comm.SetTracebackMode(0);
89 if (verbose) std::cout << comm << std::endl << std::flush;
91 if (verbose) verbose = (comm.MyPID()==0);
97 int ny = comm.NumProc()*nx;
107 int xoff[] = {-1, 0, 1, -1, 0, 1, 0};
108 int yoff[] = {-1, -1, -1, 0, 0, 0, 1};
111 Epetra_CrsMatrix *
A;
112 Epetra_Vector * x, * b, * xexact;
114 Trilinos_Util_GenerateCrsProblem(nx, ny, npoints, xoff, yoff, comm, map,
A, x, b, xexact);
118 std::cout << *
A << std::endl;
119 std::cout <<
"X exact = " << std::endl << *xexact << std::endl;
120 std::cout <<
"B = " << std::endl << *b << std::endl;
124 Epetra_Time timer(comm);
126 double start = timer.ElapsedTime();
131 if (verbose) std::cout <<
"\nTime to construct transposer = " << timer.ElapsedTime() - start << std::endl;
133 Epetra_CrsMatrix & transA =
dynamic_cast<Epetra_CrsMatrix&
>(transposer(*
A));
135 start = timer.ElapsedTime();
136 if (verbose) std::cout <<
"\nTime to create transpose matrix = " << timer.ElapsedTime() - start << std::endl;
146 for (i=0; i<
A->NumMyRows(); i++)
147 A->SumIntoMyValues(i, 1, &Value, &i);
149 start = timer.ElapsedTime();
152 if (verbose) std::cout <<
"\nTime to update transpose matrix = " << timer.ElapsedTime() - start << std::endl;
162 if (verbose) std::cout << std::endl <<
"Checking transposer for VbrMatrix objects" << std::endl<< std::endl;
165 int sizes[] = {4, 6, 5, 3};
167 Epetra_VbrMatrix * Avbr;
168 Epetra_BlockMap * bmap;
170 Trilinos_Util_GenerateVbrProblem(nx, ny, npoints, xoff, yoff, nsizes, sizes,
171 comm, bmap, Avbr, x, b, xexact);
175 std::cout << *Avbr << std::endl;
176 std::cout <<
"X exact = " << std::endl << *xexact << std::endl;
177 std::cout <<
"B = " << std::endl << *b << std::endl;
180 start = timer.ElapsedTime();
183 Epetra_CrsMatrix & transA1 =
dynamic_cast<Epetra_CrsMatrix&
>(transposer1(*Avbr));
184 if (verbose) std::cout <<
"\nTime to create transpose matrix = " << timer.ElapsedTime() - start << std::endl;
193 Epetra_Vector invRowSums(Avbr->RowMap());
195 Avbr->InvRowSums(invRowSums);
196 Avbr->LeftScale(invRowSums);
198 start = timer.ElapsedTime();
200 if (verbose) std::cout <<
"\nTime to update transpose matrix = " << timer.ElapsedTime() - start << std::endl;
218 Epetra_Vector * xexact,
bool verbose) {
220 int n =
A->NumGlobalRows();
222 if (
n<100) std::cout <<
"A transpose = " << std::endl << *transA << std::endl;
224 Epetra_Vector x1(
View,
A->OperatorDomainMap(), &((*xexact)[0]));
225 Epetra_Vector b1(
A->OperatorRangeMap());
227 A->SetUseTranspose(
true);
229 Epetra_Time timer(
A->Comm());
230 double start = timer.ElapsedTime();
232 if (verbose) std::cout <<
"\nTime to compute b1: matvec with original matrix using transpose flag = " << timer.ElapsedTime() - start << std::endl;
234 if (
n<100) std::cout <<
"b1 = " << std::endl << b1 << std::endl;
235 Epetra_Vector x2(
View,transA->OperatorRangeMap(), &((*xexact)[0]));
236 Epetra_Vector b2(transA->OperatorDomainMap());
237 start = timer.ElapsedTime();
238 transA->Multiply(
false, x2, b2);
239 if (verbose) std::cout <<
"\nTime to compute b2: matvec with transpose matrix = " << timer.ElapsedTime() - start << std::endl;
241 if (
n<100) std::cout <<
"b1 = " << std::endl << b1 << std::endl;
244 Epetra_Vector resid(
A->OperatorDomainMap());
246 resid.Update(1.0, b1, -1.0, b2, 0.0);
247 resid.Norm2(&residual);
248 if (verbose) std::cout <<
"Norm of b1 - b2 = " << residual << std::endl;
252 if (residual > 1.0e-10) ierr++;
254 if (ierr!=0 && verbose) std::cerr <<
"Status: Test failed" << std::endl;
255 else if (verbose) std::cerr <<
"Status: Test passed" << std::endl;
std::string EpetraExt_Version()
Transform to form the explicit transpose of a Epetra_RowMatrix.
int checkResults(Epetra_RowMatrix *A, Epetra_CrsMatrix *transA, Epetra_Vector *xexact, bool verbose)
bool fwd()
Foward Data Migration.
int main(int argc, char *argv[])