<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re:Why is Intel MKL failing to solve this eigenproblem while SciPy has no problems in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1209061#M30071</link>
    <description>&lt;P&gt;This issue has been closed we will no longer respond to this thread.&amp;nbsp;If you require additional assistance from Intel, please start a new thread.&amp;nbsp;Any further interaction in this thread will be considered community only&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 14 Sep 2020 04:53:14 GMT</pubDate>
    <dc:creator>Gennady_F_Intel</dc:creator>
    <dc:date>2020-09-14T04:53:14Z</dc:date>
    <item>
      <title>Why is Intel MKL failing to solve this eigenproblem while SciPy has no problems</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1208698#M30064</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am trying to solve a generalized eigenvalue problem (I want both the eigenvalues and eigenvectors):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;[A]{x} = lambda[B]{x}&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Or equivalent (Finite Element Method):&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;[M]{x} = (1/w^2)[K]{x}&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Where&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;[M]=[A]&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;[K]=[B]&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(mass and stiffness matrices, respectively).&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In order to impose Dirichlet boundary conditions,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="math-container"&gt;&lt;SPAN class="MathJax" style="margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: normal; font-family: inherit; font-size: 15px; vertical-align: baseline; box-sizing: inherit; display: inline; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; position: relative;" data-mathml="&amp;lt;math xmlns=&amp;quot;http://www.w3.org/1998/Math/MathML&amp;quot;&amp;gt;&amp;lt;mo stretchy=&amp;quot;false&amp;quot;&amp;gt;[&amp;lt;/mo&amp;gt;&amp;lt;mi&amp;gt;M&amp;lt;/mi&amp;gt;&amp;lt;mo stretchy=&amp;quot;false&amp;quot;&amp;gt;]&amp;lt;/mo&amp;gt;&amp;lt;/math&amp;gt;"&gt;&lt;SPAN class="math"&gt;&lt;SPAN&gt;&lt;SPAN class="mrow"&gt;&lt;STRONG&gt;&lt;SPAN class="mo"&gt;[&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;M&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class="mo"&gt;&lt;STRONG&gt;]&lt;/STRONG&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;is singular in my case.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;I have both&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;[M]&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;[K]&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in plain text files. These matrices are stored in COO format, 0-based indexing, not sorted.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My files (&lt;/SPAN&gt;&lt;SPAN&gt;attached, or download from&amp;nbsp;&lt;A href="https://drive.google.com/file/d/1wzhGI5MB-QN5cqIMHnd9E5YYT2lv_ufM/view?usp=sharing" target="_self" rel="nofollow noreferrer"&gt;Google Drive&lt;/A&gt;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="none"&gt;kc: where K columns are stored
kr: where K rows are stored
kv: where K values are stored
mc, mr, mv: analogous to K, but for the M matrix&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Using the data from the files, I can solve the problem with SciPy (Python). Since this is a FEA problem, I've also solved it in Abaqus CAE, so I know for a fact that both eigenvalues and eigenvectors are correctly calculated in SciPy:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="none"&gt;MODE    ABAQUS (w^2)    SciPy (w^2)
1       +6.07235E+06    +6.50440E+06
2       +2.28087E+08    +2.44463E+08
3       +1.67357E+09    +1.79572E+09
4       +3.36973E+09    +3.37316E+09
5       +5.88655E+09    +6.32761E+09
(1/lambda = w^2)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My Python code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from scipy.sparse import coo_matrix
from scipy.sparse.linalg import eigs
from numpy import real

rows = 610
cols = 610
a_nnz = 4628
b_nnz = 9266

# read a
with open('./coo/mr') as f: a_row_indx = [int(i) for i in f]
with open('./coo/mc') as f: a_col_indx = [int(i) for i in f]
with open('./coo/mv') as f: a_val_indx = [float(i) for i in f]

# read b
with open('./coo/kr') as f: b_row_indx = [int(i) for i in f]
with open('./coo/kc') as f: b_col_indx = [int(i) for i in f]
with open('./coo/kv') as f: b_val_indx = [float(i) for i in f]

