Epetra Package Browser (Single Doxygen Collection) Development
BlockMap_LL/checkmap.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 //
00004 //               Epetra: Linear Algebra Services Package
00005 //                 Copyright 2011 Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 
00043 #include "checkmap.h"
00044 int checkmap(Epetra_BlockMap & Map, long long NumGlobalElements, int NumMyElements,
00045        long long *MyGlobalElements, int ElementSize, int * ElementSizeList,
00046        long long NumGlobalPoints, int NumMyPoints,
00047        long long IndexBase, Epetra_Comm& Comm,
00048        bool DistributedGlobal,
00049        bool IsOneToOne)
00050 {
00051 
00052   int i, ierr=0, forierr=0;// forierr is used in for loops, then is tested
00053   // after for loop completes to see if it is non zero - potentially prevents
00054   // thousands of error messages
00055 
00056   if (ElementSizeList==0)
00057     {
00058       EPETRA_TEST_ERR(!Map.ConstantElementSize(),ierr);
00059     }
00060   else
00061     EPETRA_TEST_ERR(Map.ConstantElementSize(),ierr);
00062 
00063   EPETRA_TEST_ERR(DistributedGlobal!=Map.DistributedGlobal(),ierr);
00064 
00065   EPETRA_TEST_ERR(IsOneToOne!=Map.IsOneToOne(),ierr);
00066 
00067   int *MyElementSizeList;
00068 
00069   if (ElementSizeList==0)
00070     {
00071       EPETRA_TEST_ERR(Map.ElementSize()!=ElementSize,ierr);
00072 
00073       MyElementSizeList = new int[NumMyElements];
00074 
00075       EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
00076       forierr = 0;
00077       for (i=0; i<NumMyElements; i++)
00078         forierr += MyElementSizeList[i]!=ElementSize;
00079       EPETRA_TEST_ERR(forierr,ierr);
00080 
00081       EPETRA_TEST_ERR(Map.MaxMyElementSize() != ElementSize,ierr);
00082       EPETRA_TEST_ERR(Map.MinMyElementSize() != ElementSize,ierr);
00083     }
00084   else
00085     {
00086       MyElementSizeList = new int[NumMyElements];
00087       EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
00088       int MaxSize = MyElementSizeList[0];
00089       int MinSize = MyElementSizeList[0];
00090       forierr=0;
00091       for (i=0; i<NumMyElements; i++) {
00092         forierr += MyElementSizeList[i]!=ElementSizeList[i];
00093   if (MyElementSizeList[i] > MaxSize)
00094     MaxSize = MyElementSizeList[i];
00095   if (MyElementSizeList[i] < MinSize)
00096     MinSize = MyElementSizeList[i];
00097 
00098   // Test ElementSize(int LID) method 
00099 
00100   forierr += Map.ElementSize(Map.LID(MyGlobalElements[i])) != ElementSizeList[i];
00101       }
00102       EPETRA_TEST_ERR(forierr,ierr);
00103 
00104       EPETRA_TEST_ERR(MaxSize !=Map.MaxMyElementSize(),ierr);
00105       EPETRA_TEST_ERR(MinSize !=Map.MinMyElementSize(),ierr);
00106     }
00107 
00108   const Epetra_Comm & Comm1 = Map.Comm();
00109 
00110   EPETRA_TEST_ERR(Comm1.NumProc()!=Comm.NumProc(),ierr);
00111 
00112   EPETRA_TEST_ERR(Comm1.MyPID()!=Comm.MyPID(),ierr);
00113 
00114   EPETRA_TEST_ERR(Map.IndexBase64()!=IndexBase,ierr);
00115 
00116   EPETRA_TEST_ERR(!Map.LinearMap() && MyGlobalElements==0,ierr);
00117 
00118   EPETRA_TEST_ERR(Map.LinearMap() && MyGlobalElements!=0,ierr);
00119 
00120   EPETRA_TEST_ERR(Map.MaxAllGID64()!=NumGlobalElements-1+IndexBase,ierr);
00121 
00122   EPETRA_TEST_ERR(Map.MaxElementSize()!=ElementSize,ierr);
00123 
00124   int MaxLID = Map.MaxLID();
00125   EPETRA_TEST_ERR(MaxLID!=NumMyElements-1,ierr);
00126 
00127   long long MaxMyGID = (Comm.MyPID()+1)*NumMyElements-1+IndexBase;
00128   if (Comm.MyPID()>2) MaxMyGID+=3;
00129   if (!DistributedGlobal) MaxMyGID = NumMyElements-1+IndexBase;
00130   EPETRA_TEST_ERR(Map.MaxMyGID64()!=MaxMyGID,ierr);
00131 
00132   EPETRA_TEST_ERR(Map.MinAllGID64()!=IndexBase,ierr);
00133 
00134   if (ElementSizeList==0)
00135     {
00136       EPETRA_TEST_ERR(Map.MinElementSize()!=ElementSize,ierr);
00137     }
00138   else EPETRA_TEST_ERR(Map.MinElementSize()!=2,ierr);
00139 
00140   int MinLID = Map.MinLID();
00141   EPETRA_TEST_ERR(MinLID!=0,ierr);
00142 
00143   long long MinMyGID = Comm.MyPID()*NumMyElements+IndexBase;
00144   if (Comm.MyPID()>2) MinMyGID+=3;
00145   if (!DistributedGlobal) MinMyGID = IndexBase; // Not really needed
00146   EPETRA_TEST_ERR(Map.MinMyGID64()!=MinMyGID,ierr);
00147 
00148   long long * MyGlobalElements1 = new long long[NumMyElements];
00149   EPETRA_TEST_ERR(Map.MyGlobalElements(MyGlobalElements1)!=0,ierr);
00150 
00151   forierr = 0;
00152   if (MyGlobalElements==0) {
00153     for (i=0; i<NumMyElements; i++)
00154       forierr += MyGlobalElements1[i]!=MinMyGID+i;
00155     EPETRA_TEST_ERR(forierr,ierr);
00156   }
00157   else {
00158     for (i=0; i<NumMyElements; i++)
00159       forierr += MyGlobalElements[i]!=MyGlobalElements1[i];
00160     EPETRA_TEST_ERR(forierr,ierr);
00161   }
00162   EPETRA_TEST_ERR(Map.NumGlobalElements64()!=NumGlobalElements,ierr);
00163 
00164   EPETRA_TEST_ERR(Map.NumGlobalPoints64()!=NumGlobalPoints,ierr);
00165 
00166   EPETRA_TEST_ERR(Map.NumMyElements()!=NumMyElements,ierr);
00167 
00168   EPETRA_TEST_ERR(Map.NumMyPoints()!=NumMyPoints,ierr);
00169 
00170   long long MaxMyGID2 = Map.GID64(Map.LID(MaxMyGID));
00171   EPETRA_TEST_ERR(MaxMyGID2 != MaxMyGID,ierr);
00172   int MaxLID2 = Map.LID(Map.GID64(MaxLID));
00173   EPETRA_TEST_ERR(MaxLID2 != MaxLID,ierr);
00174 
00175   EPETRA_TEST_ERR(Map.GID64(MaxLID+1) != IndexBase-1,ierr);// MaxLID+1 doesn't exist
00176   EPETRA_TEST_ERR(Map.LID(MaxMyGID+1) != -1,ierr);// MaxMyGID+1 doesn't exist or is on a different processor
00177 
00178   EPETRA_TEST_ERR(!Map.MyGID(MaxMyGID),ierr);
00179   EPETRA_TEST_ERR(Map.MyGID(MaxMyGID+1),ierr);
00180 
00181   EPETRA_TEST_ERR(!Map.MyLID(MaxLID),ierr);
00182   EPETRA_TEST_ERR(Map.MyLID(MaxLID+1),ierr);
00183 
00184   EPETRA_TEST_ERR(!Map.MyGID(Map.GID64(MaxLID)),ierr);
00185   EPETRA_TEST_ERR(Map.MyGID(Map.GID64(MaxLID+1)),ierr);
00186 
00187   EPETRA_TEST_ERR(!Map.MyLID(Map.LID(MaxMyGID)),ierr);
00188   EPETRA_TEST_ERR(Map.MyLID(Map.LID(MaxMyGID+1)),ierr);
00189 
00190   // Test the FirstPointInElementList methods, begin by testing that they produce identical results
00191   int * FirstPointInElementList = new int[NumMyElements+1];
00192   Map.FirstPointInElementList(FirstPointInElementList);
00193   int * FirstPointInElementList1 = Map.FirstPointInElementList();
00194   forierr = 0;
00195   for (i=0; i<=NumMyElements; i++)
00196     forierr += FirstPointInElementList[i]!=FirstPointInElementList1[i];
00197   EPETRA_TEST_ERR(forierr,ierr);
00198   // Now make sure values are correct
00199   forierr = 0;
00200   if (Map.ConstantElementSize()) {
00201     for (i=0; i<=NumMyElements; i++)
00202       forierr += FirstPointInElementList1[i]!=(i*ElementSize);// NOTE:FirstPointInElement[NumMyElements] is not the first point of an element
00203     EPETRA_TEST_ERR(forierr,ierr);
00204   }
00205   else {
00206     int FirstPoint = 0;
00207     for (i=0; i<NumMyElements; i++) {
00208       forierr += FirstPointInElementList1[i]!=FirstPoint;
00209       FirstPoint += ElementSizeList[i];
00210     }
00211     EPETRA_TEST_ERR(forierr,ierr);
00212     EPETRA_TEST_ERR(FirstPointInElementList[NumMyElements] != NumMyPoints,ierr);// The last entry in the array = the total number of Points on the proc
00213   }
00214   delete [] FirstPointInElementList;
00215 
00216   // Declare some variables for the FindLocalElementID test
00217   int ElementID, Offset;
00218   // Test the PointToElementList methods, begin by testing that they produce identical results
00219   int * PointToElementList = new int[NumMyPoints];
00220   Map.PointToElementList(PointToElementList);
00221   int * PointToElementList1 = Map.PointToElementList();
00222   forierr = 0;
00223   for (i=0; i<NumMyPoints; i++)
00224     forierr += PointToElementList1[i] != PointToElementList[i];
00225   EPETRA_TEST_ERR(forierr,ierr);
00226   //Now make sure values are correct
00227   forierr=0;
00228   if (Map.ConstantElementSize()) {
00229     for (i=0; i<NumMyElements; i++)
00230       for (int j=0; j<ElementSize; j++) {
00231   forierr += PointToElementList[i*ElementSize+j] != i;
00232   // Test FindLocalElementID method
00233   Map.FindLocalElementID(i*ElementSize+j,ElementID,Offset);
00234   forierr += ElementID != i || Offset != j;
00235       }
00236     EPETRA_TEST_ERR(forierr,ierr);
00237   }
00238   else {
00239     int MyPointTot = 0; // Keep track of total number of points in all previously completely checked elements
00240     for (i=0; i<NumMyElements; i++) {
00241       for (int j=0; j<ElementSizeList[i]; j++) {
00242   forierr += PointToElementList[MyPointTot+j] != i;
00243   // Test FindLocalElementID method
00244   Map.FindLocalElementID(MyPointTot+j,ElementID,Offset);
00245   forierr += ElementID != i || Offset != j;
00246       }
00247       MyPointTot += ElementSizeList[i];
00248     }
00249     EPETRA_TEST_ERR(forierr,ierr);
00250   }
00251   delete [] PointToElementList;
00252 
00253   // Check RemoteIDList function that includes a parameter for size
00254   // Get some GIDs off of each processor to test
00255   int TotalNumEle, NumElePerProc, NumProc = Comm.NumProc();
00256   int MinNumEleOnProc;
00257   int NumMyEle = Map.NumMyElements();
00258   Comm.MinAll(&NumMyEle,&MinNumEleOnProc,1);
00259   if (MinNumEleOnProc > 5) NumElePerProc = 6;
00260   else NumElePerProc = MinNumEleOnProc;
00261   if (NumElePerProc > 0) {
00262     TotalNumEle = NumElePerProc*NumProc;
00263     long long * MyGIDlist = new long long[NumElePerProc];
00264     long long * GIDlist = new long long[TotalNumEle];
00265     int * PIDlist = new int[TotalNumEle];
00266     int * LIDlist = new int[TotalNumEle];
00267     int * SizeList = new int[TotalNumEle];
00268     for (i=0; i<NumElePerProc; i++)
00269     MyGIDlist[i] = MyGlobalElements1[i];
00270     Comm.GatherAll(MyGIDlist,GIDlist,NumElePerProc);// Get a few values from each proc
00271     Map.RemoteIDList(TotalNumEle, GIDlist, PIDlist, LIDlist, SizeList);
00272     int MyPID= Comm.MyPID();
00273     forierr = 0;
00274     for (i=0; i<TotalNumEle; i++) {
00275       if (Map.MyGID(GIDlist[i])) {
00276   forierr += PIDlist[i] != MyPID;
00277   forierr += !Map.MyLID(Map.LID(GIDlist[i])) || Map.LID(GIDlist[i]) != LIDlist[i] || Map.GID64(LIDlist[i]) != GIDlist[i];
00278   forierr += SizeList[i] != Map.ElementSize(LIDlist[i]);
00279       }
00280       else {
00281   forierr += PIDlist[i] == MyPID; // If MyGID comes back false, the PID listed should be that of another proc
00282       }
00283     }
00284     EPETRA_TEST_ERR(forierr,ierr);
00285 
00286     delete [] MyGIDlist;
00287     delete [] GIDlist;
00288     delete [] PIDlist;
00289     delete [] LIDlist;
00290     delete [] SizeList;
00291   }
00292 
00293   delete [] MyGlobalElements1;
00294   delete [] MyElementSizeList;
00295 
00296   // Check RemoteIDList function (assumes all maps are linear, even if not stored that way)
00297 
00298   if (Map.LinearMap()) {
00299 
00300     long long * GIDList = new long long[3];
00301     int * PIDList = new int[3];
00302     int * LIDList = new int[3];
00303     int MyPID = Map.Comm().MyPID();
00304 
00305     int NumIDs = 0;
00306     //GIDList[NumIDs++] = Map.MaxAllGID()+1; // Should return -1 for both PID and LID
00307     if (Map.MinMyGID64()-1>=Map.MinAllGID64()) GIDList[NumIDs++] = Map.MinMyGID64()-1;
00308     if (Map.MaxMyGID64()+1<=Map.MaxAllGID64()) GIDList[NumIDs++] = Map.MaxMyGID64()+1;
00309 
00310     Map.RemoteIDList(NumIDs, GIDList, PIDList, LIDList);
00311 
00312     NumIDs = 0;
00313 
00314     //EPETRA_TEST_ERR(!(PIDList[NumIDs]==-1),ierr);
00315     //EPETRA_TEST_ERR(!(LIDList[NumIDs++]==-1),ierr);
00316 
00317     if (Map.MinMyGID64()-1>=Map.MinAllGID64()) EPETRA_TEST_ERR(!(PIDList[NumIDs++]==MyPID-1),ierr);
00318     if (Map.MaxMyGID64()+1<=Map.MaxAllGID64()) EPETRA_TEST_ERR(!(PIDList[NumIDs]==MyPID+1),ierr);
00319     if (Map.MaxMyGID64()+1<=Map.MaxAllGID64()) EPETRA_TEST_ERR(!(LIDList[NumIDs++]==0),ierr);
00320 
00321     delete [] GIDList;
00322     delete [] PIDList;
00323     delete [] LIDList;
00324 
00325 
00326   }
00327   return (ierr);
00328 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines