53#include "../epetra_test_err.h"
56int main(
int argc,
char *argv[]) {
60 if ((argv[1][0] ==
'-') && (argv[1][1] ==
'v'))
70 MPI_Init(&argc,&argv);
79 int MyPID = Comm.
MyPID();
82 int verbose_int = verbose ? 1 : 0;
84 verbose = verbose_int==1 ? true :
false;
86 if (verbose && MyPID==0)
89 if (verbose) cout << Comm << endl << flush;
91 bool verbose1 = verbose;
92 if (verbose) verbose = (MyPID==0);
94 int NumMyElements = 10000;
95 int NumGlobalElements = NumMyElements*NumProc+
EPETRA_MIN(NumProc,3);
96 if (MyPID < 3) NumMyElements++;
99 bool DistributedGlobal = (NumGlobalElements>NumMyElements);
100 bool IsOneToOne =
true;
106 cout <<
"*******************************************************************************************" << endl
107 <<
" Testing Exceptions (Expect error messages if EPETRA_NO_ERROR_REPORTS is not defined" << endl
108 <<
"*******************************************************************************************" << endl
112 if (verbose) cout <<
"Checking Epetra_BlockMap(-2, ElementSize, IndexBase, Comm)" << endl;
119 if (verbose) cout <<
"Error code should be -1" << endl;
122 cout <<
"Error code = " << Error <<
"Should be -1" << endl;
126 else if (verbose) cout <<
"Checked OK\n\n" << endl;
130 if (verbose) cout <<
"Checking Epetra_BlockMap(2, 3, ElementSize, IndexBase, Comm)" << endl;
137 if (verbose) cout <<
"Error code should be -4" << endl;
140 cout <<
"Error code = " << Error <<
"Should be -4" << endl;
144 else if (verbose) cout <<
"Checked OK\n\n" << endl;
147 if (verbose) cerr << flush;
148 if (verbose) cout << flush;
152 <<
"*******************************************************************************************" << endl
153 <<
" Testing valid constructor now......................................................" << endl
154 <<
"*******************************************************************************************" << endl
157 Map =
new Epetra_BlockMap(NumGlobalElements, ElementSize, IndexBase, Comm);
158 if (verbose) cout <<
"Checking Epetra_BlockMap(NumGlobalElements, ElementSize, IndexBase, Comm)" << endl;
159 ierr =
checkmap(*Map, NumGlobalElements, NumMyElements, 0, ElementSize, 0,
160 NumGlobalElements*ElementSize, NumMyElements*ElementSize,
161 IndexBase, Comm, DistributedGlobal,IsOneToOne);
164 if (verbose && ierr==0) cout <<
"Checked OK\n\n" <<endl;
169 Map =
new Epetra_BlockMap(NumGlobalElements, NumMyElements, ElementSize, IndexBase, Comm);
171 if (verbose) cout <<
"Checking Epetra_BlockMap(NumGlobalElements, NumMyElements, ElementSize, IndexBase, Comm)" << endl;
172 ierr =
checkmap(*Map, NumGlobalElements, NumMyElements, 0, ElementSize, 0,
173 NumGlobalElements*ElementSize, NumMyElements*ElementSize,
174 IndexBase, Comm, DistributedGlobal,IsOneToOne);
177 if (verbose && ierr==0) cout <<
"Checked OK\n\n" <<endl;
184 int NumGlobalElems = (Comm.
NumProc()+1)*NumMyElems;
185 int myFirstElem = Comm.
MyPID()*NumMyElems;
186 if (Comm.
MyPID() == 0) NumMyElems *= 2;
188 int* myElems =
new int[NumMyElems];
189 for(
int ii=0; ii<NumMyElems; ++ii) {
190 myElems[ii] = myFirstElem + ii;
193 Map =
new Epetra_BlockMap(NumGlobalElems, NumMyElems, myElems, 1, 0, Comm);
195 if (verbose) cout <<
"Checking non-oneToOne Epetra_BlockMap(...)"<<endl;
203 if (verbose && ierr==0) cout <<
"Checked OK\n\n" <<endl;
211 int * MyGlobalElements =
new int[NumMyElements];
212 int MaxMyGID = (Comm.
MyPID()+1)*NumMyElements-1+IndexBase;
215 for (i = 0; i<NumMyElements; i++)
216 MyGlobalElements[i] = MaxMyGID-i;
218 Map =
new Epetra_BlockMap(NumGlobalElements, NumMyElements, MyGlobalElements, ElementSize,
221 if (verbose) cout <<
"Checking Epetra_BlockMap(NumGlobalElements, NumMyElements, MyGlobalElements, ElementSize, IndexBase, Comm)" << endl;
222 ierr =
checkmap(*Map, NumGlobalElements, NumMyElements, MyGlobalElements, ElementSize, 0,
223 NumGlobalElements*ElementSize, NumMyElements*ElementSize,
224 IndexBase, Comm, DistributedGlobal,IsOneToOne);
227 if (verbose && ierr==0) cout <<
"Checked OK\n\n" <<endl;
233 int * ElementSizeList =
new int[NumMyElements];
234 int NumMyEquations = 0;
235 int NumGlobalEquations = 0;
236 for (i = 0; i<NumMyElements; i++) {
237 ElementSizeList[i] = i%6 + 2;
238 NumMyEquations += ElementSizeList[i];
241 NumGlobalEquations = Comm.
NumProc()*NumMyEquations;
246 NumGlobalEquations += 3*((NumMyElements)%6+2);
248 NumGlobalEquations -= (Comm.
NumProc()-3)*((NumMyElements-1)%6+2);
250 Map =
new Epetra_BlockMap(NumGlobalElements, NumMyElements, MyGlobalElements, ElementSizeList,
252 if (verbose) cout <<
"Checking Epetra_BlockMap(NumGlobalElements, NumMyElements, MyGlobalElements, ElementSizeList, IndexBase, Comm)" << endl;
253 ierr =
checkmap(*Map, NumGlobalElements, NumMyElements, MyGlobalElements, ElementSize, ElementSizeList,
254 NumGlobalEquations, NumMyEquations,
255 IndexBase, Comm, DistributedGlobal,IsOneToOne);
258 if (verbose && ierr==0) cout <<
"Checked OK\n\n" <<endl;
264 bool same = Map1->
SameAs(*Map);
268 same = Map2->
SameAs(*Map);
274 Map2 =
new Epetra_BlockMap(NumGlobalElements,NumMyElements,MyGlobalElements,ElementSizeList,IndexBase-1,Comm);
275 same = Map2->
SameAs(*Map);
279 int *ElementSizeList1 =
new int[NumMyElements];
280 for (i=0; i<NumMyElements; i++)
281 ElementSizeList1[i] = i%5 + 2;
282 Map2 =
new Epetra_BlockMap(NumGlobalElements,NumMyElements,MyGlobalElements,ElementSizeList1,IndexBase,Comm);
283 same = Map2->
SameAs(*Map);
285 delete [] ElementSizeList1;
288 same = Map3->
SameAs(*Map);
293 if (verbose) cout <<
"Checking Epetra_BlockMap(*Map)" << endl;
294 ierr =
checkmap(*Map1, NumGlobalElements, NumMyElements, MyGlobalElements, ElementSize, ElementSizeList,
295 NumGlobalEquations, NumMyEquations,
296 IndexBase, Comm, DistributedGlobal,IsOneToOne);
299 if (verbose && ierr==0) cout <<
"Checked OK\n\n" <<endl;
302 if (verbose) cout <<
"Test ostream << operator" << endl << flush;
326 Map1 =
new Epetra_BlockMap(-1, NumMyElements, MyGlobalElements, ElementSizeList, IndexBase, Comm);
337 delete[] ElementSizeList;
338 delete[] MyGlobalElements;
346 <<
"*******************************************************************************************" << endl
347 <<
" Testing reference counting now....................................................." << endl
348 <<
"*******************************************************************************************" << endl << endl;
350 Epetra_BlockMap b1(NumGlobalElements, NumMyElements, ElementSize, IndexBase, Comm);
354 if(verbose) cout <<
"Default constructor. \nb1= " << b1count <<
" " << b1addr << endl;
359 int b1countold = b1count;
363 if(verbose) cout <<
"Copy constructor. \nb1= " << b1count <<
" " << b1addr <<
"\nb2= " << b2count <<
" " << b2addr << endl;
366 b1countold = b1count;
370 if(verbose) cout <<
"b2 destroyed. \nb1= " << b1count <<
" " << b1addr << endl;
373 if(verbose) cout <<
"Assignment operator, post construction" << endl;
374 Epetra_BlockMap b3(NumGlobalElements, NumMyElements, ElementSize, IndexBase-1, Comm);
379 if(verbose) cout <<
"Prior to assignment: \nb1= " << b1count <<
" " << b1addr <<
"\nb3= " << b3count <<
" " << b3addr << endl;
383 b1countold = b1count;
387 if(verbose) cout <<
"After assignment: \nb1= " << b1count <<
" " << b1addr <<
"\nb3= " << b3count <<
" " << b3addr << endl;
389 b1countold = b1count;
393 if (verbose) cout <<
"b3 destroyed. \nb1= " << b1count <<
" " << b1addr << endl;
396 if (verbose && (ierr == 0)) cout <<
"Checked OK\n\n" <<endl;
403 <<
"*******************************************************************************************" << endl
404 <<
" Testing subcommunicators now......................................................." << endl
405 <<
"*******************************************************************************************" << endl << endl;
426 delete Map1;
delete Map2;
delete Map3;
429 if (verbose && (ierr == 0)) cout <<
"Checked OK\n\n" <<endl;
int checkmap(Epetra_BlockMap &Map, int NumGlobalElements, int NumMyElements, int *MyGlobalElements, int ElementSize, int *ElementSizeList, int NumGlobalPoints, int NumMyPoints, int IndexBase, Epetra_Comm &Comm, bool DistributedGlobal, bool IsOneToOne)
std::string Epetra_Version()
Epetra_BlockMapData: The Epetra BlockMap Data Class.
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
int MinMyGID() const
Returns the minimum global ID owned by this processor.
int * ElementSizeList() const
List of the element sizes corresponding to the array MyGlobalElements().
int ReferenceCount() const
Returns the reference count of BlockMapData.
int IndexBase() const
Index base for this map.
bool SameAs(const Epetra_BlockMap &Map) const
Returns true if this and Map are identical maps.
Epetra_BlockMap * ReplaceCommWithSubset(const Epetra_Comm *Comm) const
Replace this BlockMap's communicator with a subset communicator.
const Epetra_Comm & Comm() const
Access function for Epetra_Comm communicator.
const Epetra_BlockMapData * DataPtr() const
Returns a pointer to the BlockMapData instance this BlockMap uses.
int NumMyElements() const
Number of elements on the calling processor.
int MaxMyGID() const
Returns the maximum global ID owned by this processor.
Epetra_BlockMap * RemoveEmptyProcesses() const
Return a new BlockMap with processes with zero elements removed.
Epetra_Comm: The Epetra Communication Abstract Base Class.
Epetra_MpiComm: The Epetra MPI Communication Class.
void Barrier() const
Epetra_MpiComm Barrier function.
int Broadcast(double *MyVals, int Count, int Root) const
Epetra_MpiComm Broadcast function.
int NumProc() const
Returns total number of processes.
int MyPID() const
Return my process ID.
static void SetTracebackMode(int TracebackModeValue)
Set the value of the Epetra_Object error traceback report mode.
Epetra_SerialComm: The Epetra Serial Communication Class.
#define EPETRA_TEST_ERR(a, b)
int main(int argc, char *argv[])