a = coo_matrix((a_val_indx, (a_row_indx, a_col_indx)), shape=(rows, cols))
b = coo_matrix((b_val_indx, (b_row_indx, b_col_indx)), shape=(rows, cols))

eigenvalues, eigenvectors = eigs(A=a, M=b, k=10)

val = real(eigenvalues) # to remove "+0j", eigenvalues are real
v = 1.0/val&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My question is, why is Intel MKL failing to solve this problem? I've tried tinkering with the code, but I always get errors or exceptions:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;pm(3) = 1 ! -&amp;gt; Exception thrown at 0x00007FFCE77556EC (mkl_core.dll) in Console1.exe: 0xC0000005: Access violation accessing location 0x0000000000000000.
pm(3) = 2 ! -&amp;gt; STAT = 2 SPARSE_STATUS_ALLOC_FAILED&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My Fortran code (Visual Studio):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;include 'mkl_solvers_ee'
include 'mkl_spblas'

program main

	use mkl_solvers_ee
	use mkl_spblas
	use, intrinsic :: iso_c_binding , only : c_int, c_double
	
	implicit none
	
	type(sparse_matrix_t) :: a
	type(sparse_matrix_t) :: b
	integer(c_int), parameter :: rows = 610
	integer(c_int), parameter :: cols = 610
	integer(c_int), parameter :: a_nnz = 4628
	integer(c_int), parameter :: b_nnz = 9266
	integer(c_int) :: a_row_indx(a_nnz)
	integer(c_int) :: a_col_indx(a_nnz)
	real(c_double) :: a_values(a_nnz)
	integer(c_int) :: b_row_indx(b_nnz)
	integer(c_int) :: b_col_indx(b_nnz)
	real(c_double) :: b_values(b_nnz)
	integer :: stat
	
	character, parameter :: which = 'S'
	integer(c_int) :: pm(128)
	type(matrix_descr), parameter :: descra = matrix_descr(type = sparse_matrix_type_general, mode = sparse_fill_mode_upper, diag = sparse_diag_non_unit)
	type(matrix_descr), parameter :: descrb = matrix_descr(type = sparse_matrix_type_general, mode = sparse_fill_mode_upper, diag = sparse_diag_non_unit)
	integer(c_int), parameter :: k0 = 10
	integer(c_int) :: k
	real(c_double) :: e(k0), ee(k0)
	real(c_double) :: x(k0, cols)
	real(c_double) :: res(k0)
	
	type(sparse_matrix_t) :: acsr
	type(sparse_matrix_t) :: bcsr
	
	integer :: i
	
	! read a
	open(unit=1, file="./coo/mr")
	open(unit=2, file="./coo/mc")
	open(unit=3, file="./coo/mv")
	do i = 1, a_nnz
		read(1, *) a_row_indx(i)
		read(2, *) a_col_indx(i)
		read(3, *) a_values(i)
	end do
	close(unit=1)
	close(unit=2)
	close(unit=3)
	
	! read b
	open(unit=1, file="./coo/kr")
	open(unit=2, file="./coo/kc")
	open(unit=3, file="./coo/kv")
	do i = 1, b_nnz
		read(1, *) b_row_indx(i)
		read(2, *) b_col_indx(i)
		read(3, *) b_values(i)
	end do
	close(unit=1)
	close(unit=2)
	close(unit=3)
	
	a_row_indx(:) = a_row_indx(:) + 1
	a_col_indx(:) = a_col_indx(:) + 1

	b_row_indx(:) = b_row_indx(:) + 1
	b_col_indx(:) = b_col_indx(:) + 1
	
	stat = mkl_sparse_d_create_coo(a, sparse_index_base_one, rows, cols, a_nnz, a_row_indx, a_col_indx, a_values)
	stat = mkl_sparse_d_create_coo(b, sparse_index_base_one, rows, cols, b_nnz, b_row_indx, b_col_indx, b_values)
	stat = mkl_sparse_convert_csr(a, sparse_operation_non_transpose, acsr)
	stat = mkl_sparse_convert_csr(b, sparse_operation_non_transpose, bcsr)
	stat = mkl_sparse_ee_init(pm)
	
	!pm(1) = 0
	!pm(2) = 6
	!pm(3) = 2
	!pm(4) = 512
	!pm(5) = 60 ! 10000 
	!pm(6) = 512
	!pm(7) = 0
	!pm(8) = 0
	!pm(9) = 0
	
	!pm(3) = 1 ! -&amp;gt; Exception thrown at 0x00007FFCE77556EC (mkl_core.dll) in Console1.exe: 0xC0000005: Access violation accessing location 0x0000000000000000.
	!pm(3) = 2 ! -&amp;gt; STAT = 2 SPARSE_STATUS_ALLOC_FAILED
	
	stat = mkl_sparse_d_gv(which, pm, acsr, descra, bcsr, descrb, k0, k, e, x, res)
	
	ee(:) = 1.0 / e(:)
	
