Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "MOR_MatrixMarketMVInputFile.hpp"
00007
00008 #include "Epetra_Comm.h"
00009
00010 #include "EpetraExt_MultiVectorIn.h"
00011 #include "EpetraExt_mmio.h"
00012
00013 #include "Teuchos_TestForException.hpp"
00014 #include "Teuchos_Assert.hpp"
00015
00016 #include <stdexcept>
00017 #include <cstddef>
00018 #include <cstdio>
00019
00020 namespace MOR {
00021
00022 MatrixMarketMVInputFile::MatrixMarketMVInputFile(const std::string &path) :
00023 MultiVectorInputFile(path)
00024 {
00025
00026 }
00027
00028 int MatrixMarketMVInputFile::readVectorCount(const Epetra_Comm &comm)
00029 {
00030 const int masterPID = 0;
00031
00032 int result;
00033 {
00034 std::FILE * handle;
00035 {
00036 int ierr;
00037 if (comm.MyPID() == masterPID) {
00038
00039 handle = std::fopen(this->path().c_str(), "r");
00040 ierr = (handle == NULL);
00041 }
00042
00043 const int info = comm.Broadcast(&ierr, 1, masterPID);
00044 TEUCHOS_TEST_FOR_EXCEPT(info != 0);
00045
00046 TEUCHOS_TEST_FOR_EXCEPTION(ierr != 0,
00047 std::runtime_error,
00048 "Cannot open input file: " + path());
00049 }
00050
00051 {
00052 int ierr;
00053 if (comm.MyPID() == masterPID) {
00054 int dummy;
00055 ierr = EpetraExt::mm_read_mtx_array_size(handle, &dummy, &result);
00056 }
00057
00058 const int info = comm.Broadcast(&ierr, 1, masterPID);
00059 TEUCHOS_TEST_FOR_EXCEPT(info != 0);
00060
00061 TEUCHOS_TEST_FOR_EXCEPTION(ierr != 0,
00062 std::runtime_error,
00063 "Error reading input file: " + path());
00064 }
00065 }
00066
00067
00068 const int info = comm.Broadcast(&result, 1, masterPID);
00069 TEUCHOS_TEST_FOR_EXCEPT(info != 0);
00070
00071 return result;
00072 }
00073
00074 Teuchos::RCP<Epetra_MultiVector> MatrixMarketMVInputFile::read(const Epetra_Map &map)
00075 {
00076
00077
00078 Epetra_MultiVector *raw_result = NULL;
00079 const int ierr = EpetraExt::MatrixMarketFileToMultiVector(this->path().c_str(), map, raw_result);
00080 TEUCHOS_TEST_FOR_EXCEPTION(ierr != 0,
00081 std::runtime_error,
00082 "Error reading input file: " + path());
00083
00084
00085 Teuchos::RCP<Epetra_MultiVector> result(raw_result);
00086
00087 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(result));
00088 return result;
00089 }
00090
00091 }