test/MultiVector/cxx_main.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 // Epetra_BlockMap Test routine
00030 
00031 #include "Epetra_Time.h"
00032 #include "Epetra_BlockMap.h"
00033 #include "Epetra_MultiVector.h"
00034 #include "Epetra_Import.h"
00035 #ifdef EPETRA_MPI
00036 #include "Epetra_MpiComm.h"
00037 #include <mpi.h>
00038 #else
00039 #include "Epetra_SerialComm.h"
00040 #endif
00041 #include "BuildTestProblems.h"
00042 #include "ExecuteTestProblems.h"
00043 #include "../epetra_test_err.h"
00044 #include "Epetra_Version.h"
00045 
00046 int main(int argc, char *argv[]) {
00047 
00048   int ierr = 0;
00049 
00050 #ifdef EPETRA_MPI
00051 
00052   // Initialize MPI
00053 
00054   MPI_Init(&argc,&argv);
00055   //int rank; // My process ID
00056 
00057   //MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00058   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00059 
00060 #else
00061 
00062   //int rank = 0;
00063   Epetra_SerialComm Comm;
00064 
00065 #endif
00066 
00067   Comm.SetTracebackMode(0); // This should shut down any error tracing
00068   bool verbose = false;
00069 
00070   // Check if we should print results to standard out
00071   if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
00072 
00073   //  char tmp;
00074   //  if (rank==0) cout << "Press any key to continue..."<< endl;
00075   //  if (rank==0) cin >> tmp;
00076   //  Comm.Barrier();
00077 
00078   Comm.SetTracebackMode(0); // This should shut down any error traceback reporting
00079 
00080   int MyPID = Comm.MyPID();
00081   int NumProc = Comm.NumProc(); 
00082 
00083   int numMyElements = 3;
00084   int numGlobalElements = NumProc*numMyElements;
00085 
00086   Epetra_BlockMap pll_map(numGlobalElements, numMyElements, 1, 0, Comm);
00087 
00088   Epetra_MultiVector pll_vec(pll_map, 1);
00089 
00090   double* vals = pll_vec.Values();
00091 
00092   for(int i=0; i<numMyElements; ++i) {
00093     double val = (MyPID*numMyElements+i)*1.0;
00094     vals[i] = val;
00095   }
00096 
00097   std::cout << "pll_vec: " <<std::endl<< pll_vec << std::endl;
00098 
00099  int numGlobal = pll_map.NumGlobalElements();
00100 
00101   int my_pid = pll_map.Comm().MyPID();
00102 
00103   //construct a new Epetra_BlockMap where proc 0
00104   //has all of the elements in pll_map.
00105 
00106   //numLocal == numGlobal if my_pid == 0,
00107   //numLocal == 0 if my_pid != 0
00108   int numLocal = my_pid==0 ? numGlobal : 0;
00109 
00110   Epetra_BlockMap my_map(numGlobal, numLocal, 1, 0, pll_map.Comm());
00111 
00112   //construct an import object
00113   //with target==my_map, source==pll_map
00114 
00115   Epetra_Import importer(my_map, pll_map);
00116 
00117   //construct the multivector that will hold all elements
00118   //on proc 0
00119   Epetra_MultiVector my_vec(my_map, pll_vec.NumVectors());
00120 
00121   //now import pll_vec's contents into my_vec
00122   my_vec.Import(pll_vec, importer, Insert);
00123 
00124   std::cout << "my_vec: " << std::endl << my_vec << std::endl;
00125 
00126   double negvalue = -2.0*Epetra_MaxDouble;
00127 
00128   my_vec.PutScalar(negvalue);
00129 
00130   double maxval = 0.0;
00131   int err = my_vec.MaxValue(&maxval);
00132 
00133   if (std::abs(maxval - negvalue) > 1.e-12 ||
00134       err < 0) {
00135     if (verbose) {
00136       std::cerr << "MultiVector::MaxValue test failed." << std::endl;
00137     }
00138     ierr = -1;
00139   }
00140 
00141   double largevalue = 2.0*Epetra_MaxDouble;
00142 
00143   my_vec.PutScalar(largevalue);
00144 
00145   double minval = 0.0;
00146   err = my_vec.MinValue(&minval);
00147 
00148   if (std::abs(minval - largevalue) > 1.e-12 ||
00149       err < 0) {
00150     if (verbose) {
00151       std::cerr << "MultiVector::MinValue test failed." << std::endl;
00152     }
00153     ierr = -1;
00154   }
00155 
00156 #ifdef EPETRA_MPI
00157   MPI_Finalize();
00158 #endif
00159 
00160   return ierr;
00161 }
00162 

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