Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
6592 Discussions

## sparse equation system Beginner
126 Views

Hi!

In the below code, I have declared one matrix and one vector: A and B. The  matrix A is symmetric from main diagonal. I converted the matrix A from dense format to CSR format, and from CSR format to coordinate format using the function mkl_dcsrcoo. All conversions are ok, but I can not solve correctly the system AxY=B. I obtained a wrong solution. The correct solution is: Y=[0.5 0.5 0.5]

How can I obtain the correct solution?

The code is following:

```#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include<conio.h>
#include<math.h>
#include "mkl.h"
#include "mkl_lapacke.h"

int _tmain(int argc, _TCHAR* argv[])
{
double A = {{2.5,-0.5,0.},{-0.5,5,-0.5},{0,-0.5,2.5}};
double B={1.0,2.0,1.0};
MKL_INT  rows = 3, cols = 3, nnz = 7,info;
MKL_INT job={0,0,0,2,nnz,2};
//for conversion of matrix A to CSR format
double  *arrV      = new double[nnz];
MKL_INT *Columns   = new MKL_INT[nnz];
MKL_INT *Rows      = new MKL_INT[rows+1];

mkl_ddnscsr(job,&rows, &cols, A, &rows, arrV, Columns, Rows,&info);

printf("\Values\n");
for(int i=0;i<nnz;i++)
printf("%.3f ",arrV);
printf("\nColumns\n");
for(int i=0;i<nnz;i++)
printf("%d ",Columns);
printf("\nRows\n");
for(int i=0;i<rows+1;i++)
printf("%d ",Rows);
printf("\n");

//convert to column format
double  *acoo      = new double[nnz];
int     *rowind    = new int[nnz];
int     *colind	   = new int[nnz];

MKL_INT job1={0,0,0,0,nnz,3};
mkl_dcsrcoo(job1,&rows,arrV,Columns,Rows,&nnz,acoo,rowind,colind,&info);
printf("info mkl_dcsrcoo=%d\nacoo\n",info);
for(int i=0;i<nnz;i++)
printf("%.3f ",acoo);
printf("\n");
for(int i=0;i<nnz;i++)
printf("%d ",rowind);
printf("\n");
for(int i=0;i<nnz;i++)
printf("%d ",colind);

MKL_INT colsC=3;
double alpha=1;
double *Y=new double;
mkl_dcoosm ("n",&rows,&colsC,&alpha,"TUNC",acoo,rowind,colind,&nnz,B,&rows,Y,&colsC);
printf("\n");
for(int i=0;i<3;i++)
printf("%.3f ",Y);

delete[] arrV;
delete[] Columns;
delete[] Rows;
delete[] acoo;
delete[] rowind;
delete[] colind;
_getch();
return 0;
}
```  