Epetra Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
BlockMap/checkmap.cpp
Go to the documentation of this file.
1//@HEADER
2// ************************************************************************
3//
4// Epetra: Linear Algebra Services Package
5// Copyright 2011 Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ************************************************************************
40//@HEADER
41
42
43#include "checkmap.h"
44int checkmap(Epetra_BlockMap & Map, int NumGlobalElements, int NumMyElements,
45 int *MyGlobalElements, int ElementSize, int * ElementSizeList,
46 int NumGlobalPoints, int NumMyPoints,
47 int IndexBase, Epetra_Comm& Comm,
48 bool DistributedGlobal,
49 bool IsOneToOne)
50{
51
52 int i, ierr=0, forierr=0;// forierr is used in for loops, then is tested
53 // after for loop completes to see if it is non zero - potentially prevents
54 // thousands of error messages
55
56 if (ElementSizeList==0)
57 {
59 }
60 else
62
63 EPETRA_TEST_ERR(DistributedGlobal!=Map.DistributedGlobal(),ierr);
64
65 EPETRA_TEST_ERR(IsOneToOne!=Map.IsOneToOne(),ierr);
66
67 int *MyElementSizeList;
68
69 if (ElementSizeList==0)
70 {
71 EPETRA_TEST_ERR(Map.ElementSize()!=ElementSize,ierr);
72
73 MyElementSizeList = new int[NumMyElements];
74
75 EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
76 forierr = 0;
77 for (i=0; i<NumMyElements; i++)
78 forierr += MyElementSizeList[i]!=ElementSize;
79 EPETRA_TEST_ERR(forierr,ierr);
80
81 EPETRA_TEST_ERR(Map.MaxMyElementSize() != ElementSize,ierr);
82 EPETRA_TEST_ERR(Map.MinMyElementSize() != ElementSize,ierr);
83 }
84 else
85 {
86 MyElementSizeList = new int[NumMyElements];
87 EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
88 int MaxSize = MyElementSizeList[0];
89 int MinSize = MyElementSizeList[0];
90 forierr=0;
91 for (i=0; i<NumMyElements; i++) {
92 forierr += MyElementSizeList[i]!=ElementSizeList[i];
93 if (MyElementSizeList[i] > MaxSize)
94 MaxSize = MyElementSizeList[i];
95 if (MyElementSizeList[i] < MinSize)
96 MinSize = MyElementSizeList[i];
97
98 // Test ElementSize(int LID) method
99
100 forierr += Map.ElementSize(Map.LID(MyGlobalElements[i])) != ElementSizeList[i];
101 }
102 EPETRA_TEST_ERR(forierr,ierr);
103
104 EPETRA_TEST_ERR(MaxSize !=Map.MaxMyElementSize(),ierr);
105 EPETRA_TEST_ERR(MinSize !=Map.MinMyElementSize(),ierr);
106 }
107
108 const Epetra_Comm & Comm1 = Map.Comm();
109
110 EPETRA_TEST_ERR(Comm1.NumProc()!=Comm.NumProc(),ierr);
111
112 EPETRA_TEST_ERR(Comm1.MyPID()!=Comm.MyPID(),ierr);
113
114 EPETRA_TEST_ERR(Map.IndexBase()!=IndexBase,ierr);
115
116 EPETRA_TEST_ERR(!Map.LinearMap() && MyGlobalElements==0,ierr);
117
118 EPETRA_TEST_ERR(Map.LinearMap() && MyGlobalElements!=0,ierr);
119
120 EPETRA_TEST_ERR(Map.MaxAllGID()!=NumGlobalElements-1+IndexBase,ierr);
121
122 EPETRA_TEST_ERR(Map.MaxElementSize()!=ElementSize,ierr);
123
124 int MaxLID = Map.MaxLID();
125 EPETRA_TEST_ERR(MaxLID!=NumMyElements-1,ierr);
126
127 int MaxMyGID = (Comm.MyPID()+1)*NumMyElements-1+IndexBase;
128 if (Comm.MyPID()>2) MaxMyGID+=3;
129 if (!DistributedGlobal) MaxMyGID = NumMyElements-1+IndexBase;
130 EPETRA_TEST_ERR(Map.MaxMyGID()!=MaxMyGID,ierr);
131
132 EPETRA_TEST_ERR(Map.MinAllGID()!=IndexBase,ierr);
133
134 if (ElementSizeList==0)
135 {
136 EPETRA_TEST_ERR(Map.MinElementSize()!=ElementSize,ierr);
137 }
138 else EPETRA_TEST_ERR(Map.MinElementSize()!=2,ierr);
139
140 int MinLID = Map.MinLID();
141 EPETRA_TEST_ERR(MinLID!=0,ierr);
142
143 int MinMyGID = Comm.MyPID()*NumMyElements+IndexBase;
144 if (Comm.MyPID()>2) MinMyGID+=3;
145 if (!DistributedGlobal) MinMyGID = IndexBase; // Not really needed
146 EPETRA_TEST_ERR(Map.MinMyGID()!=MinMyGID,ierr);
147
148 int * MyGlobalElements1 = new int[NumMyElements];
149 EPETRA_TEST_ERR(Map.MyGlobalElements(MyGlobalElements1)!=0,ierr);
150
151 forierr = 0;
152 if (MyGlobalElements==0) {
153 for (i=0; i<NumMyElements; i++)
154 forierr += MyGlobalElements1[i]!=MinMyGID+i;
155 EPETRA_TEST_ERR(forierr,ierr);
156 }
157 else {
158 for (i=0; i<NumMyElements; i++)
159 forierr += MyGlobalElements[i]!=MyGlobalElements1[i];
160 EPETRA_TEST_ERR(forierr,ierr);
161 }
162 EPETRA_TEST_ERR(Map.NumGlobalElements()!=NumGlobalElements,ierr);
163
164 EPETRA_TEST_ERR(Map.NumGlobalPoints()!=NumGlobalPoints,ierr);
165
166 EPETRA_TEST_ERR(Map.NumMyElements()!=NumMyElements,ierr);
167
168 EPETRA_TEST_ERR(Map.NumMyPoints()!=NumMyPoints,ierr);
169
170 int MaxMyGID2 = Map.GID(Map.LID(MaxMyGID));
171 EPETRA_TEST_ERR(MaxMyGID2 != MaxMyGID,ierr);
172 int MaxLID2 = Map.LID(Map.GID(MaxLID));
173 EPETRA_TEST_ERR(MaxLID2 != MaxLID,ierr);
174
175 EPETRA_TEST_ERR(Map.GID(MaxLID+1) != IndexBase-1,ierr);// MaxLID+1 doesn't exist
176 EPETRA_TEST_ERR(Map.LID(MaxMyGID+1) != -1,ierr);// MaxMyGID+1 doesn't exist or is on a different processor
177
178 EPETRA_TEST_ERR(!Map.MyGID(MaxMyGID),ierr);
179 EPETRA_TEST_ERR(Map.MyGID(MaxMyGID+1),ierr);
180
181 EPETRA_TEST_ERR(!Map.MyLID(MaxLID),ierr);
182 EPETRA_TEST_ERR(Map.MyLID(MaxLID+1),ierr);
183
184 EPETRA_TEST_ERR(!Map.MyGID(Map.GID(MaxLID)),ierr);
185 EPETRA_TEST_ERR(Map.MyGID(Map.GID(MaxLID+1)),ierr);
186
187 EPETRA_TEST_ERR(!Map.MyLID(Map.LID(MaxMyGID)),ierr);
188 EPETRA_TEST_ERR(Map.MyLID(Map.LID(MaxMyGID+1)),ierr);
189
190 // Test the FirstPointInElementList methods, begin by testing that they produce identical results
191 int * FirstPointInElementList = new int[NumMyElements+1];
192 Map.FirstPointInElementList(FirstPointInElementList);
193 int * FirstPointInElementList1 = Map.FirstPointInElementList();
194 forierr = 0;
195 for (i=0; i<=NumMyElements; i++)
196 forierr += FirstPointInElementList[i]!=FirstPointInElementList1[i];
197 EPETRA_TEST_ERR(forierr,ierr);
198 // Now make sure values are correct
199 forierr = 0;
200 if (Map.ConstantElementSize()) {
201 for (i=0; i<=NumMyElements; i++)
202 forierr += FirstPointInElementList1[i]!=(i*ElementSize);// NOTE:FirstPointInElement[NumMyElements] is not the first point of an element
203 EPETRA_TEST_ERR(forierr,ierr);
204 }
205 else {
206 int FirstPoint = 0;
207 for (i=0; i<NumMyElements; i++) {
208 forierr += FirstPointInElementList1[i]!=FirstPoint;
209 FirstPoint += ElementSizeList[i];
210 }
211 EPETRA_TEST_ERR(forierr,ierr);
212 EPETRA_TEST_ERR(FirstPointInElementList[NumMyElements] != NumMyPoints,ierr);// The last entry in the array = the total number of Points on the proc
213 }
214 delete [] FirstPointInElementList;
215
216 // Declare some variables for the FindLocalElementID test
217 int ElementID, Offset;
218 // Test the PointToElementList methods, begin by testing that they produce identical results
219 int * PointToElementList = new int[NumMyPoints];
220 Map.PointToElementList(PointToElementList);
221 int * PointToElementList1 = Map.PointToElementList();
222 forierr = 0;
223 for (i=0; i<NumMyPoints; i++)
224 forierr += PointToElementList1[i] != PointToElementList[i];
225 EPETRA_TEST_ERR(forierr,ierr);
226 //Now make sure values are correct
227 forierr=0;
228 if (Map.ConstantElementSize()) {
229 for (i=0; i<NumMyElements; i++)
230 for (int j=0; j<ElementSize; j++) {
231 forierr += PointToElementList[i*ElementSize+j] != i;
232 // Test FindLocalElementID method
233 Map.FindLocalElementID(i*ElementSize+j,ElementID,Offset);
234 forierr += ElementID != i || Offset != j;
235 }
236 EPETRA_TEST_ERR(forierr,ierr);
237 }
238 else {
239 int MyPointTot = 0; // Keep track of total number of points in all previously completely checked elements
240 for (i=0; i<NumMyElements; i++) {
241 for (int j=0; j<ElementSizeList[i]; j++) {
242 forierr += PointToElementList[MyPointTot+j] != i;
243 // Test FindLocalElementID method
244 Map.FindLocalElementID(MyPointTot+j,ElementID,Offset);
245 forierr += ElementID != i || Offset != j;
246 }
247 MyPointTot += ElementSizeList[i];
248 }
249 EPETRA_TEST_ERR(forierr,ierr);
250 }
251 delete [] PointToElementList;
252
253 // Check RemoteIDList function that includes a parameter for size
254 // Get some GIDs off of each processor to test
255 int TotalNumEle, NumElePerProc, NumProc = Comm.NumProc();
256 int MinNumEleOnProc;
257 int NumMyEle = Map.NumMyElements();
258 Comm.MinAll(&NumMyEle,&MinNumEleOnProc,1);
259 if (MinNumEleOnProc > 5) NumElePerProc = 6;
260 else NumElePerProc = MinNumEleOnProc;
261 if (NumElePerProc > 0) {
262 TotalNumEle = NumElePerProc*NumProc;
263 int * MyGIDlist = new int[NumElePerProc];
264 int * GIDlist = new int[TotalNumEle];
265 int * PIDlist = new int[TotalNumEle];
266 int * LIDlist = new int[TotalNumEle];
267 int * SizeList = new int[TotalNumEle];
268 for (i=0; i<NumElePerProc; i++)
269 MyGIDlist[i] = MyGlobalElements1[i];
270 Comm.GatherAll(MyGIDlist,GIDlist,NumElePerProc);// Get a few values from each proc
271 Map.RemoteIDList(TotalNumEle, GIDlist, PIDlist, LIDlist, SizeList);
272 int MyPID= Comm.MyPID();
273 forierr = 0;
274 for (i=0; i<TotalNumEle; i++) {
275 if (Map.MyGID(GIDlist[i])) {
276 forierr += PIDlist[i] != MyPID;
277 forierr += !Map.MyLID(Map.LID(GIDlist[i])) || Map.LID(GIDlist[i]) != LIDlist[i] || Map.GID(LIDlist[i]) != GIDlist[i];
278 forierr += SizeList[i] != Map.ElementSize(LIDlist[i]);
279 }
280 else {
281 forierr += PIDlist[i] == MyPID; // If MyGID comes back false, the PID listed should be that of another proc
282 }
283 }
284 EPETRA_TEST_ERR(forierr,ierr);
285
286 delete [] MyGIDlist;
287 delete [] GIDlist;
288 delete [] PIDlist;
289 delete [] LIDlist;
290 delete [] SizeList;
291 }
292
293 delete [] MyGlobalElements1;
294 delete [] MyElementSizeList;
295
296 // Check RemoteIDList function (assumes all maps are linear, even if not stored that way)
297
298 if (Map.LinearMap()) {
299
300 int * GIDList = new int[3];
301 int * PIDList = new int[3];
302 int * LIDList = new int[3];
303 int MyPID = Map.Comm().MyPID();
304
305 int NumIDs = 0;
306 //GIDList[NumIDs++] = Map.MaxAllGID()+1; // Should return -1 for both PID and LID
307 if (Map.MinMyGID()-1>=Map.MinAllGID()) GIDList[NumIDs++] = Map.MinMyGID()-1;
308 if (Map.MaxMyGID()+1<=Map.MaxAllGID()) GIDList[NumIDs++] = Map.MaxMyGID()+1;
309
310 Map.RemoteIDList(NumIDs, GIDList, PIDList, LIDList);
311
312 NumIDs = 0;
313
314 //EPETRA_TEST_ERR(!(PIDList[NumIDs]==-1),ierr);
315 //EPETRA_TEST_ERR(!(LIDList[NumIDs++]==-1),ierr);
316
317 if (Map.MinMyGID()-1>=Map.MinAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs++]==MyPID-1),ierr);
318 if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs]==MyPID+1),ierr);
319 if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(LIDList[NumIDs++]==0),ierr);
320
321 delete [] GIDList;
322 delete [] PIDList;
323 delete [] LIDList;
324
325
326 }
327 return (ierr);
328}
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)
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
int MinAllGID() const
Returns the minimum global ID across the entire map.
int RemoteIDList(int NumIDs, const int *GIDList, int *PIDList, int *LIDList) const
Returns the processor IDs and corresponding local index value for a given list of global indices.
int MaxElementSize() const
Maximum element size across all processors.
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
int MinMyElementSize() const
Minimum element size on the calling processor.
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 * PointToElementList() const
For each local point, indicates the local element ID that the point belongs to.
bool DistributedGlobal() const
Returns true if map is defined across more than one processor.
int NumMyPoints() const
Number of local points for this map; equals the sum of all element sizes on the calling processor.
int LID(int GID) const
Returns local ID of global ID, return -1 if not found on this processor.
int GID(int LID) const
Returns global ID of local ID, return IndexBase-1 if not found on this processor.
bool LinearMap() const
Returns true if the global ID space is contiguously divided (but not necessarily uniformly) across al...
int IndexBase() const
Index base for this map.
int MaxAllGID() const
Returns the maximum global ID across the entire map.
int ElementSize() const
Returns the size of elements in the map; only valid if map has constant element size.
int * FirstPointInElementList() const
Pointer to internal array containing a mapping between the local elements and the first local point n...
int MaxMyElementSize() const
Maximum element size on the calling processor.
int MinLID() const
The minimum local index value on the calling processor.
int MinElementSize() const
Minimum element size across all processors.
int FindLocalElementID(int PointID, int &ElementID, int &ElementOffset) const
Returns the LID of the element that contains the given local PointID, and the Offset of the point in ...
int NumGlobalElements() const
Number of elements across all processors.
const Epetra_Comm & Comm() const
Access function for Epetra_Comm communicator.
bool ConstantElementSize() const
Returns true if map has constant element size.
int NumMyElements() const
Number of elements on the calling processor.
bool IsOneToOne() const
bool MyLID(int lid) const
Returns true if the LID passed in belongs to the calling processor in this map, otherwise returns fal...
int MaxLID() const
The maximum local index value on the calling processor.
int NumGlobalPoints() const
Number of global points for this map; equals the sum of all element sizes across all processors.
bool MyGID(int GID_in) const
Returns true if the GID passed in belongs to the calling processor in this map, otherwise returns fal...
int MaxMyGID() const
Returns the maximum global ID owned by this processor.
Epetra_Comm: The Epetra Communication Abstract Base Class.
Definition: Epetra_Comm.h:73
virtual int NumProc() const =0
Returns total number of processes.
virtual int GatherAll(double *MyVals, double *AllVals, int Count) const =0
Epetra_Comm All Gather function.
virtual int MinAll(double *PartialMins, double *GlobalMins, int Count) const =0
Epetra_Comm Global Min function.
virtual int MyPID() const =0
Return my process ID.
#define EPETRA_TEST_ERR(a, b)