EpetraExt Package Browser (Single Doxygen Collection) Development
MatrixMarket_IO.cpp
Go to the documentation of this file.
00001 /*@HEADER
00002 // ***********************************************************************
00003 // 
00004 //     EpetraExt: Epetra Extended - 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 
00030 #include "Epetra_ConfigDefs.h"
00031 #include "EpetraExt_Version.h"
00032 
00033 #ifdef EPETRA_MPI
00034 #include "mpi.h"
00035 #include "Epetra_MpiComm.h"
00036 #else
00037 #include "Epetra_SerialComm.h"
00038 #endif
00039 
00040 #include "Trilinos_Util.h"
00041 #include "Epetra_Comm.h"
00042 #include "Epetra_Map.h"
00043 #include "Epetra_Time.h"
00044 #include "Epetra_BlockMap.h"
00045 #include "Epetra_MultiVector.h"
00046 #include "Epetra_Vector.h"
00047 #include "Epetra_Export.h"
00048 
00049 #include "Epetra_VbrMatrix.h"
00050 #include "Epetra_CrsMatrix.h"
00051 
00052 #include "EpetraExt_RowMatrixOut.h"
00053 
00054 int main(int argc, char *argv[]) {
00055 
00056 #ifdef EPETRA_MPI
00057   MPI_Init(&argc,&argv);
00058   Epetra_MpiComm Comm (MPI_COMM_WORLD);
00059 #else
00060   Epetra_SerialComm Comm;
00061 #endif
00062 
00063   int MyPID = Comm.MyPID();
00064 
00065   bool verbose = true; 
00066   if (MyPID==0) verbose = true;
00067 
00068   if (verbose)
00069     cout << EpetraExt::EpetraExt_Version() << endl << endl;
00070                                                                                 
00071   cout << Comm << endl;
00072 
00073   if(argc < 2 && verbose) {
00074     cerr << "Usage: " << argv[0] 
00075    << " HB_filename" << endl;
00076     return(1);
00077 
00078   }
00079 
00080   // Uncomment the next three lines to debug in mpi mode
00081   //int tmp;
00082   //if (MyPID==0) cin >> tmp;
00083   //Comm.Barrier();
00084 
00085   Epetra_Map * readMap;
00086   Epetra_CrsMatrix * readA; 
00087   Epetra_Vector * readx; 
00088   Epetra_Vector * readb;
00089   Epetra_Vector * readxexact;
00090    
00091   // Call routine to read in HB problem
00092   Trilinos_Util_ReadHb2Epetra(argv[1], Comm, readMap, readA, readx, readb, readxexact);
00093 
00094   // Create uniform distributed map
00095   Epetra_Map map(readMap->NumGlobalElements(), 0, Comm);
00096 
00097   // Create Exporter to distribute read-in matrix and vectors
00098 
00099   Epetra_Export exporter(*readMap, map);
00100   Epetra_CrsMatrix A(Copy, map, 0);
00101   Epetra_Vector x(map);
00102   Epetra_Vector b(map);
00103   Epetra_Vector xexact(map);
00104 
00105   Epetra_Time FillTimer(Comm);
00106   x.Export(*readx, exporter, Add);
00107   b.Export(*readb, exporter, Add);
00108   xexact.Export(*readxexact, exporter, Add);
00109   Comm.Barrier();
00110   double vectorRedistributeTime = FillTimer.ElapsedTime();
00111   A.Export(*readA, exporter, Add);
00112   Comm.Barrier();
00113   double matrixRedistributeTime = FillTimer.ElapsedTime() - vectorRedistributeTime;
00114   assert(A.FillComplete()==0);    
00115   Comm.Barrier();
00116   double fillCompleteTime = FillTimer.ElapsedTime() - matrixRedistributeTime;
00117   if (Comm.MyPID()==0)  {
00118     cout << "\n\n****************************************************" << endl;
00119     cout << "\n Vector redistribute  time (sec) = " << vectorRedistributeTime<< endl;
00120     cout << "    Matrix redistribute time (sec) = " << matrixRedistributeTime << endl;
00121     cout << "    Transform to Local  time (sec) = " << fillCompleteTime << endl<< endl;
00122   }
00123   Epetra_Vector tmp1(*readMap);
00124   Epetra_Vector tmp2(map);
00125   readA->Multiply(false, *readxexact, tmp1);
00126 
00127   A.Multiply(false, xexact, tmp2);
00128   double residual;
00129   tmp1.Norm2(&residual);
00130   if (verbose) cout << "Norm of Ax from file            = " << residual << endl;
00131   tmp2.Norm2(&residual);
00132   if (verbose) cout << "Norm of Ax after redistribution = " << residual << endl << endl << endl;
00133 
00134   //cout << "A from file = " << *readA << endl << endl << endl;
00135 
00136   //cout << "A after dist = " << A << endl << endl << endl;
00137 
00138   delete readA;
00139   delete readx;
00140   delete readb;
00141   delete readxexact;
00142   delete readMap;
00143 
00144   Comm.Barrier();
00145 
00146   EpetraExt::RowMatrixToMatrixMarketFile("test.mm", A, "test matrix", "This is a test matrix");
00147                
00148 #ifdef EPETRA_MPI
00149   MPI_Finalize() ;
00150 #endif
00151 
00152 return 0 ;
00153 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines