Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
12 Views

dss_reorder gives access violation error.

Jump to solution

I'm trying to solve sparse symmetric system:

Matrix A looks like this (I set unly one half, like in example code  dss_sym_c.c ):

[[  1.17  -0.08   0.    -0.09   0.     0.     0.     0.     0.  ]
 [  0.     6.98  -1.73   0.    -4.16   0.     0.     0.     0.  ]
 [  0.     0.    10.5    0.     0.    -7.77   0.     0.     0.  ]
 [  0.     0.     0.     3.68  -0.86   0.    -1.73   0.     0.  ]
 [  0.     0.     0.     0.    13.55  -2.14   0.    -5.37   0.  ]
 [  0.     0.     0.     0.     0.    19.9    0.     0.    -8.97]
 [  0.     0.     0.     0.     0.     0.     4.04  -1.3    0.  ]
 [  0.     0.     0.     0.     0.     0.     0.    10.23  -2.55]
 [  0.     0.     0.     0.     0.     0.     0.     0.    12.53]]

And RHS:

[1,2,3,4,5,6,7,8,9]

The sample code after substitution of my data:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "mkl_dss.h"
#include "mkl_types.h"
/*
** Define the array and rhs vectors
*/
#define NROWS       9
#define NCOLS       9
#define NNONZEROS   23
#define NRHS        1
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,4,7,10,13,16,19,21,23,24 };
static _INTEGER_t columns[NNONZEROS] = { 4, 2, 1, 5, 3, 2, 6, 4, 3, 7, 5, 4, 8, 6, 5, 9, 7, 6, 8, 7, 9, 8, 9 };
static _DOUBLE_PRECISION_t values[NNONZEROS] = { -0.09,-0.08,1.17,-4.16,-1.73,6.98,-7.77,0,10.5,-1.73,-0.86,3.68,-5.37,-2.14,13.55,-8.97,0,19.90,-1.30,4.04,-2.55,10.23,12.53 };
static _DOUBLE_PRECISION_t rhs[NCOLS] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

int main()
{

    /* Allocate storage for the solver handle and the right-hand side. */
    _DOUBLE_PRECISION_t solValues[NROWS];
    _MKL_DSS_HANDLE_t handle;
    _INTEGER_t error;
    MKL_INT opt = MKL_DSS_DEFAULTS;
    MKL_INT sym = MKL_DSS_NON_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); // <<<< --------- This line gives access violation error. 
    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;

    /* -------------------------- */
    /* Deallocate solver storage  */
    /* -------------------------- */
    error = dss_delete(handle, opt);
    if (error != MKL_DSS_SUCCESS)
        goto printError;
    /* ---------------------- */
    /* Print solution vector  */
    /* ---------------------- */
    printf(" Solution array: ");
    for (int i = 0; i < nCols; i++)
        printf(" %g", solValues);
    printf("\n");

    getchar();

    exit(0);
printError:
    printf("Solver returned error code %d\n", error);
    exit(1);
}

 

The python code I checked my matrix:

import numpy as np
from scipy.sparse import csr_matrix

indptr = np.array([1,4,7,10,13,16,19,21,23,24])
indices = np.array([4,2,1,5,3,2,6,4,3,7,5,4,8,6,5,9,7,6,8,7,9,8,9])

indptr-=1;
indices-=1;

data = np.array([-0.09,-0.08,1.17,-4.16,-1.73,6.98,-7.77,0,10.5,-1.73,-0.86,3.68,-5.37,-2.14,13.55,-8.97,0,19.90,-1.30,4.04,-2.55,10.23,12.53 ])

print(csr_matrix( (data,indices,indptr), shape=(9,9) ).todense())

Can you help me please ? What I made wrong ?

0 Kudos

Accepted Solutions
Highlighted
Black Belt
12 Views

You have to provide the columns of the nonzero elements in each row in increasing order -- {{1,2,4}, {2,3,5},...}. Similarly for the data values array. See the DSS section of the MKL documentation for details.

View solution in original post

0 Kudos
3 Replies
Highlighted
Moderator
12 Views

what version of mkl do you use? we had some problem on the reordering stage with MKL 2017 beta. DSS API doesn't contains matrix checker option. You may try to use check if the input matrix is valid by using Pardiso API and set iparm[26]=1.

0 Kudos
Highlighted
Black Belt
13 Views

You have to provide the columns of the nonzero elements in each row in increasing order -- {{1,2,4}, {2,3,5},...}. Similarly for the data values array. See the DSS section of the MKL documentation for details.

View solution in original post

0 Kudos
Highlighted
Beginner
12 Views

Thank you very much for help.

I use 

    MKL_INT info;
    MKL_INT job[8] = { 1, // COO to CSR  // Need 2 here to get correct conversion
        1, // 1 based indexing in CSR rows
        1, // 1 based indexing in CSR cols
        0, // 
        nnz, // number of the non-zero elements
        0, // job indicator
        0,
        0
    };

    mkl_dcsrcoo(job, &m, a_csr, j_csr, i_csr, &nnz,  acoo, rowind, colind, &info);

to convert matrix to CSR format. 

When changed job[0] to 2 error was resolved.

0 Kudos