example/UG_Ex1/cxx_main.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include "Epetra_config.h"
00004 #ifdef HAVE_MPI
00005 #include "mpi.h"
00006 #include "Epetra_MpiComm.h"
00007 #else
00008 #include "Epetra_SerialComm.h"
00009 #endif
00010 #include "Epetra_Map.h"
00011 #include "Epetra_IntSerialDenseVector.h"
00012 #include "Epetra_SerialDenseVector.h"
00013 #include "Epetra_Vector.h"
00014 #include "Epetra_CrsMatrix.h"
00015 #include "Epetra_Version.h"
00016                                             
00017 // prototype
00018 double power_method(const Epetra_CrsMatrix& A);
00019 int main(int argc, char *argv[]) {
00020 #ifdef HAVE_MPI
00021   MPI_Init(&argc,&argv);
00022   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00023 #else
00024   Epetra_SerialComm Comm;
00025 #endif
00026 
00027   if (Comm.MyPID()==0)
00028     cout << Epetra_Version() << endl << endl;
00029 
00030   cout << Comm << endl; // Print out process information
00031   // Get the number of global equations from the command line
00032   if (argc!=2) { 
00033     cout << "Usage: " << argv[0] << " number_of_equations" << endl;
00034     exit(1);
00035    }
00036   int NumGlobalElements = atoi(argv[1]);
00037   // Construct a Map that puts approximately the same number of 
00038   // equations on each processor.
00039   Epetra_Map Map(NumGlobalElements, 0, Comm);
00040   // Get update list and number of local equations from newly created Map.
00041   int NumMyElements = Map.NumMyElements();
00042   // Create an Epetra_CrsMatrix
00043   Epetra_CrsMatrix A(Copy, Map, 1);
00044  // Add  rows one-at-a-time
00045   Epetra_SerialDenseVector DiagVal(1); 
00046   DiagVal[0] = 2.0; // We set all diagonal values to 2
00047   Epetra_IntSerialDenseVector ColIndices(1);
00048   for (int i=0; i<NumMyElements; i++) {
00049     int RowIndex = Map.GID(i);
00050     ColIndices[0] = RowIndex;
00051     // Put in the diagonal entry
00052     A.InsertGlobalValues(RowIndex, DiagVal.Length(), 
00053        DiagVal.Values(), ColIndices.Values());  
00054   }
00055   if (Map.MyGID(0)) { // Change the first global diagonal value to 4.0
00056     DiagVal[0] = 4.0;
00057     int RowIndex = 0;
00058     ColIndices[0] = RowIndex;
00059   A.ReplaceGlobalValues(RowIndex, DiagVal.Length(), 
00060       DiagVal.Values(), ColIndices.Values());
00061   }
00062   // Finish up
00063  A.FillComplete();
00064   // Iterate
00065   double lambda = power_method(A);
00066   if (Comm.MyPID()==0) 
00067     cout << endl << "Estimate of Dominant Eigenvalue = " << lambda << endl;   
00068 #ifdef UG_EX1_MPI
00069   MPI_Finalize() ;
00070 #endif
00071 return 0;
00072 }

Generated on Wed May 12 21:41:04 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7