56 #include "Petra_Comm.h"
57 #include "Petra_Map.h"
58 #include "Petra_Time.h"
59 #include "Petra_RDP_CRS_Matrix.h"
61 int main(
int argc,
char *argv[])
70 MPI_Init(&argc,&argv);
73 MPI_Comm_size(MPI_COMM_WORLD, &size);
74 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
86 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
91 Petra_Comm & Comm = *
new Petra_Comm( MPI_COMM_WORLD );
93 Petra_Comm & Comm = *
new Petra_Comm();
102 int MyPID = Comm.MyPID();
103 int NumProc = Comm.NumProc();
104 if (verbose) cout <<
"Processor "<<MyPID<<
" of "<< NumProc
105 <<
" is alive."<<endl;
107 bool verbose1 = verbose;
110 if (verbose && rank!=0) verbose =
false;
112 int NumMyPoints = 10000;
113 int NumGlobalPoints = NumMyPoints*NumProc+minfn(NumProc,3);
114 if (MyPID < 3) NumMyPoints++;
116 bool DistributedGlobal = (NumGlobalPoints>NumMyPoints);
121 Petra_Map& SourceMap = *
new Petra_Map(NumGlobalPoints, NumMyPoints, 0, Comm);
124 int NumMyElements = SourceMap.NumMyElements();
125 int * SourceMyGlobalElements =
new int[NumMyElements];
126 SourceMap.MyGlobalElements(SourceMyGlobalElements);
133 Petra_RDP_Vector & RandVec = *
new Petra_RDP_Vector(SourceMap);
136 int *TargetMyGlobalElements =
new int[NumMyElements];
138 for (i=0; i< NumMyPoints/2; i++) TargetMyGlobalElements[i] = i;
139 for (i=NumMyPoints/2; i<NumMyPoints; i++) {
140 int index = abs((
int)(((
double) (NumGlobalPoints-1) ) * RandVec[i]));
141 TargetMyGlobalElements[i] = minfn(NumGlobalPoints-1,maxfn(0,index));
145 int NumPermutedIDs = 0;
146 int NumRemoteIDs = 0;
147 bool StillContiguous =
true;
148 for (i=0; i < NumMyPoints; i++) {
149 if (SourceMyGlobalElements[i]==TargetMyGlobalElements[i] && StillContiguous)
151 else if (SourceMap.MyGID(TargetMyGlobalElements[i])) {
152 StillContiguous =
false;
156 StillContiguous =
false;
160 assert(NumMyPoints==NumSameIDs+NumPermutedIDs+NumRemoteIDs);
162 Petra_Map & TargetMap = *
new Petra_Map(-1, NumMyElements, TargetMyGlobalElements, 0, Comm);
167 Petra_RDP_MultiVector & SourceMultiVector = *
new Petra_RDP_MultiVector(SourceMap, NumVectors);
168 for (j=0; j < NumVectors; j++)
169 for (i=0; i < NumMyElements; i++)
170 SourceMultiVector[j][i] = (
double) SourceMyGlobalElements[i]*(j+1);
174 Petra_RDP_MultiVector & TargetMultiVector = *
new Petra_RDP_MultiVector(TargetMap, NumVectors);
176 Petra_Import & Importer = *
new Petra_Import(TargetMap, SourceMap);
178 assert(TargetMultiVector.Import(SourceMultiVector, Importer,
Insert)==0);
182 for (j=0; j < NumVectors; j++)
183 for (i=0; i < NumMyElements; i++) {
184 if (TargetMultiVector[j][i]!= (
double) TargetMyGlobalElements[i]*(j+1))
185 cout <<
"TargetMultiVector["<<i<<
"]["<<j<<
"] = " << TargetMultiVector[j][i]
186 <<
" TargetMyGlobalElements[i]*(j+1) = " << TargetMyGlobalElements[i]*(j+1) << endl;
187 assert(TargetMultiVector[j][i]== (
double) TargetMyGlobalElements[i]*(j+1));
190 if (verbose) cout <<
"MultiVector Import using Importer Check OK" << endl << endl;
197 Petra_RDP_Vector & TargetVector = *
new Petra_RDP_Vector(SourceMap);
198 Petra_RDP_Vector & ExpectedTarget = *
new Petra_RDP_Vector(SourceMap);
199 Petra_RDP_Vector & SourceVector = *
new Petra_RDP_Vector(TargetMap);
201 NumSameIDs = Importer.NumSameIDs();
202 int NumPermuteIDs = Importer.NumPermuteIDs();
203 int NumExportIDs = Importer.NumExportIDs();
204 int *PermuteToLIDs = Importer.PermuteToLIDs();
205 int *PermuteFromLIDs = Importer.PermuteFromLIDs();
206 int *ExportLIDs = Importer.ExportLIDs();
207 int *ExportPIDs = Importer.ExportPIDs();
209 for (i=0; i < NumSameIDs; i++) ExpectedTarget[i] = (
double) (MyPID+1);
210 for (i=0; i < NumPermuteIDs; i++) ExpectedTarget[PermuteFromLIDs[i]] =
212 for (i=0; i < NumExportIDs; i++) ExpectedTarget[ExportLIDs[i]] +=
213 (
double) (ExportPIDs[i]+1);
215 for (i=0; i < NumMyElements; i++) SourceVector[i] = (
double) (MyPID+1);
217 assert(TargetVector.Export(SourceVector, Importer,
Add)==0);
219 for (i=0; i < NumMyElements; i++) {
220 if (TargetVector[i]!= ExpectedTarget[i])
221 cout <<
" TargetVector["<<i<<
"] = " << TargetVector[i]
222 <<
" ExpectedTarget["<<i<<
"] = " << ExpectedTarget[i] <<
" on PE " << MyPID << endl;
223 assert(TargetVector[i]== ExpectedTarget[i]);
226 if (verbose) cout <<
"Vector Export using Importer Check OK" << endl << endl;
243 Petra_Map& StandardMap = *
new Petra_Map(NumGlobalPoints, NumMyPoints, 0, Comm);
246 NumMyElements = StandardMap.NumMyElements();
247 int * StandardMyGlobalElements =
new int[NumMyElements];
248 StandardMap.MyGlobalElements(StandardMyGlobalElements);
253 Petra_CRS_Graph& StandardGraph = *
new Petra_CRS_Graph(
Copy, StandardMap, 3);
254 assert(!StandardGraph.IndicesAreGlobal());
255 assert(!StandardGraph.IndicesAreLocal());
262 int *Indices =
new int[2];
265 for (i=0; i<NumMyPoints; i++)
267 if (StandardMyGlobalElements[i]==0)
272 else if (StandardMyGlobalElements[i] == NumGlobalPoints-1)
274 Indices[0] = NumGlobalPoints-2;
279 Indices[0] = StandardMyGlobalElements[i]-1;
280 Indices[1] = StandardMyGlobalElements[i]+1;
283 assert(StandardGraph.InsertGlobalIndices(StandardMyGlobalElements[i], NumEntries, Indices)==0);
284 assert(StandardGraph.InsertGlobalIndices(StandardMyGlobalElements[i], 1, StandardMyGlobalElements+i)==0);
288 assert(StandardGraph.IndicesAreGlobal());
289 assert(StandardGraph.FillComplete()==0);
290 assert(StandardGraph.IndicesAreLocal());
291 assert(!StandardGraph.StorageOptimized());
292 StandardGraph.OptimizeStorage();
293 assert(StandardGraph.StorageOptimized());
294 assert(!StandardGraph.UpperTriangular());
295 assert(!StandardGraph.LowerTriangular());
300 Petra_RDP_CRS_Matrix& StandardMatrix = *
new Petra_RDP_CRS_Matrix(
Copy, StandardGraph);
301 assert(!StandardMatrix.IndicesAreGlobal());
302 assert(StandardMatrix.IndicesAreLocal());
309 double *Values =
new double[2];
310 Values[0] = -1.0; Values[1] = -1.0;
313 for (i=0; i<NumMyPoints; i++)
315 if (StandardMyGlobalElements[i]==0)
320 else if (StandardMyGlobalElements[i] == NumGlobalPoints-1)
322 Indices[0] = NumGlobalPoints-2;
327 Indices[0] = StandardMyGlobalElements[i]-1;
328 Indices[1] = StandardMyGlobalElements[i]+1;
331 assert(StandardMatrix.ReplaceGlobalValues(StandardMyGlobalElements[i], NumEntries, Values, Indices)==0);
332 assert(StandardMatrix.ReplaceGlobalValues(StandardMyGlobalElements[i], 1, &two, StandardMyGlobalElements+i)==0);
336 assert(StandardMatrix.IndicesAreLocal());
337 assert(StandardMatrix.FillComplete()==0);
338 assert(StandardMatrix.IndicesAreLocal());
339 assert(StandardMatrix.StorageOptimized());
340 assert(!StandardMatrix.UpperTriangular());
341 assert(!StandardMatrix.LowerTriangular());
345 int OverlapNumMyElements;
348 OverlapNumMyElements = NumMyElements + 1;
349 if (MyPID==0) OverlapNumMyElements--;
351 if (MyPID==0) OverlapMinMyGID = StandardMap.MinMyGID();
352 else OverlapMinMyGID = StandardMap.MinMyGID()-1;
354 int * OverlapMyGlobalElements =
new int[OverlapNumMyElements];
356 for (i=0; i< OverlapNumMyElements; i++) OverlapMyGlobalElements[i] = OverlapMinMyGID + i;
358 Petra_Map& OverlapMap = *
new Petra_Map(-1, OverlapNumMyElements, OverlapMyGlobalElements, 0, Comm);
362 Petra_RDP_CRS_Matrix& OverlapMatrix = *
new Petra_RDP_CRS_Matrix(
Copy, OverlapMap, 4);
363 assert(!OverlapMatrix.IndicesAreGlobal());
364 assert(!OverlapMatrix.IndicesAreLocal());
370 double pos_one = 1.0;
371 double neg_one = -1.0;
373 for (i=0; i<OverlapNumMyElements; i++)
375 int node_left = OverlapMyGlobalElements[i]-1;
376 int node_center = node_left + 1;
377 int node_right = node_left + 2;
380 assert(OverlapMatrix.InsertGlobalValues(node_center, 1, &neg_one, &node_left)==0);
381 assert(OverlapMatrix.InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
383 if (i<OverlapNumMyElements-1) {
384 assert(OverlapMatrix.InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
385 if (node_right<NumGlobalPoints)
386 assert(OverlapMatrix.InsertGlobalValues(node_center, 1, &neg_one, &node_right)==0);
393 assert(OverlapMatrix.InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
395 if (MyPID==NumProc-1) {
396 int node_center = OverlapMyGlobalElements[OverlapNumMyElements-1];
397 assert(OverlapMatrix.InsertGlobalValues(node_center, 1, &pos_one, &node_center)==0);
400 assert(OverlapMatrix.FillComplete()==0);
404 Petra_RDP_CRS_Matrix& GatheredMatrix = *
new Petra_RDP_CRS_Matrix(
Copy, StandardGraph);
405 Petra_Export & Exporter = *
new Petra_Export(OverlapMap, StandardMap);
406 assert(GatheredMatrix.Export(OverlapMatrix, Exporter,
Add)==0);
407 assert(GatheredMatrix.FillComplete()==0);
411 int StandardNumEntries, GatheredNumEntries;
412 int * StandardIndices, * GatheredIndices;
413 double * StandardValues, * GatheredValues;
415 int StandardNumMyNonzeros = StandardMatrix.NumMyNonzeros();
416 int GatheredNumMyNonzeros = GatheredMatrix.NumMyNonzeros();
417 assert(StandardNumMyNonzeros==GatheredNumMyNonzeros);
419 int StandardNumMyRows = StandardMatrix.NumMyRows();
420 int GatheredNumMyRows = GatheredMatrix.NumMyRows();
421 assert(StandardNumMyRows==GatheredNumMyRows);
423 for (i=0; i< StandardNumMyRows; i++)
425 assert(StandardMatrix.ExtractMyRowView(i, StandardNumEntries, StandardValues, StandardIndices)==0);
426 assert(GatheredMatrix.ExtractMyRowView(i, GatheredNumEntries, GatheredValues, GatheredIndices)==0);
427 assert(StandardNumEntries==GatheredNumEntries);
428 for (j=0; j < StandardNumEntries; j++) {
435 assert(StandardIndices[j]==GatheredIndices[j]);
436 assert(StandardValues[j]==GatheredValues[j]);
440 if (verbose) cout <<
"Matrix Export Check OK" << endl;
443 delete &SourceVector;
444 delete &TargetVector;
445 delete &ExpectedTarget;
452 delete [] SourceMyGlobalElements;
453 delete [] TargetMyGlobalElements;
455 delete &SourceMultiVector;
456 delete &TargetMultiVector;
460 delete &GatheredMatrix;
461 delete &OverlapMatrix;
463 delete [] OverlapMyGlobalElements;
465 delete &StandardMatrix;
466 delete &StandardGraph;
468 delete [] StandardMyGlobalElements;
int main(int argc, char *argv[])