Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Map/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"
44 int checkmap(Epetra_Map & Map, int NumGlobalElements, int NumMyElements,
45  int *MyGlobalElements, int IndexBase, Epetra_Comm& Comm,
46  bool DistributedGlobal)
47 {
48  int i, ierr=0, forierr = 0;
49 
51 
52  EPETRA_TEST_ERR(DistributedGlobal!=Map.DistributedGlobal(),ierr);
53 
54 
55  EPETRA_TEST_ERR(Map.ElementSize()!=1,ierr);
56  int *MyElementSizeList = new int[NumMyElements];
57 
58  EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
59 
60  forierr = 0;
61  for (i=0; i<NumMyElements; i++) forierr += MyElementSizeList[i]!=1;
62  EPETRA_TEST_ERR(forierr,ierr);
63 
64  delete [] MyElementSizeList;
65 
66  const Epetra_Comm & Comm1 = Map.Comm();
67 
68  EPETRA_TEST_ERR(Comm1.NumProc()!=Comm.NumProc(),ierr);
69 
70  EPETRA_TEST_ERR(Comm1.MyPID()!=Comm.MyPID(),ierr);
71 
72  EPETRA_TEST_ERR(Map.IndexBase()!=IndexBase,ierr);
73 
74  EPETRA_TEST_ERR(!Map.LinearMap() && MyGlobalElements==0,ierr);
75 
76  EPETRA_TEST_ERR(Map.LinearMap() && MyGlobalElements!=0,ierr);
77 
78  EPETRA_TEST_ERR(Map.MaxAllGID()!=NumGlobalElements-1+IndexBase,ierr);
79 
80  EPETRA_TEST_ERR(Map.MaxElementSize()!=1,ierr);
81 
82  int MaxLID = Map.MaxLID();
83  EPETRA_TEST_ERR(MaxLID!=NumMyElements-1,ierr);
84 
85  int MaxMyGID = (Comm.MyPID()+1)*NumMyElements-1+IndexBase;
86  if (Comm.MyPID()>2) MaxMyGID+=3;
87  if (!DistributedGlobal) MaxMyGID = NumMyElements-1+IndexBase;
88  EPETRA_TEST_ERR(Map.MaxMyGID()!=MaxMyGID,ierr);
89 
90  EPETRA_TEST_ERR(Map.MinAllGID()!=IndexBase,ierr);
91 
92  EPETRA_TEST_ERR(Map.MinElementSize()!=1,ierr);
93 
94  EPETRA_TEST_ERR(Map.MinLID()!=0,ierr);
95 
96  int MinMyGID = Comm.MyPID()*NumMyElements+IndexBase;
97  if (Comm.MyPID()>2) MinMyGID+=3;
98  if (!DistributedGlobal) MinMyGID = 0;
99  EPETRA_TEST_ERR(Map.MinMyGID()!=MinMyGID,ierr);
100 
101  int * MyGlobalElements1 = new int[NumMyElements];
102  EPETRA_TEST_ERR(Map.MyGlobalElements(MyGlobalElements1)!=0,ierr);
103 
104  forierr = 0;
105  if (MyGlobalElements==0)
106  {
107  for (i=0; i<NumMyElements; i++)
108  forierr += MyGlobalElements1[i]!=MinMyGID+i;
109  EPETRA_TEST_ERR(forierr,ierr);
110  }
111  else {
112  for (i=0; i<NumMyElements; i++)
113  forierr += MyGlobalElements[i]!=MyGlobalElements1[i];
114  EPETRA_TEST_ERR(forierr,ierr);
115  }
116  EPETRA_TEST_ERR(Map.NumGlobalElements()!=NumGlobalElements,ierr);
117 
118  EPETRA_TEST_ERR(Map.NumGlobalPoints()!=NumGlobalElements,ierr);
119 
120  EPETRA_TEST_ERR(Map.NumMyElements()!=NumMyElements,ierr);
121 
122  EPETRA_TEST_ERR(Map.NumMyPoints()!=NumMyElements,ierr);
123 
124  int MaxMyGID2 = Map.GID(Map.LID(MaxMyGID));
125  EPETRA_TEST_ERR(MaxMyGID2 != MaxMyGID,ierr);
126  int MaxLID2 = Map.LID(Map.GID(MaxLID));
127  EPETRA_TEST_ERR(MaxLID2 != MaxLID,ierr);
128 
129  EPETRA_TEST_ERR(Map.GID(MaxLID+1) != IndexBase-1,ierr);// MaxLID+1 doesn't exist
130  EPETRA_TEST_ERR(Map.LID(MaxMyGID+1) != -1,ierr);// MaxMyGID+1 doesn't exist or is on a different processor
131 
132  EPETRA_TEST_ERR(!Map.MyGID(MaxMyGID),ierr);
133  EPETRA_TEST_ERR(Map.MyGID(MaxMyGID+1),ierr);
134 
135  EPETRA_TEST_ERR(!Map.MyLID(MaxLID),ierr);
136  EPETRA_TEST_ERR(Map.MyLID(MaxLID+1),ierr);
137 
138  EPETRA_TEST_ERR(!Map.MyGID(Map.GID(MaxLID)),ierr);
139  EPETRA_TEST_ERR(Map.MyGID(Map.GID(MaxLID+1)),ierr);
140 
141  EPETRA_TEST_ERR(!Map.MyLID(Map.LID(MaxMyGID)),ierr);
142  EPETRA_TEST_ERR(Map.MyLID(Map.LID(MaxMyGID+1)),ierr);
143 
144  // Check RemoteIDList function
145  // Get some GIDs off of each processor to test
146  int TotalNumEle, NumElePerProc, NumProc = Comm.NumProc();
147  int MinNumEleOnProc;
148  int NumMyEle=Map.NumMyElements();
149  Comm.MinAll(&NumMyEle,&MinNumEleOnProc,1);
150  if (MinNumEleOnProc > 5) NumElePerProc = 6;
151  else NumElePerProc = MinNumEleOnProc;
152  if (NumElePerProc > 0) {
153  TotalNumEle = NumElePerProc*NumProc;
154  int * MyGIDlist = new int[NumElePerProc];
155  int * GIDlist = new int[TotalNumEle];
156  int * PIDlist = new int[TotalNumEle];
157  int * LIDlist = new int[TotalNumEle];
158  for (i=0; i<NumElePerProc; i++)
159  MyGIDlist[i] = MyGlobalElements1[i];
160  Comm.GatherAll(MyGIDlist,GIDlist,NumElePerProc);// Get a few values from each proc
161  Map.RemoteIDList(TotalNumEle, GIDlist, PIDlist, LIDlist);
162  int MyPID= Comm.MyPID();
163 
164  forierr = 0;
165  for (i=0; i<TotalNumEle; i++) {
166  if (Map.MyGID(GIDlist[i])) {
167  forierr += PIDlist[i] != MyPID;
168  forierr += !Map.MyLID(Map.LID(GIDlist[i])) || Map.LID(GIDlist[i]) != LIDlist[i] || Map.GID(LIDlist[i]) != GIDlist[i];
169  }
170  else {
171  forierr += PIDlist[i] == MyPID; // If MyGID comes back false, the PID listed should be that of another proc
172  }
173  }
174  EPETRA_TEST_ERR(forierr,ierr);
175 
176  delete [] MyGIDlist;
177  delete [] GIDlist;
178  delete [] PIDlist;
179  delete [] LIDlist;
180  }
181 
182  delete [] MyGlobalElements1;
183 
184  // Check RemoteIDList function (assumes all maps are linear, even if not stored that way)
185 
186  if (Map.LinearMap()) {
187 
188  int * GIDList = new int[3];
189  int * PIDList = new int[3];
190  int * LIDList = new int[3];
191  int MyPID = Map.Comm().MyPID();
192 
193  int NumIDs = 0;
194  //GIDList[NumIDs++] = Map.MaxAllGID()+1; // Should return -1 for both PID and LID
195  if (Map.MinMyGID()-1>=Map.MinAllGID()) GIDList[NumIDs++] = Map.MinMyGID()-1;
196  if (Map.MaxMyGID()+1<=Map.MaxAllGID()) GIDList[NumIDs++] = Map.MaxMyGID()+1;
197 
198  Map.RemoteIDList(NumIDs, GIDList, PIDList, LIDList);
199 
200  NumIDs = 0;
201 
202  //EPETRA_TEST_ERR(!(PIDList[NumIDs]==-1),ierr);
203  //EPETRA_TEST_ERR(!(LIDList[NumIDs++]==-1),ierr);
204 
205  if (Map.MinMyGID()-1>=Map.MinAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs++]==MyPID-1),ierr);
206  if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs]==MyPID+1),ierr);
207  if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(LIDList[NumIDs++]==0),ierr);
208 
209  delete [] GIDList;
210  delete [] PIDList;
211  delete [] LIDList;
212 
213  }
214 
215  return (ierr);
216 }
217 
218 
int NumGlobalElements() const
Number of elements across all processors.
Epetra_Map: A class for partitioning vectors and matrices.
Definition: Epetra_Map.h:127
bool DistributedGlobal() const
Returns true if map is defined across more than one processor.
int ElementSize() const
Returns the size of elements in the map; only valid if map has constant element size.
int MaxLID() const
The maximum local index value on the calling processor.
virtual int GatherAll(double *MyVals, double *AllVals, int Count) const =0
Epetra_Comm All Gather function.
#define EPETRA_TEST_ERR(a, b)
int MyGlobalElements(int *MyGlobalElementList) const
Puts list of global elements on this processor into the user-provided array.
bool ConstantElementSize() const
Returns true if map has constant element size.
int * ElementSizeList() const
List of the element sizes corresponding to the array MyGlobalElements().
virtual int MinAll(double *PartialMins, double *GlobalMins, int Count) const =0
Epetra_Comm Global Min function.
int MinLID() const
The minimum local index value on the calling processor.
virtual int MyPID() const =0
Return my process ID.
int IndexBase() const
Index base for this map.
int NumMyElements() const
Number of elements on the calling processor.
Epetra_Comm: The Epetra Communication Abstract Base Class.
Definition: Epetra_Comm.h:81
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)
int GID(int LID) const
Returns global ID of local ID, return IndexBase-1 if not found on this processor. ...
int MinAllGID() const
Returns the minimum global ID across the entire map.
int LID(int GID) const
Returns local ID of global ID, return -1 if not found on this processor.
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.
int MinMyGID() const
Returns the minimum global ID owned by this processor.
const Epetra_Comm & Comm() const
Access function for Epetra_Comm communicator.
bool LinearMap() const
Returns true if the global ID space is contiguously divided (but not necessarily uniformly) across al...
virtual int NumProc() const =0
Returns total number of processes.
int MaxElementSize() const
Maximum element size across all processors.
int NumGlobalPoints() const
Number of global points for this map; equals the sum of all element sizes across all processors...
bool MyLID(int lid) const
Returns true if the LID passed in belongs to the calling processor in this map, otherwise returns fal...
int NumMyPoints() const
Number of local points for this map; equals the sum of all element sizes on the calling processor...
int MinElementSize() const
Minimum element size across all processors.
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 MaxAllGID() const
Returns the maximum global ID across the entire map.