BlockMap/checkmap.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //               Epetra: Linear Algebra Services Package 
00005 //                 Copyright (2001) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ************************************************************************
00027 //@HEADER
00028 
00029 #include "checkmap.h"
00030 int checkmap(Epetra_BlockMap & Map, int NumGlobalElements, int NumMyElements, 
00031        int *MyGlobalElements, int ElementSize, int * ElementSizeList,
00032        int NumGlobalPoints, int NumMyPoints,
00033        int IndexBase, Epetra_Comm& Comm,
00034        bool DistributedGlobal,
00035        bool IsOneToOne)
00036 {
00037 
00038   int i, ierr=0, forierr=0;// forierr is used in for loops, then is tested
00039   // after for loop completes to see if it is non zero - potentially prevents
00040   // thousands of error messages
00041 
00042   if (ElementSizeList==0)
00043     {
00044       EPETRA_TEST_ERR(!Map.ConstantElementSize(),ierr);
00045     }
00046   else
00047     EPETRA_TEST_ERR(Map.ConstantElementSize(),ierr);
00048   
00049   EPETRA_TEST_ERR(DistributedGlobal!=Map.DistributedGlobal(),ierr);
00050 
00051   EPETRA_TEST_ERR(IsOneToOne!=Map.IsOneToOne(),ierr);
00052 
00053   int *MyElementSizeList;
00054 
00055   if (ElementSizeList==0)
00056     {
00057       EPETRA_TEST_ERR(Map.ElementSize()!=ElementSize,ierr);
00058       
00059       MyElementSizeList = new int[NumMyElements];
00060       
00061       EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
00062       forierr = 0;
00063       for (i=0; i<NumMyElements; i++) 
00064         forierr += MyElementSizeList[i]!=ElementSize;
00065       EPETRA_TEST_ERR(forierr,ierr);
00066 
00067       EPETRA_TEST_ERR(Map.MaxMyElementSize() != ElementSize,ierr);
00068       EPETRA_TEST_ERR(Map.MinMyElementSize() != ElementSize,ierr);
00069     }
00070   else
00071     {
00072       MyElementSizeList = new int[NumMyElements];
00073       EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
00074       int MaxSize = MyElementSizeList[0];
00075       int MinSize = MyElementSizeList[0];
00076       forierr=0;
00077       for (i=0; i<NumMyElements; i++) {
00078         forierr += MyElementSizeList[i]!=ElementSizeList[i];
00079   if (MyElementSizeList[i] > MaxSize)
00080     MaxSize = MyElementSizeList[i];
00081   if (MyElementSizeList[i] < MinSize)
00082     MinSize = MyElementSizeList[i];
00083 
00084   // Test ElementSize(int LID) method 
00085 
00086   forierr += Map.ElementSize(Map.LID(MyGlobalElements[i])) != ElementSizeList[i];
00087       }
00088       EPETRA_TEST_ERR(forierr,ierr);
00089    
00090       EPETRA_TEST_ERR(MaxSize !=Map.MaxMyElementSize(),ierr);
00091       EPETRA_TEST_ERR(MinSize !=Map.MinMyElementSize(),ierr);
00092     }
00093 
00094   const Epetra_Comm & Comm1 = Map.Comm();
00095 
00096   EPETRA_TEST_ERR(Comm1.NumProc()!=Comm.NumProc(),ierr);
00097 
00098   EPETRA_TEST_ERR(Comm1.MyPID()!=Comm.MyPID(),ierr);
00099 
00100   EPETRA_TEST_ERR(Map.IndexBase()!=IndexBase,ierr);
00101 
00102   EPETRA_TEST_ERR(!Map.LinearMap() && MyGlobalElements==0,ierr);
00103 
00104   EPETRA_TEST_ERR(Map.LinearMap() && MyGlobalElements!=0,ierr);
00105 
00106   EPETRA_TEST_ERR(Map.MaxAllGID()!=NumGlobalElements-1+IndexBase,ierr);
00107 
00108   EPETRA_TEST_ERR(Map.MaxElementSize()!=ElementSize,ierr);
00109 
00110   int MaxLID = Map.MaxLID();
00111   EPETRA_TEST_ERR(MaxLID!=NumMyElements-1,ierr);
00112 
00113   int MaxMyGID = (Comm.MyPID()+1)*NumMyElements-1+IndexBase;
00114   if (Comm.MyPID()>2) MaxMyGID+=3;
00115   if (!DistributedGlobal) MaxMyGID = NumMyElements-1+IndexBase;
00116   EPETRA_TEST_ERR(Map.MaxMyGID()!=MaxMyGID,ierr);
00117 
00118   EPETRA_TEST_ERR(Map.MinAllGID()!=IndexBase,ierr);
00119 
00120   if (ElementSizeList==0)
00121     {
00122       EPETRA_TEST_ERR(Map.MinElementSize()!=ElementSize,ierr);
00123     }
00124   else EPETRA_TEST_ERR(Map.MinElementSize()!=2,ierr);
00125 
00126   int MinLID = Map.MinLID();
00127   EPETRA_TEST_ERR(MinLID!=0,ierr);
00128 
00129   int MinMyGID = Comm.MyPID()*NumMyElements+IndexBase;
00130   if (Comm.MyPID()>2) MinMyGID+=3;
00131   if (!DistributedGlobal) MinMyGID = IndexBase; // Not really needed
00132   EPETRA_TEST_ERR(Map.MinMyGID()!=MinMyGID,ierr);
00133 
00134   int * MyGlobalElements1 = new int[NumMyElements];
00135   EPETRA_TEST_ERR(Map.MyGlobalElements(MyGlobalElements1)!=0,ierr);
00136   
00137   forierr = 0;
00138   if (MyGlobalElements==0) {
00139     for (i=0; i<NumMyElements; i++) 
00140       forierr += MyGlobalElements1[i]!=MinMyGID+i;
00141     EPETRA_TEST_ERR(forierr,ierr);
00142   }
00143   else {
00144     for (i=0; i<NumMyElements; i++)
00145       forierr += MyGlobalElements[i]!=MyGlobalElements1[i];
00146     EPETRA_TEST_ERR(forierr,ierr);
00147   }
00148   EPETRA_TEST_ERR(Map.NumGlobalElements()!=NumGlobalElements,ierr);
00149   
00150   EPETRA_TEST_ERR(Map.NumGlobalPoints()!=NumGlobalPoints,ierr);
00151   
00152   EPETRA_TEST_ERR(Map.NumMyElements()!=NumMyElements,ierr);  
00153 
00154   EPETRA_TEST_ERR(Map.NumMyPoints()!=NumMyPoints,ierr);
00155 
00156   int MaxMyGID2 = Map.GID(Map.LID(MaxMyGID));
00157   EPETRA_TEST_ERR(MaxMyGID2 != MaxMyGID,ierr);
00158   int MaxLID2 = Map.LID(Map.GID(MaxLID));
00159   EPETRA_TEST_ERR(MaxLID2 != MaxLID,ierr);
00160 
00161   EPETRA_TEST_ERR(Map.GID(MaxLID+1) != IndexBase-1,ierr);// MaxLID+1 doesn't exist
00162   EPETRA_TEST_ERR(Map.LID(MaxMyGID+1) != -1,ierr);// MaxMyGID+1 doesn't exist or is on a different processor
00163 
00164   EPETRA_TEST_ERR(!Map.MyGID(MaxMyGID),ierr);
00165   EPETRA_TEST_ERR(Map.MyGID(MaxMyGID+1),ierr);
00166 
00167   EPETRA_TEST_ERR(!Map.MyLID(MaxLID),ierr);
00168   EPETRA_TEST_ERR(Map.MyLID(MaxLID+1),ierr);
00169 
00170   EPETRA_TEST_ERR(!Map.MyGID(Map.GID(MaxLID)),ierr);
00171   EPETRA_TEST_ERR(Map.MyGID(Map.GID(MaxLID+1)),ierr);
00172 
00173   EPETRA_TEST_ERR(!Map.MyLID(Map.LID(MaxMyGID)),ierr);
00174   EPETRA_TEST_ERR(Map.MyLID(Map.LID(MaxMyGID+1)),ierr);
00175 
00176   // Test the FirstPointInElementList methods, begin by testing that they produce identical results
00177   int * FirstPointInElementList = new int[NumMyElements+1];
00178   Map.FirstPointInElementList(FirstPointInElementList);
00179   int * FirstPointInElementList1 = Map.FirstPointInElementList();
00180   forierr = 0;
00181   for (i=0; i<=NumMyElements; i++)
00182     forierr += FirstPointInElementList[i]!=FirstPointInElementList1[i];
00183   EPETRA_TEST_ERR(forierr,ierr);
00184   // Now make sure values are correct
00185   forierr = 0;
00186   if (Map.ConstantElementSize()) {
00187     for (i=0; i<=NumMyElements; i++)
00188       forierr += FirstPointInElementList1[i]!=(i*ElementSize);// NOTE:FirstPointInElement[NumMyElements] is not the first point of an element
00189     EPETRA_TEST_ERR(forierr,ierr);
00190   }
00191   else {
00192     int FirstPoint = 0;
00193     for (i=0; i<NumMyElements; i++) {
00194       forierr += FirstPointInElementList1[i]!=FirstPoint;
00195       FirstPoint += ElementSizeList[i];
00196     }
00197     EPETRA_TEST_ERR(forierr,ierr);
00198     EPETRA_TEST_ERR(FirstPointInElementList[NumMyElements] != NumMyPoints,ierr);// The last entry in the array = the total number of Points on the proc
00199   }
00200   delete [] FirstPointInElementList;
00201 
00202   // Declare some variables for the FindLocalElementID test
00203   int ElementID, Offset;
00204   // Test the PointToElementList methods, begin by testing that they produce identical results
00205   int * PointToElementList = new int[NumMyPoints];
00206   Map.PointToElementList(PointToElementList);
00207   int * PointToElementList1 = Map.PointToElementList();
00208   forierr = 0;
00209   for (i=0; i<NumMyPoints; i++)
00210     forierr += PointToElementList1[i] != PointToElementList[i];
00211   EPETRA_TEST_ERR(forierr,ierr);
00212   //Now make sure values are correct
00213   forierr=0;
00214   if (Map.ConstantElementSize()) {
00215     for (i=0; i<NumMyElements; i++)
00216       for (int j=0; j<ElementSize; j++) {
00217   forierr += PointToElementList[i*ElementSize+j] != i;
00218   // Test FindLocalElementID method
00219   Map.FindLocalElementID(i*ElementSize+j,ElementID,Offset);
00220   forierr += ElementID != i || Offset != j;
00221       }
00222     EPETRA_TEST_ERR(forierr,ierr);
00223   }
00224   else {
00225     int MyPointTot = 0; // Keep track of total number of points in all previously completely checked elements
00226     for (i=0; i<NumMyElements; i++) {
00227       for (int j=0; j<ElementSizeList[i]; j++) {
00228   forierr += PointToElementList[MyPointTot+j] != i;
00229   // Test FindLocalElementID method
00230   Map.FindLocalElementID(MyPointTot+j,ElementID,Offset);
00231   forierr += ElementID != i || Offset != j;
00232       }
00233       MyPointTot += ElementSizeList[i];
00234     }
00235     EPETRA_TEST_ERR(forierr,ierr);
00236   }
00237   delete [] PointToElementList;
00238 
00239   // Check RemoteIDList function that includes a parameter for size
00240   // Get some GIDs off of each processor to test
00241   int TotalNumEle, NumElePerProc, NumProc = Comm.NumProc();
00242   int MinNumEleOnProc;
00243   int NumMyEle = Map.NumMyElements();
00244   Comm.MinAll(&NumMyEle,&MinNumEleOnProc,1);
00245   if (MinNumEleOnProc > 5) NumElePerProc = 6;
00246   else NumElePerProc = MinNumEleOnProc;
00247   if (NumElePerProc > 0) {
00248     TotalNumEle = NumElePerProc*NumProc;
00249     int * MyGIDlist = new int[NumElePerProc];
00250     int * GIDlist = new int[TotalNumEle];
00251     int * PIDlist = new int[TotalNumEle];
00252     int * LIDlist = new int[TotalNumEle];
00253     int * SizeList = new int[TotalNumEle];
00254     for (i=0; i<NumElePerProc; i++)
00255     MyGIDlist[i] = MyGlobalElements1[i];
00256     Comm.GatherAll(MyGIDlist,GIDlist,NumElePerProc);// Get a few values from each proc
00257     Map.RemoteIDList(TotalNumEle, GIDlist, PIDlist, LIDlist, SizeList);
00258     int MyPID= Comm.MyPID();
00259     forierr = 0;
00260     for (i=0; i<TotalNumEle; i++) {
00261       if (Map.MyGID(GIDlist[i])) {
00262   forierr += PIDlist[i] != MyPID;
00263   forierr += !Map.MyLID(Map.LID(GIDlist[i])) || Map.LID(GIDlist[i]) != LIDlist[i] || Map.GID(LIDlist[i]) != GIDlist[i];
00264   forierr += SizeList[i] != Map.ElementSize(LIDlist[i]);
00265       }
00266       else {
00267   forierr += PIDlist[i] == MyPID; // If MyGID comes back false, the PID listed should be that of another proc
00268       }
00269     }
00270     EPETRA_TEST_ERR(forierr,ierr);
00271 
00272     delete [] MyGIDlist;
00273     delete [] GIDlist;
00274     delete [] PIDlist;
00275     delete [] LIDlist;
00276     delete [] SizeList;
00277   }
00278 
00279   delete [] MyGlobalElements1;
00280   delete [] MyElementSizeList;
00281 
00282   // Check RemoteIDList function (assumes all maps are linear, even if not stored that way)
00283 
00284   if (Map.LinearMap()) {
00285 
00286     int * GIDList = new int[3];
00287     int * PIDList = new int[3];
00288     int * LIDList = new int[3];
00289     int MyPID = Map.Comm().MyPID();
00290   
00291     int NumIDs = 0;
00292     //GIDList[NumIDs++] = Map.MaxAllGID()+1; // Should return -1 for both PID and LID
00293     if (Map.MinMyGID()-1>=Map.MinAllGID()) GIDList[NumIDs++] = Map.MinMyGID()-1;
00294     if (Map.MaxMyGID()+1<=Map.MaxAllGID()) GIDList[NumIDs++] = Map.MaxMyGID()+1;
00295 
00296     Map.RemoteIDList(NumIDs, GIDList, PIDList, LIDList);
00297 
00298     NumIDs = 0;
00299 
00300     //EPETRA_TEST_ERR(!(PIDList[NumIDs]==-1),ierr);
00301     //EPETRA_TEST_ERR(!(LIDList[NumIDs++]==-1),ierr);
00302 
00303     if (Map.MinMyGID()-1>=Map.MinAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs++]==MyPID-1),ierr);
00304     if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs]==MyPID+1),ierr);
00305     if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(LIDList[NumIDs++]==0),ierr);
00306 
00307     delete [] GIDList;
00308     delete [] PIDList;
00309     delete [] LIDList;
00310 
00311 
00312   }
00313   return (ierr);
00314 }

Generated on Thu Sep 18 12:37:56 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1