Community
cancel
Showing results for 
Search instead for 
Did you mean: 
utab
Beginner
42 Views

problem with mkl_dcsradd, the last entry is not there

Dear all,

I am trying to add two sparse crs matrices through mkl_dcsradd,
+ I am first converting my 0 based indices for the CSR matrix to 1-based indices in the routine
+ call the routine with request =1 to compute the nonzeros of the resulting matrix per row, ic array and also to get the nnz of the resulting operation which is returned in the last element of the ic array
+ allocate the jc and c array with the last element of the ic array
+ call the routine with request 2 this time.

however I am not find the last element of my resulting matrix right. As an example here is the simple sparse matrix I tried to add up to itself, basically C = A + beta* A, where beta =1,

1 2 0
2 3 1
0 1 4

then I convert the indices to one based and get(and they are increasing row wise as mentioned in the docs.)

1
2
1
2
3
2
3
--
1
3
6

the first set are the column indices as 1 based and the second set are the row pointer indices again 1-based. Seems correct. Calling the routine with these index arrays, and the allocation

ic = new long long int [m+1]; // as mentioned above with request 1

I find the ic = 7, and call this actual_nnz_for_C which is the number of nonzeros in C then allocate c and jc depending on this information

c = new double[actual_nnz_for_C];
jc = new long long int[actual_nnz_for_C];

and call routine with request 2, runs fine however, the result I get when I try to print the resulting values with

for(int k=0; k {
std::cout << jc << " " << c << std::endl;
}

I get

1 2
2 4
1 4
2 6
3 2
2 2
0 3.16202e-322

where the last entry is not right. Is there a problem with my allocations?

Where am I mistaken?

Any help is appreciated.

Best,
Umut

EDIT:

Just to test my understanding the matrices are different than above..

int main()
{
double a[] = {1,2,2,3,1,1,4};
double b[] = {1,2,2,3,1,1,4};
long long int ja[] = {1,2,1,2,3,2,3};
long long int ia[] = {1,3,6,7};
long long int jb[] = {1,3,1,2,3,2,3};
long long int ib[] = {1,3,6,7};
double* c = NULL;
long long int* jc = NULL;
long long int* ic = NULL;
//
MKL_INT m = 3;
MKL_INT n = 3;
MKL_INT k = 2;
double beta = 1.0;
char trans = 'N';
MKL_INT request = 1;
MKL_INT sort = 0;
MKL_INT nzmax = 0;
MKL_INT info;
//
ic = new long long int[m+1];
mkl_dcsradd(&trans, &request, &sort,
&m, &n,
a, ja, ia, β,
b, jb, ib, c,
jc, ic, &nzmax, &info);
//
c = new double[ic];
jc = new long long int[ic];
//
request = 2;
mkl_dcsradd(&trans, &request, &sort,
&m, &n,
a, ja, ia, β,
b, jb, ib, c,
jc, ic, &nzmax, &info);
//
for(int z=0;z;z++)
std::cout << c << std::endl;
return 0;
}

out
2
2
2
4
6
2
2
0














0 Kudos
1 Reply
Chao_Y_Intel
Employee
42 Views

Hello,

A few notes on the problem,
For CSR format:
This last element for ia/ib should be 8, not 7:
Also the length for c is ic-1.

I have a bit change, and I got:
2
4
4
6
2
2
8

Thanks,
Chao

int main()

{

double a[] = {1,2,2,3,1,1,4};

double b[] = {1,2,2,3,1,1,4};

int ja[] = {1,2,1,2,3,2,3};

// long long int ia[] = {1,3,6,7};

// long long int jb[] = {1,3,1,2,3,2,3};

// long long int ib[] = {1,3,6,7};

int ia[] = {1,3,6,8};

int jb[] = {1,2,1,2,3,2,3};

int ib[] = {1,3,6,8};

double* c = NULL;

// long long int* jc = NULL;

// long long int* ic = NULL;

int* jc = NULL;

int* ic = NULL;

//

MKL_INT m = 3;

MKL_INT n = 3;

MKL_INT k = 2;

double beta = 1.0;

char trans = 'N';

MKL_INT request = 1;

MKL_INT sort = 0;

MKL_INT nzmax = 0;

MKL_INT info;

//

//ic = new long long int[m+1];

ic = new int[m+1];

mkl_dcsradd(&trans, &request, &sort,

&m, &n,

a, ja, ia, β,

b, jb, ib, c,

jc, ic, &nzmax, &info);

//

c = new double[ic];

//jc = new long long int[ic];

jc = new int[ic];

//

request = 2;

mkl_dcsradd(&trans, &request, &sort,

&m, &n,

a, ja, ia, β,

b, jb, ib, c,

jc, ic, &nzmax, &info);

//

for(int z=0;z-1;z++)

std::cout << c << std::endl;

return 0;

}

Reply