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

Conversion to sparse matrix: wrong behavior of mkl_zdnscsr

Massimiliano_Culpo
222 Views
Hi,

I am trying to convert a complex(8) dense matrix into csr sparse format using MKL specific routines. Anyhow, I encountered a problem I was able to isolate in the code attached below:

[fortran]program dns2csr

  complex(8),      allocatable :: Aall(:,:)
  integer,         allocatable :: ia  (:)
  integer,         allocatable :: ja  (:)
  complex(8),      allocatable :: zval(:)
  real(8),         allocatable :: dval(:)
  ! Variables needed by MKL
  integer                      :: job(1:8)
  integer                      :: info
  
  integer,           parameter :: nrow = 3
  integer,           parameter :: ncol = 3
  
  ! Allocate workspace
  allocate(Aall(1:3,1:3))
  allocate(ia (1:nrow+1))
  ! Initialize dns matrix
  Aall      = cmplx(0.0d0,0.0d0)
  Aall(1,1) = cmplx(1.0d0,0.0d0)
  Aall(3,1) = cmplx(5.0d0,0.0d0)
  Aall(2,2) = cmplx(4.0d0,0.0d0)
  Aall(3,2) = cmplx(0.0d0,4.0d0)
  Aall(1,3) = cmplx(3.0d0,0.0d0)

  ! Set job
  job(1) = 0 ! Convert from dense to CSR format
  job(2) = 1 ! One-based indexing for dense
  job(3) = 1 ! One-based indexing for CSR
  job(4) = 2 ! Pass the whole dense matrix to MKL routines 
  
  ! Compute ia only
  job(5) = 0 ! Max number of nnz
  job(6) = 0 ! Construct ia only
  allocate(ja(1),zval(1),dval(1))
  call mkl_zdnscsr(job,nrow,ncol,Aall,nrow,zval,ja,ia,info)
  print *,ia
  print *,info
  call mkl_ddnscsr(job,nrow,ncol,real(Aall),nrow,dval,ja,ia,info)
  print *,ia
  print *,info

  deallocate(ia,ja,dval,zval)
  deallocate(Aall)

end program dns2csr[/fortran]
I compile this program with the command:
[bash]ifort -O0 -warn all dns2csr.f90 -lmkl_intel -lmkl_sequential  -lmkl_core[/bash]
Then running a.out I get the following output:
[bash]$ ./a.out 
           1           1           1           1
           0
           1           3           4           5
           3
[/bash]
While the correct one should have been:
[bash]$ ./a.out 
           1           3           4           6
           3
           1           3           4           5
           3
[/bash]
It seems that conversion from dense format to csr format works properly only with real(8) type. I wonder if the routine mkl_zdnscsr is somehow buggy or if I am doing some trivial error I am not able to spot. Is anyone able to reproduce the same behavior?

M.
0 Kudos
1 Solution
Murat_G_Intel
Employee
222 Views
Hi Massimiliano,

Thank you for reporting this issue. The subroutine works correctly if you set both imaginary and real parts of a complex number to non-zero. It seems like the component that checks whether an entry is nonzero or not is in error. We will fix this as soon as possible.

-- Efe

View solution in original post

8 Replies
barragan_villanueva_
Valued Contributor I
222 Views
Hi,

According to MKL Reference Manual

mkl_?dnscsr

Convert a sparse matrix in dense representation to the CSR format and vice versa.


but

COMPLEX for mkl_cdnscsr
DOUBLE COMPLEX for mkl_zdnscsr

INTERFACE is as follows:

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

  INTEGER       job(8)
  INTEGER       m, n, lda, info
  INTEGER      ja(*), ia(m+1)
  DOUBLE COMPLEX      adns(*), acsr(*)


However, in your example complex(8) and real(8)are used for mkl_zdnscsr function.

Massimiliano_Culpo
222 Views
Hi Victor,

and many thanks for your reply!

Nonetheless I think you misunderstood my post a little. I used complex(8) (syntax equivalent to a complex*16 declaration, at least on my machine) in the calling mkl_zdnscsr, while real(8) (syntax equivalent to a real*8 declaration, at least on my machine) was used in the calling to mkl_ddnscsr.

My point was to say that the same piece of code works if I am using double precision matrix, while it is not if I am using double complex matrix. Of course when I work with complex(8)/real(8) I call the z/d version of mkl_Xdnscsr.

Any suggestion on what to do? Are you able to reproduce this problem?

Many thanks again,
Massimiliano
Gennady_F_Intel
Moderator
222 Views
Massimiliano,
yes, it looks like the bug. Please let us the time we will investigate and back to you shortly.
--Gennady
Murat_G_Intel
Employee
223 Views
Hi Massimiliano,

Thank you for reporting this issue. The subroutine works correctly if you set both imaginary and real parts of a complex number to non-zero. It seems like the component that checks whether an entry is nonzero or not is in error. We will fix this as soon as possible.

-- Efe
Massimiliano_Culpo
222 Views
Hi,

many thanks for the quick response! I'll look forward to the fixed version (and will use other means to convert the complex matrix in the meanwhile :-) )

Massimiliano
Gennady_F_Intel
Moderator
222 Views

HiMassimiliano, thanks for the problem you raised.This issue has been submitted to our internal development tracking database for further investigation, we will inform you once a new update becomes available.

Here is a bug tracking number for your reference: 200209064.

Gennady_F_Intel
Moderator
222 Views
Massimiliano,
could you please check how it works with the latest 10.3 update 4 which was released yesterday and let us know if you will see the same behavior?
--Gennady
Massimiliano_Culpo
222 Views
I have just tried MKL 10.3 Update 4.

The output now is:

[bash]1           3           4           6
0
1           3           4           5
0
[/bash]
which I think is fine. Many thanks for updating me on the issue!

Massimiliano
Reply