46 #include "Teuchos_CommHelpers.hpp" 47 #include "Epetra_Comm.h" 48 #include "Epetra_Map.h" 49 #include "Epetra_CrsMatrix.h" 50 #include "Epetra_Vector.h" 51 #include "Trilinos_Util.h" 55 const Epetra_Comm& comm)
57 int my_proc = comm.MyPID();
59 long long num_global_rows = 0;
62 std::ifstream* infile = NULL;
63 infile =
new std::ifstream(mm_file.c_str());
64 if (infile == NULL || !*infile) {
65 throw std::runtime_error(
"Failed to open file "+mm_file);
68 std::ifstream& in = *infile;
75 }
while(line[0] ==
'%');
79 int numrows, numcols, nnz;
80 std::istringstream isstr(line);
81 isstr >> numrows >> numcols >> nnz;
85 throw std::runtime_error(
"Failed to parse matrix-market header.");
89 num_global_rows = numrows;
90 nnz_per_row = nnz/numrows;
93 comm.Broadcast(&num_global_rows, 1, 0);
94 comm.Broadcast(&nnz_per_row, 1, 0);
96 const int indexBase = 0;
97 Epetra_Map rowmap(num_global_rows, indexBase, comm);
99 Epetra_CrsMatrix* A =
new Epetra_CrsMatrix(Copy, rowmap, nnz_per_row);
101 Teuchos::Array<long long> col;
102 Teuchos::Array<double> coef;
105 int g_row=-1, last_row=-1;
110 std::istringstream isstr(line);
111 isstr >> irow >> icol >> val;
113 if (isstr.fail())
continue;
114 if (!rowmap.MyGID(irow-1))
continue;
117 if (g_row != last_row) {
118 if (col.size() > 0) {
119 A->InsertGlobalValues(last_row, col.size(), &coef[0], &col[0] );
125 col.push_back(icol-1);
129 if (col.size() > 0) {
130 A->InsertGlobalValues(g_row, col.size(), &coef[0], &col[0]);
140 const Epetra_Comm& comm)
142 int my_proc = comm.MyPID();
144 long long num_global_rows = 0;
146 std::ifstream* infile = NULL;
148 infile =
new std::ifstream(mm_file.c_str());
149 if (infile == NULL || !*infile) {
150 throw std::runtime_error(
"Failed to open file "+mm_file);
153 std::ifstream& in = *infile;
160 }
while(line[0] ==
'%');
164 int numrows, numcols;
165 std::istringstream isstr(line);
166 isstr >> numrows >> numcols;
170 throw std::runtime_error(
"Failed to parse matrix-market header.");
173 num_global_rows = numrows;
176 comm.Broadcast(&num_global_rows, 1, 0);
178 const int indexBase = 0;
179 Epetra_Map rowmap(num_global_rows, indexBase, comm);
181 Epetra_Vector* b =
new Epetra_Vector(rowmap, 1);
188 std::ifstream& in = *infile;
191 std::istringstream isstr(line);
194 if (isstr.fail())
continue;
196 b->ReplaceGlobalValue(irow++, icol, val);
204 const Epetra_Comm& Comm,
205 Epetra_CrsMatrix*& A,
208 Epetra_Map* Map = NULL;
209 Epetra_Vector* x = NULL;
210 Epetra_Vector* xexact = NULL;
211 Trilinos_Util_ReadHb2Epetra64(const_cast<char*>(hb_file.c_str()), Comm, Map,
Epetra_Vector * read_vector_mm(const std::string &mm_file, const Epetra_Comm &comm)
Epetra_CrsMatrix * read_matrix_mm(const std::string &mm_file, const Epetra_Comm &comm)
void read_matrix_hb(const std::string &hb_file, const Epetra_Comm &Comm, Epetra_CrsMatrix *&A, Epetra_Vector *&b)