1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
/*
Copyright (c) 2012-2025, Intel Corporation
SPDX-License-Identifier: BSD-3-Clause
*/
#include "../../common/timing.h"
#include "algorithm.h"
#include "matrix.h"
#include "util.h"
#include <cmath>
int main(int argc, char **argv) {
if (argc < 4) {
printf("usage: %s <input-matrix> <input-rhs> <output-file>\n", argv[0]);
return -1;
}
double gmres_cycles;
DEBUG_PRINT("Loading A...\n");
Matrix *A = CRSMatrix::matrix_from_mtf(argv[1]);
if (A == nullptr)
return -1;
DEBUG_PRINT("... size: " SIZE_T_FORMAT "\n", A->cols());
DEBUG_PRINT("Loading b...\n");
Vector *b = Vector::vector_from_mtf(argv[2]);
if (b == nullptr)
return -1;
Vector x(A->cols());
DEBUG_PRINT("Beginning gmres...\n");
reset_and_start_timer();
gmres(*A, *b, x, A->cols() / 2, .01);
gmres_cycles = get_elapsed_mcycles();
// Write result out to file
x.to_mtf(argv[argc - 1]);
// Compute residual (double-check)
#ifdef DEBUG
Vector bprime(b->size());
A->multiply(x, bprime);
Vector resid(bprime.size(), &(bprime[0]));
resid.subtract(*b);
DEBUG_PRINT("residual error check: %lg\n", resid.norm() / b->norm());
#endif
// Print profiling results
DEBUG_PRINT("-- Total mcycles to solve : %.03f --\n", gmres_cycles);
}
|