end program main
	
!	0	SPARSE_STATUS_SUCCESS			The operation was successful.
!	1	SPARSE_STATUS_NOT_INITIALIZED	The routine encountered an empty handle or matrix array.
!	2	SPARSE_STATUS_ALLOC_FAILED		Internal memory allocation failed.
!	3	SPARSE_STATUS_INVALID_VALUE		The input parameters contain an invalid value.
!	4	SPARSE_STATUS_EXECUTION_FAILED	Execution failed.
!	5	SPARSE_STATUS_INTERNAL_ERROR	An error in algorithm implementation occurred.
!	6	SPARSE_STATUS_NOT_SUPPORTED		The requested operation is not supported.&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have wasted all day looking at this code and I can't tell what I am doing wrong. Any help is greatly appreciated.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;EDIT&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code correction:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;character, parameter :: which = 'L'&lt;/LI-CODE&gt;
&lt;P&gt;Since I want the lowest w^2, i.e, the largest eigenvalues (lambda = 1/w^2).&lt;/P&gt;
&lt;LI-CODE lang="fortran"&gt;pm(3) = 1 ! -&amp;gt; Exception thrown at 0x00007FFCE77556EC (mkl_core.dll) in Console1.exe: 0xC0000005: Access violation accessing location 0x0000000000000000.
pm(3) = 2 ! -&amp;gt; Stack trace terminated abnormally. forrtl: severe (157): Message not found - Unhandled exception at 0x00007FF92E64ED79 (ntdll.dll) in Console1.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FF92E6B77F0).

	&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 11 Sep 2020 15:10:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1208698#M30064</guid>
      <dc:creator>csouto</dc:creator>
      <dc:date>2020-09-11T15:10:12Z</dc:date>
    </item>
    <item>
      <title>Re:Why is Intel MKL failing to solve this eigenproblem while SciPy has no problems</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1209060#M30070</link>
      <description>&lt;P&gt;here is a duplicated thread.&lt;/P&gt;&lt;P&gt;please check the same one: &lt;A href="https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1208958#M30068" target="_blank"&gt;https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1208958#M30068&lt;/A&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 14 Sep 2020 04:52:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1209060#M30070</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2020-09-14T04:52:17Z</dc:date>
    </item>
    <item>
      <title>Re:Why is Intel MKL failing to solve this eigenproblem while SciPy has no problems</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1209061#M30071</link>
      <description>&lt;P&gt;This issue has been closed we will no longer respond to this thread.&amp;nbsp;If you require additional assistance from Intel, please start a new thread.&amp;nbsp;Any further interaction in this thread will be considered community only&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 14 Sep 2020 04:53:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Why-is-Intel-MKL-failing-to-solve-this-eigenproblem-while-SciPy/m-p/1209061#M30071</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2020-09-14T04:53:14Z</dc:date>
    </item>
  </channel>
</rss>

