42 #include "Epetra_Map.h" 43 #include "Epetra_Time.h" 44 #include "Epetra_CrsMatrix.h" 45 #include "Epetra_Vector.h" 46 #include "Epetra_SerialDenseVector.h" 47 #include "Epetra_Flops.h" 49 #include "Epetra_MpiComm.h" 52 #include "Epetra_SerialComm.h" 54 #include "Epetra_Version.h" 55 #include "Trilinos_Util_CrsMatrixGallery.h" 62 int main(
int argc,
char *argv[])
64 int ierr = 0, i, forierr = 0;
71 MPI_Init(&argc,&argv);
74 MPI_Comm_size(MPI_COMM_WORLD, &size);
75 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
76 Epetra_MpiComm Comm( MPI_COMM_WORLD );
82 Epetra_SerialComm Comm;
89 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
96 int MyPID = Comm.MyPID();
97 int NumProc = Comm.NumProc();
99 if(verbose && MyPID==0)
100 cout << Epetra_Version() << endl << endl;
102 if (verbose) cout <<
"Processor "<<MyPID<<
" of "<< NumProc
103 <<
" is alive."<<endl;
106 CrsMatrixGallery laplace_2d(
"laplace_2d", Comm);
107 laplace_2d.Set(
"problem_size",Comm.NumProc()*Comm.NumProc()*4);
108 Epetra_CrsMatrix * laplace_2d_matrix = laplace_2d.GetMatrix();
109 if (verbose) cout <<
"Orig matrix = " << *laplace_2d_matrix << endl;
110 const Epetra_Map * origRowMap = laplace_2d.GetMap();
111 int * origGids = origRowMap->MyGlobalElements();
114 Epetra_IntSerialDenseVector newRowMapGids(origRowMap->NumMyElements()/2 + 1);
115 int numNewRowGids = 0;
116 for (
int i=0; i<origRowMap->NumMyElements(); i=i+2)
117 newRowMapGids[numNewRowGids++] = origGids[i];
118 Epetra_Map newRowMap(-1, numNewRowGids, newRowMapGids.Values(), 0, origRowMap->Comm());
125 Epetra_CrsMatrix & subA = subMatrixTransform(*laplace_2d_matrix);
126 if (verbose) cout <<
"Sub matrix (every other row/column) = " << subA << endl;
130 (*laplace_2d_matrix)[0][0] = 12.0;
131 if (verbose) cout <<
"Orig matrix = " << *laplace_2d_matrix << endl;
132 subMatrixTransform.fwd();
133 assert(subA[0][0]==12.0);
134 if (verbose) cout <<
"Sub matrix (every other row/column) = " << subA << endl;
139 if (verbose) cout <<
"Sub matrix (every other row/column) = " << subA << endl;
140 subMatrixTransform.rvs();
141 assert((*laplace_2d_matrix)[0][0]==24.0);
142 if (verbose) cout <<
"Orig matrix = " << *laplace_2d_matrix << endl;
144 if (Comm.MyPID()==0) cout <<
"EpetraExt::CrsMatrix_SubCopy tests passed." << endl;
Generates a sub-block view of a Epetra_CrsMatrix.
int main(int argc, char *argv[])