Quantcast
Channel: Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 2652

MKL-DSS-DSS-Error, reordering problem

$
0
0

I am trying to solve a sparse system of equations but I am getting this error "MKL-DSS-DSS-Error, reordering problem" without any more specifics on what the error is. This is what my code looks like:

#include "mkl_dss.h"

#include "mkl_types.h"
/*
** Define the array and rhs vectors
*/
//#define NROWS         5
//#define NCOLS         5
//#define NNONZEROS     9
//#define NRHS         1
#if defined(MKL_ILP64)
#define MKL_INT long long
#else
#define MKL_INT int
#endif
//static const MKL_INT nRows =     NROWS     ;
//static const MKL_INT nCols =     NCOLS     ;
//static const MKL_INT nNonZeros = NNONZEROS  ;
//static const MKL_INT nRhs =      NRHS     ;
//static _INTEGER_t rowIndex[NROWS+1] = { 1, 6, 7, 8, 9, 10 };
//static _INTEGER_t columns[NNONZEROS] = { 1, 2, 3, 4, 5, 2, 3, 4, 5 };
//static _DOUBLE_PRECISION_t values[NNONZEROS] = { 9, 1.5, 6, .75, 3, 0.5, 12, .625, 16 };
//static _DOUBLE_PRECISION_t rhs[NCOLS] = { 1, 2, 3, 4, 5 };

void mkl_dss(double* K, int* col_ind, int* row_ptr, double* F, int nn, int nnz) {

    MKL_INT nRows = 2*nn;
    MKL_INT nCols = 2*nn;
    MKL_INT nNonZeros = nnz;
    MKL_INT nRhs = 1;
    MKL_INT i;

    _INTEGER_t *rowIndex, *columns;
    _DOUBLE_PRECISION_t *values, *rhs, *solValues;

    rowIndex = new _INTEGER_t[nRows + 1];
    columns = new _INTEGER_t[nnz];
    values = new _DOUBLE_PRECISION_t[nnz];
    rhs = new _DOUBLE_PRECISION_t[nCols];
    solValues = new _DOUBLE_PRECISION_t[nCols];

    for(i = 0; i < nnz; i++){
        values[i] = K[i];
        columns[i] = col_ind[i];
    }

    for(i = 0; i < nRows + 1; i++)
        rowIndex[i] = row_ptr[i];
        
    for(i = 0; i < nCols; i++){
        rhs[i] = F[i];
        solValues[i] = 0.0;
    }
    
    /* Allocate storage for the solver handle and the right-hand side. */
//    _DOUBLE_PRECISION_t solValues[NROWS];
    _MKL_DSS_HANDLE_t handle;
    _INTEGER_t error;
    _CHARACTER_t statIn[] = "determinant";
    _DOUBLE_PRECISION_t statOut[5];
    MKL_INT opt = MKL_DSS_DEFAULTS;
    MKL_INT sym = MKL_DSS_SYMMETRIC;
    MKL_INT type = MKL_DSS_POSITIVE_DEFINITE;
/* --------------------- */
/* Initialize the solver */
/* --------------------- */
    error = dss_create(handle, opt );
    if ( error != MKL_DSS_SUCCESS ) goto printError;
/* ------------------------------------------- */
/* Define the non-zero structure of the matrix */
/* ------------------------------------------- */
    error = dss_define_structure(
        handle, sym, rowIndex, nRows, nCols,
        columns, nNonZeros );
    if ( error != MKL_DSS_SUCCESS ) goto printError;
/* ------------------ */
/* Reorder the matrix */
/* ------------------ */
    error = dss_reorder( handle, opt, 0);
    if ( error != MKL_DSS_SUCCESS ) goto printError;
/* ------------------ */
/* Factor the matrix */
/* ------------------ */
    error = dss_factor_real( handle, type, values );
    if ( error != MKL_DSS_SUCCESS ) goto printError;
/* ------------------------ */
/* Get the solution vector */
/* ------------------------ */
    error = dss_solve_real( handle, opt, rhs, nRhs, solValues );
    if ( error != MKL_DSS_SUCCESS ) goto printError;
/* ------------------------ */
/* Get the determinant (not for a diagonal matrix) */
/*--------------------------*/
    if ( nRows < nNonZeros ) {
        error = dss_statistics(handle, opt, statIn, statOut);
        if ( error != MKL_DSS_SUCCESS ) goto printError;
/*-------------------------*/
/* print determinant */
/*-------------------------*/
        printf(" determinant power is %g \n", statOut[0]);
        printf(" determinant base is %g \n", statOut[1]);
        printf(" Determinant is %g \n", (pow(10.0,statOut[0]))*statOut[1]);
    }
/* -------------------------- */
/* Deallocate solver storage */
/* -------------------------- */
    error = dss_delete( handle, opt );
    if ( error != MKL_DSS_SUCCESS ) goto printError;
/* ---------------------- */
/* Print solution vector */
/* ---------------------- */
    printf(" Solution array: ");
    for(i = 0; i< nCols; i++)
        printf(" %g", solValues[i] );
    printf("\n");
    
printError:
    printf("Solver returned error code %d\n", error);

    for(i = 0; i < nCols; i++)
        F[i] = solValues[i];

    delete[] rowIndex;
    delete[] columns;
    delete[] values; 
    delete[] rhs; 
    delete[] solValues;
}

The same piece of code worked for the default example problem, so I know the sparse solver compiles and links correctly. But it does not work when I use my own set of arrays. I have a hunch that opt = MKL_DSS_DEFAULTS is not working as it should. Should I be using something different ? I have used Fortran style indexing (starting from 1) for the columns and row index vectors. I have also tried zero based indexing and set the opt = MKL_DSS_MSG_LVL_WARNING + MKL_DSS_TERM_LVL_ERROR+MKL_DSS_ZERO_BASED_INDEXING which also did not work.


Viewing all articles
Browse latest Browse all 2652

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>