Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

## Function mkl_sdnscsr- urgent

Beginner
1,380 Views
Hi,

I have got some basic questions.

I'm trying to use the functions of Intel Math Kernel Library- for converting a matrix in dense representation into CSR format.

There are the following possibilities as I see:

1) The function mkl_sdnscsr which has the following arguments;

(job, m , n, adns, lda, acsr, ja, ia, info)

Now:

from the inputs required;

acsr = array containing non zero elements of the matrix A. Its length is equal to the number of non zero elements of the matrix A.

ja = array containing the column indices for each non zero element of the matrix A.

My question is;

if in my routine, I do not have theindices of the non zero elements of my matrix available, then , how do I use this function?

Because, I have a matrix (Say) 'K' which is in dense form,and I have not stored the indices of the non zero elements. How can I use this function in such a case?

I just havea matrix of form:

3.14 0 0 20.04 0 0

0 27 0 0 -0.6 0

0 0 -0.01 0 0 0

-0.031 0 0 0.08 0 314

That is all and I want to convert into CSR format.

I just want to give this matrix as input and get the CSR format. Is it possible?

9 Replies
Moderator
1,380 Views
Hi, I am not sure I understand completely your question: You don't need to store indices of the non zeroes elements of the dense matrixes at all.
to convert from dense representation to CSR you need to do
job[0] = 0;.....
m = 6;
n = 4;
and make the call:
Beginner
1,380 Views

My code is like this:

int job[50],m,n;

int lda;

job[1]=0; job[2]=1; job[3]=1; job[4]=2;job[5]= 100;job[6]=1;

m=3;n=3;

lda=3;

return 0;

I get an error identifier mkl_sdnscsr is not identified. Please can anyone help? What is this due to?
Beginner
1,380 Views
Honored Contributor III
1,380 Views
You need to include the appropriate header files, e.g.,

#include "mkl_spblas.h"

Your MKL installation comes with at least one example source file (....\mkl\examples\spblas\source or ...\mkl\examples\spblasc\source\sconverters.c -- depending on the version of MKL that you have) that illustrates how to convert between different matrix storage formats.
Beginner
1,380 Views
Thanks a lot but it is still not working.I just pasted the code from the example file as you mentioned- to make it easy to start:

// project9.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include "mkl_spblas.h"

#include "mkl_types.h"

int _tmain(int argc, _TCHAR* argv[])

{

/********************************************************************************

* Definition arrays for sparse matrix formats

********************************************************************************/

#define M 4

#define N 4

#define LDA 4

#define NZMAX 8

#define NNZ 8

#define MBLK 2

#define NN 2

#define INFO 0

#define MN 16

#define IBASE1 1

#define IBASE2 1

#define LOCAT 2

#define IDIAG 3

#define NDIAG 4

#define INDIA 12

MKL_INT m = M, n=N, lda=LDA, nzmax=NZMAX, nnz = NNZ, mblk=MBLK, nn=NN, info=INFO,mn=MN;

MKL_INT ibase1 = IBASE1,ibase2 = IBASE2, locat = LOCAT,idiag = IDIAG,ndiag = NDIAG;

float Absr[NZMAX];

float Absr_standard[NZMAX] = {5.0, 9.0, 8.0, 2.0, 3.0, 1.0, 6.0, 4.0};

float Acsr[NZMAX];

float Acsr_standard[NZMAX] = {5.0, 8.0, 9.0, 2.0, 3.0, 6.0, 1.0, 4.0};

float Acsc[NZMAX];

float Acsc_standard[NZMAX] = {5.0, 9.0, 8.0, 2.0, 3.0,

1.0, 6.0, 4.0};

float Adia_standard[INDIA] = {0.0, 9.0, 0.0, 1.0,

5.0, 2.0, 3.0, 4.0,

8.0, 0.0, 6.0, 0.0};

float Askyl_standard[6] = {5.0, 9.0, 2.0, 3.0, 1.0, 4.0};

float Acoo[NZMAX];

float Acoo_standard[NZMAX] = {5.0, 8.0, 9.0, 2.0, 3.0, 6.0, 1.0, 4.0};

MKL_INT AI[M+1];

MKL_INT AI1[M+1];

MKL_INT AI_standard[M+1] = {1, 3, 5, 7, 9};

MKL_INT AJ[NZMAX];

MKL_INT AJ1[NZMAX];

MKL_INT AJ_standard[NZMAX] = {1, 2, 1, 2, 3, 4, 3, 4};

MKL_INT AJB[NN];

MKL_INT AJB_standard[MBLK] = {1,2};

MKL_INT AIB[NN+1];

MKL_INT AIB_standard[MBLK+1] = {1, 2, 3};

MKL_INT ir[NZMAX];

MKL_INT ir_standard[NZMAX] = {1, 1, 2, 2, 3, 3, 4, 4};

MKL_INT jc[NZMAX];

MKL_INT jc_standard[NZMAX] = {1, 2, 1, 2, 3, 4, 3, 4};

MKL_INT pointers[M+1];

MKL_INT pointersl_standard[M+1] = {1, 2, 4, 5, 7};

MKL_INT distance[IDIAG];

MKL_INT distance_standard[IDIAG] = {-1, 0, 1};

MKL_INT AJL[6];

MKL_INT AJL_standard[6] = {1, 1, 2, 3, 3, 4};

//*************************************************************************************************

//* Declaration of local variables :

//*************************************************************************************************

MKL_INT job0=1;

MKL_INT ifail=1;

MKL_INT nr,ldAbsr;

MKL_INT i,j,ij;

float rfail=0.0;

MKL_INT job[8];

printf("\n EXAMPLE PROGRAM FOR CONVERTER FROM ONE\n");

printf("\n SPARSE FORMAT ROUTINES TO OTHER \n");

printf("\n REAL SINGLE PRECISION \n");

locat=2;

ibase1=1;

ibase2=1;

job[1]=ibase1;

job[2]=ibase2;

job[3]=locat;

job[4]=nzmax;

//***************************************************************************************************

//* TASK 1 Obtain compressed sparse row matrix from dense matrix

//**************************************************************************************************

for ( j=0; j

for ( i=0; i

for ( j=0; j

for ( i=0; i

job[0]=0;

job[5]=1;

if (info!=0) goto FAILURE1;

for ( i=0; i

{

ifail=AI-AI_standard;

if (ifail!=0) goto FAILURE1;

}

for ( i=0; i

{

ifail=AJ-AJ_standard;

if (ifail!=0) goto FAILURE1;

}

for ( i=0; i

{

rfail=Acsr-Acsr_standard;

if (rfail!=0) goto FAILURE1;

}

FAILURE1: printf("\n Example FAILED to convert from dns to csr...\n");

return 1;

}

When I build, i get error:

1>project9.obj : error LNK2019: unresolved external symbol _mkl_sdnscsr referenced in function _wmain

Valued Contributor I
1,380 Views

A.
Beginner
1,380 Views
I'm sorry to come again but tried various options in link adviser but get same error regarding 'fatal link error'.
Moderator
1,380 Views
if Linker adviser didn't help then may be you will try to build these (\examples\spblas\source\) examples and see how they are linking ...may be it would help you. if not, we will create the MVSC project and attach to this thread.... but please try to build the example first.
`[bash]..mkllibia32> dumpbin /symbols mkl_core.lib | find "mkl_sdnscsr"[/bash]`