Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
6440 Discussions

mkl_sparse_?_update_values seems not to work

Meng__Xiangyi
Novice
141 Views

Hi,

I have constructed a sparse matrix in BSR format and try to use the function mkl_sparse_?_update_values to update some values, but it seems that the updated matrix doesn't change the value, dose anybody meet the  same problem as me?

0 Kudos
4 Replies
Meng__Xiangyi
Novice
141 Views

This is my test code 

program main

use mkl_spblas

use iso_c_binding

implicit none

type(SPARSE_MATRIX_T) A, B

type(MATRIX_DESCR) descA

integer :: indexing = SPARSE_INDEX_BASE_ONE

integer :: block_layout = SPARSE_LAYOUT_COLUMN_MAJOR

integer nrows, ncols, block_size, block_size2, nblocks

integer, allocatable :: row_ptr(:), col_indx(:)

real(8), allocatable :: values(:)

type(c_ptr) rows_start_c, rows_end_c, col_indx_c, values_c

integer, pointer :: rows_start_f(:), rows_end_f(:), col_indx_f(:)

real(8), pointer :: values_f(:)

integer stat, i, j

integer :: nvalues = 3, indx(3) = (/3, 5, 6/), indy(3) = (/3, 4, 6/)

real(8) :: values_(3) = (/2.d0, 2.d0, 2.d0/)

nrows = 3

ncols = 3

block_size = 2

block_size2 = block_size * block_size

nblocks = 5

allocate(row_ptr(nrows + 1))

allocate(col_indx(nblocks))

allocate(values(block_size2 * nblocks))

row_ptr = (/ 1, 3, 4, 6 /)

col_indx = (/ 1, 2, 2, 2, 3 /)

values = (/ 1.d0, 2.d0, 0.d0, 1.d0, 6.d0, 8.d0, 7.d0, 2.d0, 1.d0, 5.d0, 4.d0, 1.d0, 4.d0, 0.d0, 3.d0, 0.d0, 7.d0, 0.d0, 2.d0, 0.d0 /)

print *, '---------------------------------------------------'

do i = 1, nrows

print '(1x, a, i2, a)', '-------------block row #', i, '--------------'

do j = row_ptr(i), row_ptr(i + 1) - 1

print '(1x, a, i2)', 'block column #', col_indx(j)

print '(<block_size>f6.2)', transpose(reshape(values((j - 1) * block_size2 + 1 : j * block_size2), (/block_size, block_size/)))

end do

end do

print *, '---------------------------------------------------'

stat = mkl_sparse_d_create_bsr(A, indexing, block_layout, nrows, ncols, block_size, row_ptr, row_ptr(2), col_indx, values)



stat = mkl_sparse_d_update_values(A, nvalues, indx, indy, values_)

stat = mkl_sparse_d_export_bsr(A, indexing, block_layout, nrows, ncols, block_size, rows_start_c, rows_end_c, col_indx_c, values_c)

call c_f_pointer(rows_start_c, rows_start_f, [nrows])

call c_f_pointer(rows_end_c , rows_end_f , [nrows])

call c_f_pointer(col_indx_c , col_indx_f , [rows_end_f(nrows) - 1])

call c_f_pointer(values_c , values_f , [block_size2 * nblocks])

print *, '---------------------------------------------------'

do i = 1, nrows

print '(1x, a, i2, a)', '-------------block row #', i, '--------------'

do j = rows_start_f(i), rows_end_f(i) - 1

print '(1x, a, i2)', 'block column #', col_indx(j)

print '(<block_size>f6.2)', transpose(reshape(values_f((j - 1) * block_size2 + 1 : j * block_size2), (/block_size, block_size/)))

end do

end do

print *, '---------------------------------------------------'

end program main

 

 

and this is the output

 

---------------------------------------------------
 -------------block row # 1--------------
 block column # 1
  1.00  0.00
  2.00  1.00
 block column # 2
  6.00  7.00
  8.00  2.00
 -------------block row # 2--------------
 block column # 2
  1.00  4.00
  5.00  1.00
 -------------block row # 3--------------
 block column # 2
  4.00  3.00
  0.00  0.00
 block column # 3
  7.00  2.00
  0.00  0.00
 ---------------------------------------------------
 ---------------------------------------------------
 -------------block row # 1--------------
 block column # 1
  1.00  0.00
  2.00  1.00
 block column # 2
  6.00  7.00
  8.00  2.00
 -------------block row # 2--------------
 block column # 2
  1.00  4.00
  5.00  1.00
 -------------block row # 3--------------
 block column # 2
  4.00  3.00
  0.00  0.00
 block column # 3
  7.00  2.00
  0.00  0.00
 ---------------------------------------------------

MariaZh
Employee
141 Views

Hi,
Can you please check the returned status of the routine and provide a reproducer for your case?

Best regards,
Maria

Meng__Xiangyi
Novice
141 Views

Zhukova, Maria (Intel) wrote:

Hi,
Can you please check the returned status of the routine and provide a reproducer for your case?

Best regards,
Maria

Thank you for your reply, after calling 'stat = mkl_sparse_d_update_values(A, nvalues, indx, indy, values_)', the value of 'stat' is 6, which is associated with SPARSE_STATUS_NOT_SUPPORTED, is there anything wrong with my arguments?

And another question, when I want to update all the values in the matrix, how can I give the arguments? As all the arguments are not declared optional, how can I ignore 'indx' and 'indy' as Reference Developer said?

MariaZh
Employee
141 Views

Hi,
Updating the selected values of the matrix is not supported currently.
If you want to update the values of the full matrix, you just need to pass NULL for indx and indy.
Hope this helps!

Best regards,
Maria

Reply