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

Function mkl_sdnscsr- urgent

atee1234
Beginner
1,806 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?

Pleasehelp.








0 Kudos
9 Replies
Gennady_F_Intel
Moderator
1,806 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;
float adns[24]; // your input dense
and make the call:
mkl_sdnscsr(job, &m, &n, adns,....);
--Gennady
0 Kudos
atee1234
Beginner
1,806 Views

Thanks a lot for your reply.

My code is like this:

int job[50],m,n;

float adns[3][3];

int lda;

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

m=3;n=3;

adns[1][1]=1; adns[1][2]=0;adns[1][3]=0; adns[2][1]=0; adns[2][2]=3;adns[2][3]=4; adns[3][1]=0;adns[3][2]=4;adns[3][3]=5;

lda=3;

mkl_sdnscsr(job,&m,&n,adns,&lda)

return 0;



I get an error identifier mkl_sdnscsr is not identified. Please can anyone help? What is this due to?
0 Kudos
atee1234
Beginner
1,806 Views
Looking forward for the reply!
0 Kudos
mecej4
Honored Contributor III
1,806 Views
You need to include the appropriate header files, e.g.,

#include "mkl_spblas.h"

in your source file(s) and link against the appropriate MKL libraries.

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.
0 Kudos
atee1234
Beginner
1,806 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 Adns[MN];

float Adns_standard[MN];

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[INDIA];

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 Asky[6];

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

Adns[i + lda*j]=0.0;

Adns[0]=5.0;

Adns[1]=9.0;

Adns[4]=8.0;

Adns[5]=2.0;

Adns[10]=3.0;

Adns[11]=1.0;

Adns[14]=6.0;

Adns[15]=4.0;

for ( j=0; j

for ( i=0; i

Adns_standard[i + lda*j]=Adns[i + lda*j];

job[0]=0;

job[5]=1;

mkl_sdnscsr(job,&m,&n,Adns,&lda,Acsr,AJ,AI,&info);

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

Please help, urgent.

0 Kudos
ArturGuzik
Valued Contributor I
1,806 Views
You still miss libraries in your linking command. try to use Link Advisor to get the correct one.

A.
0 Kudos
atee1234
Beginner
1,806 Views
I'm sorry to come again but tried various options in link adviser but get same error regarding 'fatal link error'.
0 Kudos
Gennady_F_Intel
Moderator
1,806 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.
--Gennady
0 Kudos
mecej4
Honored Contributor III
1,806 Views
Older versions of MKL may not provide the single-precision versions of functions, e.g., mkl_sdnscsr(). For example, the MKL that came with Intel C++ 11.1.065 did not. You can settle the question for your installation by running the command below in the MKL\LIB\IA32 directory:
[bash]..mkllibia32> dumpbin /symbols mkl_core.lib | find "mkl_sdnscsr"
[/bash]
If nothing is found, you conclude that only the double precision version is available, and you may consider obtaining a later version of MKL.

Your code in #5 above has a bug; you need to add a "return 0;" statement before the FAILURE1: label. Otherwise, the code prints a "FAILED" message even after a correct run.
0 Kudos
Reply