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