Epetra Package Browser (Single Doxygen Collection) Development
test/SimpleLongLongTest/cxx_main.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 "Epetra_Map.h"
00044 #include "Epetra_Time.h"
00045 #include "Epetra_CrsMatrix.h"
00046 #include "Epetra_Vector.h"
00047 #include "Epetra_Flops.h"
00048 #ifdef EPETRA_MPI
00049 #include "Epetra_MpiComm.h"
00050 #include "mpi.h"
00051 #else
00052 #include "Epetra_SerialComm.h"
00053 #endif
00054 #include "../epetra_test_err.h"
00055 #include "Epetra_Version.h"
00056 
00057 // prototypes
00058 
00059 int main(int argc, char *argv[])
00060 {
00061   int ierr = 0;
00062 
00063 #ifdef EPETRA_MPI
00064 
00065   // Initialize MPI
00066 
00067   MPI_Init(&argc,&argv);
00068   int rank; // My process ID
00069 
00070   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00071   Epetra_MpiComm Comm( MPI_COMM_WORLD );
00072 
00073 #else
00074 
00075   int rank = 0;
00076   Epetra_SerialComm Comm;
00077 
00078 #endif
00079 
00080   bool verbose = false;
00081 
00082   // Check if we should print results to standard out
00083   if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
00084 
00085   int verbose_int = verbose ? 1 : 0;
00086   Comm.Broadcast(&verbose_int, 1, 0);
00087   verbose = verbose_int==1 ? true : false;
00088 
00089 
00090   //  char tmp;
00091   //  if (rank==0) cout << "Press any key to continue..."<< std::endl;
00092   //  if (rank==0) cin >> tmp;
00093   //  Comm.Barrier();
00094 
00095   Comm.SetTracebackMode(0); // This should shut down any error traceback reporting
00096   int MyPID = Comm.MyPID();
00097   int NumProc = Comm.NumProc();
00098 
00099   if(verbose && MyPID==0)
00100     cout << Epetra_Version() << std::endl << std::endl;
00101 
00102   if (verbose) cout << "Processor "<<MyPID<<" of "<< NumProc
00103                     << " is alive."<<endl;
00104 
00105   //bool verbose1 = verbose; // unused
00106 
00107   // Redefine verbose to only print on PE 0
00108   if(verbose && rank!=0) verbose = false;
00109 
00110   int NumMyEquations = 1;
00111   long long NumGlobalEquations = NumProc;
00112 
00113   // Get update list and number of local equations from newly created Map
00114   long long* MyGlobalElementsLL = new long long[NumMyEquations];
00115 
00116   MyGlobalElementsLL[0] = 2000000000+MyPID;
00117 
00118   // Construct a Map that puts approximately the same Number of equations on each processor
00119 
00120   Epetra_Map MapLL(NumGlobalEquations, NumMyEquations, MyGlobalElementsLL, 0, Comm);
00121 
00122   EPETRA_TEST_ERR(MapLL.GlobalIndicesInt(),ierr);
00123   EPETRA_TEST_ERR(!(MapLL.GlobalIndicesLongLong()),ierr);
00124 
00125   // Create an integer vector NumNz that is used to build the Petra Matrix.
00126   // NumNz[i] is the Number of OFF-DIAGONAL term for the ith global equation on this processor
00127 
00128   int* NumNzLL = new int[NumMyEquations];
00129   NumNzLL[0] = 0;
00130 
00131   // Create int types meant to add to long long matrix for test of failure
00132   int* MyIntGlobalElementsLL = new int[NumMyEquations];
00133   MyIntGlobalElementsLL[0] = 20000+MyPID;
00134 
00135   // Create a long long Epetra_Matrix
00136   Epetra_CrsMatrix A_LL(Copy, MapLL, NumNzLL);
00137   EPETRA_TEST_ERR(A_LL.IndicesAreGlobal(),ierr);
00138   EPETRA_TEST_ERR(A_LL.IndicesAreLocal(),ierr);
00139 
00140   // Insert values
00141   double one = 1.0;
00142 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00143   // Try to add ints which should fail and be caught as an int
00144   try {
00145     A_LL.InsertGlobalValues(MyIntGlobalElementsLL[0], 1, &one, MyIntGlobalElementsLL+0);
00146   } catch(int i) {
00147     EPETRA_TEST_ERR(!(i==-1),ierr);
00148   }
00149 #endif
00150 
00151   // Add long longs which should succeed
00152   EPETRA_TEST_ERR(!(A_LL.InsertGlobalValues(MyGlobalElementsLL[0], 1, &one, MyGlobalElementsLL+0)==0),ierr);
00153   EPETRA_TEST_ERR(!(A_LL.IndicesAreGlobal()),ierr);
00154   EPETRA_TEST_ERR(!(A_LL.FillComplete(false)==0),ierr);
00155   EPETRA_TEST_ERR(!(A_LL.IndicesAreLocal()),ierr);
00156 
00157 
00158   // Get update list and number of local equations from newly created Map
00159   int* MyGlobalElementsInt = new int[NumMyEquations];
00160 
00161   MyGlobalElementsInt[0] = 2000+MyPID;
00162 
00163   // Create an integer vector NumNz that is used to build the Petra Matrix.
00164   // NumNz[i] is the Number of OFF-DIAGONAL term for the ith global equation on this processor
00165 
00166   int* NumNzInt = new int[NumMyEquations];
00167   NumNzInt[0] = 0;
00168 
00169   // Create int types meant to add to long long matrix for test of failure
00170   long long* MyLLGlobalElementsInt = new long long[NumMyEquations];
00171   MyLLGlobalElementsInt[0] = 2000000000+MyPID;
00172 
00173 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00174   // Construct a Map that puts approximately the same Number of equations on each processor
00175 
00176   Epetra_Map MapInt(NumGlobalEquations, NumMyEquations, MyGlobalElementsInt, 0LL, Comm);
00177 
00178   EPETRA_TEST_ERR(!(MapInt.GlobalIndicesInt()),ierr);
00179   EPETRA_TEST_ERR(MapInt.GlobalIndicesLongLong(),ierr);
00180 
00181   // Create a int Epetra_Matrix
00182   Epetra_CrsMatrix A_Int(Copy, MapInt, NumNzInt);
00183   EPETRA_TEST_ERR(A_Int.IndicesAreGlobal(),ierr);
00184   EPETRA_TEST_ERR(A_Int.IndicesAreLocal(),ierr);
00185 
00186   // Insert values
00187   try {
00188     A_Int.InsertGlobalValues(MyLLGlobalElementsInt[0], 1, &one, MyLLGlobalElementsInt+0);
00189   } catch(int i) {
00190     EPETRA_TEST_ERR(!(i==-1),ierr);
00191   }
00192   // Add long longs which should succeed
00193   EPETRA_TEST_ERR(!(A_Int.InsertGlobalValues(MyGlobalElementsInt[0], 1, &one, MyGlobalElementsInt+0)==0),ierr);
00194   EPETRA_TEST_ERR(!(A_Int.IndicesAreGlobal()),ierr);
00195   EPETRA_TEST_ERR(!(A_Int.FillComplete(false)==0),ierr);
00196   EPETRA_TEST_ERR(!(A_Int.IndicesAreLocal()),ierr);
00197 #endif
00198 
00199   delete [] MyGlobalElementsLL;
00200   delete [] NumNzLL;
00201   delete [] MyIntGlobalElementsLL;
00202   delete [] MyGlobalElementsInt;
00203   delete [] NumNzInt;
00204   delete [] MyLLGlobalElementsInt;
00205 
00206 #ifdef EPETRA_MPI
00207   MPI_Finalize() ;
00208 #endif
00209 
00210 /* end main
00211 */
00212 return ierr ;
00213 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines