00001 #include "EpetraExt_ConfigDefs.h"
00002 #ifdef HAVE_MPI
00003 #include "mpi.h"
00004 #include "Epetra_MpiComm.h"
00005 #else
00006 #include "Epetra_SerialComm.h"
00007 #endif
00008 #include <vector>
00009 #include "Teuchos_CommandLineProcessor.hpp"
00010 #include "Epetra_Map.h"
00011 #include "Epetra_BlockMap.h"
00012 #include "Epetra_CrsMatrix.h"
00013 #include "Epetra_Time.h"
00014 #include "Epetra_Vector.h"
00015 #include "Epetra_Import.h"
00016 #include "EpetraExt_Exception.h"
00017 #include "EpetraExt_Utils.h"
00018 #include "EpetraExt_HDF5.h"
00019 #include "EpetraExt_BlockMapIn.h"
00020 #include "EpetraExt_BlockMapOut.h"
00021 #include "EpetraExt_MultiVectorIn.h"
00022 #include "EpetraExt_MultiVectorOut.h"
00023 #include "EpetraExt_RowMatrixOut.h"
00024 #include "EpetraExt_CrsMatrixIn.h"
00025
00026
00027
00028
00029
00030
00031
00032 int main (int argc, char **argv)
00033 {
00034 #ifdef HAVE_MPI
00035 MPI_Init(&argc, &argv);
00036 Epetra_MpiComm Comm(MPI_COMM_WORLD);
00037 #else
00038 Epetra_SerialComm Comm;
00039 #endif
00040
00041 if (Comm.MyPID() == 0)
00042 {
00043 cout << "Converter from MatrixMarket files to HDF5 files" << endl;
00044 cout << "For notes on the usage, execute" << endl;
00045 cout << " ./HDF5Converter.exe --help" << endl;
00046 cout << endl;
00047 }
00048
00049
00050 Teuchos::CommandLineProcessor CLP;
00051
00052 string MapFileName = "not-set";
00053 string XFileName = "not-set";
00054 string BFileName = "not-set";
00055 string MatrixFileName = "not-set";
00056 string HDF5FileName = "myfile.f5";
00057 string MapHDF5Name = "map";
00058 string XHDF5Name = "X";
00059 string BHDF5Name = "B";
00060 string MatrixHDF5Name = "matrix";
00061
00062 CLP.setOption("in-map", &MapFileName, "map file name");
00063 CLP.setOption("in-matrix", &MatrixFileName, "matrix file name");
00064 CLP.setOption("in-x", &XFileName, "x vector file name");
00065 CLP.setOption("in-b", &BFileName, "b vector file name");
00066 CLP.setOption("output", &HDF5FileName, "name of HDF5 file");
00067 CLP.setOption("out-map", &MapHDF5Name, "map name in HDF5 file");
00068 CLP.setOption("out-matrix", &MatrixHDF5Name, "matrix name in HDF5 file");
00069 CLP.setOption("out-x", &XHDF5Name, "x vector name in HDF5 file");
00070 CLP.setOption("out-b", &BHDF5Name, "b vector name in HDF5 file");
00071
00072 CLP.throwExceptions(false);
00073 CLP.parse(argc,argv);
00074
00075 Epetra_Map* Map = 0;
00076 Epetra_CrsMatrix* Matrix = 0;
00077 Epetra_MultiVector* X = 0;
00078 Epetra_MultiVector* B = 0;
00079
00080 if (MapFileName != "not-set")
00081 {
00082 if (Comm.MyPID() == 0)
00083 cout << "Reading map from " << MapFileName << endl;
00084
00085 EpetraExt::MatrixMarketFileToMap(MapFileName.c_str(), Comm, Map);
00086 }
00087 else
00088 {
00089 cerr << "You need to specify a map, sorry" << endl;
00090 #ifdef HAVE_MPI
00091 MPI_Finalize();
00092 #endif
00093 exit(EXIT_SUCCESS);
00094 }
00095
00096 if (XFileName != "not-set")
00097 {
00098 if (Comm.MyPID() == 0)
00099 cout << "Reading vector from " << XFileName << endl;
00100
00101 EpetraExt::MatrixMarketFileToMultiVector(XFileName.c_str(), *Map, X);
00102 }
00103
00104 if (BFileName != "not-set")
00105 {
00106 if (Comm.MyPID() == 0)
00107 cout << "Reading vector from " << BFileName << endl;
00108
00109 EpetraExt::MatrixMarketFileToMultiVector(BFileName.c_str(), *Map, B);
00110 }
00111
00112 if (MatrixFileName != "not-set")
00113 {
00114 if (Comm.MyPID() == 0)
00115 cout << "Reading matrix from " << MatrixFileName << endl;
00116
00117 EpetraExt::MatrixMarketFileToCrsMatrix(MatrixFileName.c_str(), *Map, Matrix);
00118 }
00119
00120
00121
00122
00123
00124 EpetraExt::HDF5 HDF5(Comm);
00125
00126 HDF5.Create(HDF5FileName);
00127
00128 if (Map)
00129 HDF5.Write(MapHDF5Name + EpetraExt::toString(Comm.NumProc()), *Map);
00130 if (Matrix)
00131 HDF5.Write(MatrixHDF5Name, *Matrix);
00132 if (X)
00133 HDF5.Write(XHDF5Name, *X);
00134 if (B)
00135 HDF5.Write(BHDF5Name, *B);
00136 HDF5.Close();
00137
00138 if (Map) delete Map;
00139 if (Matrix) delete Matrix;
00140 if (X) delete X;
00141 if (B) delete B;
00142
00143 #ifdef HAVE_MPI
00144 MPI_Finalize();
00145 #endif
00146
00147 return(EXIT_SUCCESS);
00148 }