/* examples/C/lsmr.c - Example code for SPRAL_LSMR package */ #include "spral.h" #include #include void matrix_mult(int m, int n, int const *ptr, int const *row, double const *val, double const *v, double *u); void matrix_mult_trans(int m, int n, int const *ptr, int const *row, double const *val, double const *u, double *v); int main(void) { /* Derived types */ void *keep; struct spral_lsmr_options options; struct spral_lsmr_inform inform; /* Initialize derived types */ keep = NULL; spral_lsmr_default_options(&options); options.unit_diagnostics = -1; /* Switch off diagnostic printing */ /* Data for matrix: * ( 1.0 -1.0 ) * ( 2.0 ) * ( 2.0 2.0 ) * ( 5.0 3.0 -2.0 ) * ( 6.0 ) */ const int m = 5, n = 3; int ptr[] = { 0, 3, 5, 9 }; int row[] = { 0, 2, 3, 1, 3, 0, 2, 3, 4 }; double val[] = { 1.0, 2.0, 5.0, 2.0, 3.0, -1.0, 2.0, -2.0, 6.0 }; /* Data for rhs b */ double b[] = { 1.0, 1.0, 1.0, 1.0, 1.0 }; /* prepare for LSMR calls (using no preconditioning) */ int action = 0; double u[m], v[n], x[n]; for(int i=0; i