Hello. I am using the following example (heavily inspired by mkl/examples/solverc/source/dss_sym_c.c) to try and solve a system on a very simple diagonal matrix. The code below works correctly, and the output is as follows:
(0): 1 2 -3 -3
(1): 1 -2 -3 3
(2): 0 0 -0 -0
(3): 1 0.333333 -0.142857 -0.142857
However, if I assign MKL_DSS_DIAGONAL_SOLVE to opt_solve, instead of asking for a full solve, I get garbage as the resulting solution. The output is as follows:
(0): 2.02053e-319 1.39142e-317 2.27227e-318 1.39142e-317
(1): 3.52525e-294 2.64829e-314 0 0
(2): 0 0 2.82113e-317 2.81698e-317
(3): 0 0 0 2.122e-314
Am I doing anything wrong? The only difference between the first and second result is the changed assignment to opt_solve.
Thanks,
Pietro
#include <stdio.h> #include <stdlib.h> #include <math.h> #include "mkl_dss.h" #include "mkl_types.h" #define NROWS 4 #define NCOLS 4 #define NNONZEROS 4 #define NRHS 4 MKL_INT main () { const MKL_INT nRows = NROWS; const MKL_INT nCols = NCOLS; const MKL_INT nNonZeros = NNONZEROS; const MKL_INT nRhs = NRHS; _INTEGER_t rowIndex[NROWS + 1] = { 1, 2, 3, 4, 5}; _INTEGER_t columns[NNONZEROS] = { 1,2,3,4}; _DOUBLE_PRECISION_t values[NNONZEROS] = { 1,3,-7,-7}; _DOUBLE_PRECISION_t rhs[NRHS*NROWS] = { 1, 6, 21, 21, 1,-6, 21, -21, 0, 0, 0, 0, 1, 1, 1, 1}; _DOUBLE_PRECISION_t solValues[NRHS*NCOLS]; _MKL_DSS_HANDLE_t handle; _INTEGER_t error; MKL_INT i,j, opt_create = MKL_DSS_DEFAULTS, opt_def_str = MKL_DSS_SYMMETRIC, opt_reord = MKL_DSS_AUTO_ORDER, opt_factor = MKL_DSS_INDEFINITE, opt_solve = MKL_DSS_DEFAULTS, opt_default = MKL_DSS_DEFAULTS; if (( (error = dss_create (handle, opt_create)) != MKL_DSS_SUCCESS) || ((error = dss_define_structure (handle, opt_def_str, rowIndex, nRows, nCols, columns, nNonZeros)) != MKL_DSS_SUCCESS) || ((error = dss_reorder (handle, opt_reord, 0)) != MKL_DSS_SUCCESS) || ((error = dss_factor_real (handle, opt_factor, values)) != MKL_DSS_SUCCESS) || ((error = dss_solve_real (handle, opt_solve, rhs, nRhs, solValues)) != MKL_DSS_SUCCESS) || ((error = dss_delete (handle, opt_default)) != MKL_DSS_SUCCESS)) { printf ("error: %dn", error); } else { printf ("Solutions:n"); for (j=0;j<nRhs; ++j) { printf ("(%d): ", j); for (i = 0; i < nCols; i++) printf (" %g", solValues[j*nCols+i]); printf ("n"); } } }