Map/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_Map & Map, int NumGlobalElements, int NumMyElements, 
00031        int *MyGlobalElements, int IndexBase, Epetra_Comm& Comm,
00032        bool DistributedGlobal)
00033 {
00034   int i, ierr=0, forierr = 0;
00035 
00036   EPETRA_TEST_ERR(!Map.ConstantElementSize(),ierr);
00037 
00038   EPETRA_TEST_ERR(DistributedGlobal!=Map.DistributedGlobal(),ierr);
00039 
00040 
00041   EPETRA_TEST_ERR(Map.ElementSize()!=1,ierr);
00042   int *MyElementSizeList = new int[NumMyElements];
00043 
00044   EPETRA_TEST_ERR(Map.ElementSizeList(MyElementSizeList)!=0,ierr);
00045 
00046   forierr = 0;
00047   for (i=0; i<NumMyElements; i++) forierr += MyElementSizeList[i]!=1;
00048   EPETRA_TEST_ERR(forierr,ierr);
00049 
00050   delete [] MyElementSizeList;
00051 
00052   const Epetra_Comm & Comm1 = Map.Comm();
00053 
00054   EPETRA_TEST_ERR(Comm1.NumProc()!=Comm.NumProc(),ierr);
00055 
00056   EPETRA_TEST_ERR(Comm1.MyPID()!=Comm.MyPID(),ierr);
00057 
00058   EPETRA_TEST_ERR(Map.IndexBase()!=IndexBase,ierr);
00059 
00060   EPETRA_TEST_ERR(!Map.LinearMap() && MyGlobalElements==0,ierr);
00061 
00062   EPETRA_TEST_ERR(Map.LinearMap() && MyGlobalElements!=0,ierr);
00063 
00064   EPETRA_TEST_ERR(Map.MaxAllGID()!=NumGlobalElements-1+IndexBase,ierr);
00065 
00066   EPETRA_TEST_ERR(Map.MaxElementSize()!=1,ierr);
00067 
00068   int MaxLID = Map.MaxLID();
00069   EPETRA_TEST_ERR(MaxLID!=NumMyElements-1,ierr);
00070 
00071   int MaxMyGID = (Comm.MyPID()+1)*NumMyElements-1+IndexBase;
00072   if (Comm.MyPID()>2) MaxMyGID+=3;
00073   if (!DistributedGlobal) MaxMyGID = NumMyElements-1+IndexBase;
00074   EPETRA_TEST_ERR(Map.MaxMyGID()!=MaxMyGID,ierr);
00075 
00076   EPETRA_TEST_ERR(Map.MinAllGID()!=IndexBase,ierr);
00077 
00078   EPETRA_TEST_ERR(Map.MinElementSize()!=1,ierr);
00079 
00080   EPETRA_TEST_ERR(Map.MinLID()!=0,ierr);
00081 
00082   int MinMyGID = Comm.MyPID()*NumMyElements+IndexBase;
00083   if (Comm.MyPID()>2) MinMyGID+=3;
00084   if (!DistributedGlobal) MinMyGID = 0;
00085   EPETRA_TEST_ERR(Map.MinMyGID()!=MinMyGID,ierr);
00086   
00087   int * MyGlobalElements1 = new int[NumMyElements];
00088   EPETRA_TEST_ERR(Map.MyGlobalElements(MyGlobalElements1)!=0,ierr);
00089 
00090   forierr = 0;
00091   if (MyGlobalElements==0)
00092     {
00093       for (i=0; i<NumMyElements; i++) 
00094   forierr += MyGlobalElements1[i]!=MinMyGID+i;
00095       EPETRA_TEST_ERR(forierr,ierr);
00096     }
00097   else {
00098     for (i=0; i<NumMyElements; i++)
00099       forierr += MyGlobalElements[i]!=MyGlobalElements1[i];
00100     EPETRA_TEST_ERR(forierr,ierr);
00101   }
00102   EPETRA_TEST_ERR(Map.NumGlobalElements()!=NumGlobalElements,ierr);
00103   
00104   EPETRA_TEST_ERR(Map.NumGlobalPoints()!=NumGlobalElements,ierr);
00105   
00106   EPETRA_TEST_ERR(Map.NumMyElements()!=NumMyElements,ierr);  
00107 
00108   EPETRA_TEST_ERR(Map.NumMyPoints()!=NumMyElements,ierr);
00109 
00110   int MaxMyGID2 = Map.GID(Map.LID(MaxMyGID));
00111   EPETRA_TEST_ERR(MaxMyGID2 != MaxMyGID,ierr);
00112   int MaxLID2 = Map.LID(Map.GID(MaxLID));
00113   EPETRA_TEST_ERR(MaxLID2 != MaxLID,ierr);
00114 
00115   EPETRA_TEST_ERR(Map.GID(MaxLID+1) != IndexBase-1,ierr);// MaxLID+1 doesn't exist
00116   EPETRA_TEST_ERR(Map.LID(MaxMyGID+1) != -1,ierr);// MaxMyGID+1 doesn't exist or is on a different processor
00117 
00118   EPETRA_TEST_ERR(!Map.MyGID(MaxMyGID),ierr);
00119   EPETRA_TEST_ERR(Map.MyGID(MaxMyGID+1),ierr);
00120 
00121   EPETRA_TEST_ERR(!Map.MyLID(MaxLID),ierr);
00122   EPETRA_TEST_ERR(Map.MyLID(MaxLID+1),ierr);
00123 
00124   EPETRA_TEST_ERR(!Map.MyGID(Map.GID(MaxLID)),ierr);
00125   EPETRA_TEST_ERR(Map.MyGID(Map.GID(MaxLID+1)),ierr);
00126 
00127   EPETRA_TEST_ERR(!Map.MyLID(Map.LID(MaxMyGID)),ierr);
00128   EPETRA_TEST_ERR(Map.MyLID(Map.LID(MaxMyGID+1)),ierr);
00129 
00130   // Check RemoteIDList function
00131   // Get some GIDs off of each processor to test
00132   int TotalNumEle, NumElePerProc, NumProc = Comm.NumProc();
00133   int MinNumEleOnProc;
00134   int NumMyEle=Map.NumMyElements();
00135   Comm.MinAll(&NumMyEle,&MinNumEleOnProc,1);
00136   if (MinNumEleOnProc > 5) NumElePerProc = 6;
00137   else NumElePerProc = MinNumEleOnProc;
00138   if (NumElePerProc > 0) {
00139     TotalNumEle = NumElePerProc*NumProc;
00140     int * MyGIDlist = new int[NumElePerProc];
00141     int * GIDlist = new int[TotalNumEle];
00142     int * PIDlist = new int[TotalNumEle];
00143     int * LIDlist = new int[TotalNumEle];
00144     for (i=0; i<NumElePerProc; i++)
00145     MyGIDlist[i] = MyGlobalElements1[i];
00146     Comm.GatherAll(MyGIDlist,GIDlist,NumElePerProc);// Get a few values from each proc
00147     Map.RemoteIDList(TotalNumEle, GIDlist, PIDlist, LIDlist);
00148     int MyPID= Comm.MyPID();
00149 
00150     forierr = 0;
00151     for (i=0; i<TotalNumEle; i++) {
00152       if (Map.MyGID(GIDlist[i])) {
00153   forierr += PIDlist[i] != MyPID;
00154   forierr += !Map.MyLID(Map.LID(GIDlist[i])) || Map.LID(GIDlist[i]) != LIDlist[i] || Map.GID(LIDlist[i]) != GIDlist[i];
00155       }
00156       else {
00157   forierr += PIDlist[i] == MyPID; // If MyGID comes back false, the PID listed should be that of another proc
00158       }
00159     }
00160     EPETRA_TEST_ERR(forierr,ierr);
00161 
00162     delete [] MyGIDlist;
00163     delete [] GIDlist;
00164     delete [] PIDlist;
00165     delete [] LIDlist;
00166   }
00167 
00168   delete [] MyGlobalElements1;
00169 
00170   // Check RemoteIDList function (assumes all maps are linear, even if not stored that way)
00171 
00172   if (Map.LinearMap()) {
00173 
00174     int * GIDList = new int[3];
00175     int * PIDList = new int[3];
00176     int * LIDList = new int[3];
00177     int MyPID = Map.Comm().MyPID();
00178   
00179     int NumIDs = 0;
00180     //GIDList[NumIDs++] = Map.MaxAllGID()+1; // Should return -1 for both PID and LID
00181     if (Map.MinMyGID()-1>=Map.MinAllGID()) GIDList[NumIDs++] = Map.MinMyGID()-1;
00182     if (Map.MaxMyGID()+1<=Map.MaxAllGID()) GIDList[NumIDs++] = Map.MaxMyGID()+1;
00183 
00184     Map.RemoteIDList(NumIDs, GIDList, PIDList, LIDList);
00185 
00186     NumIDs = 0;
00187 
00188     //EPETRA_TEST_ERR(!(PIDList[NumIDs]==-1),ierr);
00189     //EPETRA_TEST_ERR(!(LIDList[NumIDs++]==-1),ierr);
00190 
00191     if (Map.MinMyGID()-1>=Map.MinAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs++]==MyPID-1),ierr);
00192     if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(PIDList[NumIDs]==MyPID+1),ierr);
00193     if (Map.MaxMyGID()+1<=Map.MaxAllGID()) EPETRA_TEST_ERR(!(LIDList[NumIDs++]==0),ierr);
00194 
00195     delete [] GIDList;
00196     delete [] PIDList;
00197     delete [] LIDList;
00198 
00199   }
00200   
00201   return (ierr);
00202 }
00203 
00204  

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