00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00081
00082
00083
00084
00085 Epetra_Map * readMap;
00086 Epetra_CrsMatrix * readA;
00087 Epetra_Vector * readx;
00088 Epetra_Vector * readb;
00089 Epetra_Vector * readxexact;
00090
00091
00092 Trilinos_Util_ReadHb2Epetra(argv[1], Comm, readMap, readA, readx, readb, readxexact);
00093
00094
00095 Epetra_Map map(readMap->NumGlobalElements(), 0, Comm);
00096
00097
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
00135
00136
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 }