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

mkl_dcsrcoo documentation: nnz is required input parameter?

bob_edwards
Beginner
388 Views
Hello,
I've noticed a few problems with the documentation of mkl_dcsrcoo, one of which took me a few hours to figure out. The parameter nnz is listed as an output parameter, but I have found that it's value must be set to the number of non-zero elements (the same value assigned to job(5)), or the result is a crash or undefined behavior.
Here is a quick test example in C++:
[cpp]#include "mkl_spblas.h"
#include "mkl_types.h"
#include 
using namespace std;

// test matrix A = [1 0]
//                 [0 1]
int main() {
    MKL_INT rowind[2] = {1,2},ia[2],ja[3],job[8] = {1,1,1,0,2,0,0,0};
    MKL_INT info, nnz,n=2;
    double Acoo[2] = {1.0,1.0}, Acsr[2];

    nnz = 0;    // set nnz to a nonsense value before the conversion
    mkl_dcsrcoo (job,&n, Acsr, ja, ia,&nnz,Acoo,rowind,rowind,&info);
    cout << "\n\nAfter passing nnz=0 to mkl_dcsrcoo" << endl;
    cout << "nnz: "  << nnz     << " info: " << info    << endl;
    cout << "ia: "   << ia[0]   << " "       << ia[1]   << endl;
    cout << "Acsr: " << Acsr[0] << " "       << Acsr[1] << endl;

    nnz = 2;   // set nnz to 2
    mkl_dcsrcoo (job,&n, Acsr, ja, ia,&nnz,Acoo,rowind,rowind,&info);

    cout << "\n\nAfter passing nnz=2 to mkl_dcsrcoo" << endl;
    cout << "nnz: "  << nnz     << " info: " << info    << endl;
    cout << "ia: "   << ia[0]   << " "       << ia[1]   << endl;
    cout << "Acsr: " << Acsr[0] << " "       << Acsr[1] << endl;
}
[/cpp]
Without the following output:
After passing nnz=0 to mkl_dcsrcoo
nnz: 0 info: 0
ia: 1 1
Acsr: 2.65259e-314 2.65259e-314

After passing nnz=2 to mkl_dcsrcoo
nnz: 2 info: 0
ia: 1 2
Acsr: 1 1
What I find alarming is that in both instances info = 0 indicating a successful conversion from COO to CSR.
There are other minor missing things in the documentation: mkl_dcsrcoo(job, &n, should be changed too mkl_dcsrcoo(job,&mto match the description, and then the description could be modified to

mINTEGER. Dimension of the matrixA.
m INTEGER. Number of columns of the matrix A
Cheers,

Bob
0 Kudos
2 Replies
Gennady_F_Intel
Moderator
388 Views
Bob,
we will take into account these comments

Yes, we should to explicitly point that nnz is the input parameter also.

Nevertheless, Looking at the input parameter description we can see..

rowind (input/output)INTEGER. Array of length nnz, contains the row indices for each non-zero element of the matrix A.

--Gennady

0 Kudos
pawanlri
Beginner
388 Views
Here is a general woking example for a rectangualr matrix
[bash]// This is a routine to check the mkl_csrcoo routine 
// for a rectangular matrix, there is a bug in the 
// mkl doc, which was pointed out. Here is the working example.
// Matrix is 
//  
//      1 0 2 0
// A =  0 0 3 0
//      5 0 7 8
//
// nnz = 6, m = 3, n = 4

#include 
#include "mkl_spblas.h"

int main(int argc, char *argv[] )
{
  double acoo[6] ={1., 2., 3., 5., 7., 8.};
  int rowind[6] = {1, 1, 2, 3, 3, 3};
  int colind[6] = {1, 3, 3, 1, 3, 4};
  int m=3, n=4, nnz=6;
  int job[8]={1,1,1,0,6,0,0,0};
  double acsr[6] = {1., 2., 3., 5., 7., 8.}; 
  int ia[4]; // m+1 
  int ja[6]; 
  int i, info;
  mkl_dcsrcoo(job, &m, acsr, ja, ia, &nnz, acoo, rowind, colind, &info);

  printf("n info = %d n ", info);
  printf("n--- csr matrix ---n");
  printf("n ia = ");
  for(i=0;i);
  printf("n ja = ");
  for(i=0;i);
  printf("n acsr = ");
  for(i=0;i);
  printf("n n");

  return 0;

}
[/bash]
Hopefully, this helps !
Cheers,
Pawan
0 Kudos
Reply