49 #include "Petra_Comm.h"
50 #include "Petra_Map.h"
51 #include "Petra_Time.h"
52 #include "Petra_RDP_MultiVector.h"
53 #include "Petra_RDP_Vector.h"
54 #include "Petra_RDP_CRS_Matrix.h"
66 Petra_RDP_CRS_Matrix*
readMatrixIn(FILE *dataFile, Petra_Comm& Comm);
68 Petra_RDP_Vector*
readVectorIn(FILE *dataFile, Petra_Comm& Comm);
70 Petra_RDP_Vector* xptr,
71 Petra_RDP_Vector* bptr);
74 int main(
int argc,
char *argv[])
80 MPI_Init(&argc,&argv);
82 MPI_Comm_size(MPI_COMM_WORLD, &size);
83 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
90 Petra_Comm & Comm = *
new Petra_Comm( MPI_COMM_WORLD );
92 Petra_Comm & Comm = *
new Petra_Comm();
95 int MyPID = Comm.MyPID();
96 int NumProc = Comm.NumProc();
99 bool verbose = (MyPID==0);
106 cout <<
" reading in F matrix " << endl;
107 dataFile = fopen(
"F.data",
"r");
108 Petra_RDP_CRS_Matrix* Fptr =
readMatrixIn(dataFile, Comm);
112 cout <<
" reading in B matrix " << endl;
113 dataFile = fopen(
"B.data",
"r");
116 Petra_RDP_CRS_Matrix&
B = *Bptr;
117 cout <<
"global rows " << B.NumGlobalRows() << endl;
118 cout <<
"global cols " << B.NumGlobalCols() << endl;
119 cout <<
"my local rows " << B.NumMyRows() << endl;
120 cout <<
"my local cols " << B.NumMyCols() << endl;
123 cout <<
"reading in vector b " << endl;
124 dataFile = fopen(
"rhs.data",
"r");
141 int NumGlobalElements = 0;
145 fscanf(dataFile,
"%d", &NumGlobalElements);
147 fscanf(dataFile,
"%d", &maxNumNz);
151 Petra_Map& Map = *
new Petra_Map(NumGlobalElements, 0, Comm);
154 int NumMyElements = Map.NumMyElements();
156 int * MyGlobalElements =
new int[NumMyElements];
157 Map.MyGlobalElements(MyGlobalElements);
159 int * NumNz =
new int[NumMyElements];
160 for (i=0; i<NumMyElements; i++)
162 fscanf(dataFile,
"%d", &NumNz[i]);
168 Petra_RDP_CRS_Matrix* Mptr =
new Petra_RDP_CRS_Matrix(
Copy, Map, NumNz);
169 Petra_RDP_CRS_Matrix& M = *Mptr;
170 double *Values =
new double[maxNumNz];
171 int *Indices =
new int[maxNumNz];
178 fscanf(dataFile,
"%d", &nnzM);
182 int * iM =
new int[nnzM];
183 int * jM =
new int[nnzM];
184 double * sM =
new double[nnzM];
185 for (i=0; i<nnzM; i++)
187 fscanf(dataFile,
"%d %d %lg", &iM[i], &jM[i], &sM[i]);
200 for (i=0; i<NumGlobalElements; i++)
203 for (j=0; j<NumNz[i]; j++)
206 Indices[j] = jM[offset + j];
207 Values[j] = sM[offset + j];
213 NumEntries = NumNz[i];
214 assert(M.InsertGlobalValues(MyGlobalElements[i],
215 NumEntries, Values, Indices)==0);
217 offset = offset + NumNz[i];
222 assert(M.FillComplete()==0);
224 cout <<
"nonzeros = " << M.NumGlobalNonzeros() << endl;
225 cout <<
"rows = " << M.NumGlobalRows() << endl;
226 cout <<
"cols = " << M.NumGlobalCols() << endl;
241 int NumGlobalElements = 0;
245 fscanf(dataFile,
"%d", &NumGlobalElements);
247 fscanf(dataFile,
"%d", &maxNumNz);
251 Petra_Map& Map = *
new Petra_Map(NumGlobalElements, 0, Comm);
255 Petra_Map& ColMap = *
new Petra_Map(24, 0, Comm);
258 int NumMyElements = Map.NumMyElements();
260 int * MyGlobalElements =
new int[NumMyElements];
261 Map.MyGlobalElements(MyGlobalElements);
263 int * NumNz =
new int[NumMyElements];
264 for (i=0; i<NumMyElements; i++)
266 fscanf(dataFile,
"%d", &NumNz[i]);
272 Petra_RDP_CRS_Matrix* Mptr =
new Petra_RDP_CRS_Matrix(
Copy, Map, NumNz);
273 Petra_RDP_CRS_Matrix& M = *Mptr;
274 double *Values =
new double[maxNumNz];
275 int *Indices =
new int[maxNumNz];
282 fscanf(dataFile,
"%d", &nnzM);
286 int * iM =
new int[nnzM];
287 int * jM =
new int[nnzM];
288 double * sM =
new double[nnzM];
289 for (i=0; i<nnzM; i++)
291 fscanf(dataFile,
"%d %d %lg", &iM[i], &jM[i], &sM[i]);
304 for (i=0; i<NumGlobalElements; i++)
307 for (j=0; j<NumNz[i]; j++)
310 Indices[j] = jM[offset + j];
311 Values[j] = sM[offset + j];
317 NumEntries = NumNz[i];
318 assert(M.InsertGlobalValues(MyGlobalElements[i],
319 NumEntries, Values, Indices)==0);
321 offset = offset + NumNz[i];
326 assert(M.FillComplete(ColMap, Map)==0);
328 cout <<
"nonzeros = " << M.NumGlobalNonzeros() << endl;
329 cout <<
"rows = " << M.NumGlobalRows() << endl;
330 cout <<
"cols = " << M.NumGlobalCols() << endl;
346 int NumGlobalElements = 0;
350 fscanf(dataFile,
"%d", &NumGlobalElements);
351 fscanf(dataFile,
"%d", &NzElms);
354 Petra_Map& Map = *
new Petra_Map(NumGlobalElements, 0, Comm);
357 int NumMyElements = Map.NumMyElements();
358 int * MyGlobalElements =
new int[NumMyElements];
359 Map.MyGlobalElements(MyGlobalElements);
362 Petra_RDP_Vector* vptr =
new Petra_RDP_Vector(Map);
363 Petra_RDP_Vector& v = *vptr;
366 double * myArray =
new double[NumMyElements];
371 for (i=0; i<NzElms; i++)
373 fscanf(dataFile,
"%d %lg", &tempInd, &tempVal);
374 v[tempInd] = tempVal;
385 Petra_RDP_Vector* xptr,
386 Petra_RDP_Vector* bptr)
388 Petra_RDP_CRS_Matrix&
A = *Aptr;
389 Petra_RDP_Vector& x = *xptr;
390 Petra_RDP_Vector& b = *bptr;
Petra_RDP_CRS_Matrix * readMatrixIn(FILE *dataFile, Petra_Comm &Comm)
Petra_RDP_Vector * readVectorIn(FILE *dataFile, Petra_Comm &Comm)
Petra_RDP_CRS_Matrix * readRectMatrixIn(FILE *dataFile, Petra_Comm &Comm)
void matVecTest(Petra_RDP_CRS_Matrix *Aptr, Petra_RDP_Vector *xptr, Petra_RDP_Vector *bptr)
int main(int argc, char *argv[])