<?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 Jim, in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975663#M17059</link>
    <description>Jim,

The coefficients of the matrix are all of the form (a + b/sqrt(2)) X 10&lt;SUP&gt;9&lt;/SUP&gt;, where a and b are small integers (plus or minus 0, 1, 2, 4). The M-V product should give 2 X 10&lt;SUP&gt;9&lt;/SUP&gt; in rows 1 and 3, and zero in the rest of the rows. Relative to the non-zero coefficients, a sum such as 2 X 10&lt;SUP&gt;-6&lt;/SUP&gt; is about the same as 1 is relative to machine-epsilon. 
 
The non-zero values that the OP obtained will be sensitive to the order of evaluation. Compared to the exact value (zero), the values given by MKL and Matlab are equally bad (or good, depending on the point of view).

The values in the file values.txt are not all given to the full number of digits that double precision permits. Correcting them caused the output KX(4:8) to become exactly zero, leaving KX(2) as the only number that is small instead of being identically zero.</description>
    <pubDate>Tue, 18 Dec 2012 20:18:00 GMT</pubDate>
    <dc:creator>mecej4</dc:creator>
    <dc:date>2012-12-18T20:18:00Z</dc:date>
    <item>
      <title>an accuracy problem between MKL and MATLAB</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975660#M17056</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;rencently,I have run a program &amp;nbsp;using Intel MKL sparse format and MATLAB respectively.I find an accuracy problem in my result. Let me briefly summarize what I did.&lt;/P&gt;
&lt;P&gt;At first,I use the MKL libary to compute K*X=KX ,as follows:&lt;/P&gt;
&lt;P&gt;the full format symmetric matrix K converts to the sparse format CSC (COPPTR,ROWIND,VALUES or&amp;nbsp;ROWIND,VALUES,pointer_B,pointer_E)&lt;/P&gt;
&lt;P&gt;program exe101&lt;BR /&gt;implicit none&lt;BR /&gt;integer::i,j&lt;BR /&gt;integer,parameter::DP=8&lt;BR /&gt;integer::nRows,nNonzero&lt;BR /&gt;integer,allocatable::COPPTR(:),ROWIND(:),pointer_B(:),pointer_E(:)&lt;BR /&gt;real(kind=DP),allocatable::VALUES(:)&lt;BR /&gt;real(kind=DP),allocatable::X(:),KX(:)&lt;BR /&gt;real(kind=DP)::alpha,beta&lt;BR /&gt;character(6):: matdescra&lt;/P&gt;
&lt;P&gt;open(unit=10,file='nRows.txt')&lt;BR /&gt;read(10,*)nRows&lt;BR /&gt;close(10,status="keep")&lt;/P&gt;
&lt;P&gt;open(unit=10,file='nNonzero.txt')&lt;BR /&gt;read(10,*)nNonzero&lt;BR /&gt;close(10,status="keep")&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;allocate(COPPTR(nRows+1))&lt;BR /&gt;open(unit=10,file='COPPTR.txt')&lt;BR /&gt;read(10,*)COPPTR&lt;BR /&gt;close(10,status="keep")&lt;/P&gt;
&lt;P&gt;allocate(ROWIND(nNonzero))&lt;BR /&gt;open(unit=10,file='ROWIND.txt')&lt;BR /&gt;read(10,*)ROWIND&lt;BR /&gt;close(10,status="keep")&lt;/P&gt;
&lt;P&gt;allocate(VALUES(nNonzero))&lt;BR /&gt;open(unit=10,file='VALUES.txt')&lt;BR /&gt;read(10,*)VALUES&lt;BR /&gt;close(10,status="keep")&lt;/P&gt;
&lt;P&gt;allocate(X(nRows))&lt;BR /&gt;allocate(KX(nRows))&lt;BR /&gt;X=1.0&lt;/P&gt;
&lt;P&gt;alpha=1.0&lt;BR /&gt;beta=0.0&lt;BR /&gt;matdescra='SLNF'&lt;/P&gt;
&lt;P&gt;allocate(pointer_B(nRows))&lt;BR /&gt;allocate(pointer_E(nRows))&lt;/P&gt;
&lt;P&gt;do i=1,nRows&lt;BR /&gt; pointer_B(i)=COPPTR(i)&lt;BR /&gt; pointer_E(i)=COPPTR(i+1)&lt;BR /&gt;end do&lt;/P&gt;
&lt;P&gt;call mkl_dcscmv('N', nRows, nRows, alpha, matdescra, VALUES, ROWIND, pointer_B, pointer_E,X, beta, KX)&lt;/P&gt;
&lt;P&gt;open(unit=10,file='KX.txt')&lt;BR /&gt;write(10,'(1X,1f40.21)')KX&lt;BR /&gt;end&lt;/P&gt;
&lt;P&gt;output::&lt;/P&gt;
&lt;P&gt;KX=&lt;/P&gt;
&lt;P&gt;1999999999.999993562698364257812&lt;BR /&gt; -0.000006198883056640625&lt;BR /&gt; 2000000000.000000000000000000000&lt;BR /&gt; 0.000000000000000000000&lt;BR /&gt; 0.000000000000000000000&lt;BR /&gt; 0.000000000000000000000&lt;BR /&gt; 0.000002384185791015625&lt;BR /&gt; 0.000001907348632812500&lt;/P&gt;
&lt;P&gt;Secondly,I use MATLAB to&amp;nbsp;compute K*X=KX&lt;/P&gt;
&lt;P&gt;output::&lt;/P&gt;
&lt;P&gt;1999999999.99999&lt;BR /&gt; -6.19888305664063e-06&lt;BR /&gt; 2000000000.00000&lt;BR /&gt; 0&lt;BR /&gt; 0&lt;BR /&gt; 0&lt;BR /&gt; 2.14576721191406e-06&lt;BR /&gt; 1.90734863281250e-06&lt;/P&gt;
&lt;P&gt;where&lt;/P&gt;
&lt;P&gt;input::&lt;BR /&gt;K=&lt;/P&gt;
&lt;P&gt;5.414213562373090e+009 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 -2.000000000000000e+009 0.000000000000000e+000 -7.071067811865480e+008 -7.071067811865480e+008&lt;/P&gt;
&lt;P&gt;0.000000000000000e+000 3.414213562373090e+009 0.000000000000000e+000 -2.000000000000000e+009 0.000000000000000e+000 0.000000000000000e+000 -7.071067811865480e+008 -7.071067811865480e+008&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;0.000000000000000e+000 0.000000000000000e+000 4.000000000000000e+009 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 -2.000000000000000e+009 0.000000000000000e+000&lt;/P&gt;
&lt;P&gt;0.000000000000000e+000 -2.000000000000000e+009 0.000000000000000e+000 2.000000000000000e+009 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000&lt;/P&gt;
&lt;P&gt;-2.000000000000000e+009 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 2.000000000000000e+009 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000&lt;/P&gt;
&lt;P&gt;0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 2.000000000000000e+009 0.000000000000000e+000 -2.000000000000000e+009&lt;/P&gt;
&lt;P&gt;-7.071067811865480e+008 -7.071067811865480e+008 -2.000000000000000e+009 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 2.707106781186550e+009 7.071067811865480e+008&lt;/P&gt;
&lt;P&gt;-7.071067811865480e+008 -7.071067811865480e+008 0.000000000000000e+000 0.000000000000000e+000 0.000000000000000e+000 -2.000000000000000e+009 7.071067811865480e+008 2.707106781186550e+009&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;X=&lt;BR /&gt;1.0&lt;BR /&gt;1.0&lt;BR /&gt;1.0&lt;BR /&gt;1.0&lt;BR /&gt;1.0&lt;BR /&gt;1.0&lt;BR /&gt;1.0&lt;BR /&gt;1.0&lt;/P&gt;
&lt;P&gt;I want to know why &amp;nbsp;two results are different &amp;nbsp;and how&amp;nbsp;&amp;nbsp;to improve the accuracy of sparse(dense) matrix- vector.&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2012 12:13:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975660#M17056</guid>
      <dc:creator>shaopeng_z_</dc:creator>
      <dc:date>2012-12-18T12:13:51Z</dc:date>
    </item>
    <item>
      <title>Such small discrepancies are</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975661#M17057</link>
      <description>Such small discrepancies are to be expected, given that the result has some elements of the order of 2 billion, and some elements of the order of a millionth. That ratio of the two is about the same as that of 1.0 to machine epsilon in double precision, and we know well that the subtractive cancellation (that happens when the matrix-vector product is computed) leads to precision loss.</description>
      <pubDate>Tue, 18 Dec 2012 13:36:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975661#M17057</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2012-12-18T13:36:02Z</dc:date>
    </item>
    <item>
      <title>mecej4, why then does the 7th</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975662#M17058</link>
      <description>mecej4, why then does the 7th entry vary by a much larger factor?
(was this a type-o by the OP?)

Jim Dempsey</description>
      <pubDate>Tue, 18 Dec 2012 15:39:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975662#M17058</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2012-12-18T15:39:15Z</dc:date>
    </item>
    <item>
      <title>Jim,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975663#M17059</link>
      <description>Jim,

The coefficients of the matrix are all of the form (a + b/sqrt(2)) X 10&lt;SUP&gt;9&lt;/SUP&gt;, where a and b are small integers (plus or minus 0, 1, 2, 4). The M-V product should give 2 X 10&lt;SUP&gt;9&lt;/SUP&gt; in rows 1 and 3, and zero in the rest of the rows. Relative to the non-zero coefficients, a sum such as 2 X 10&lt;SUP&gt;-6&lt;/SUP&gt; is about the same as 1 is relative to machine-epsilon. 
 
The non-zero values that the OP obtained will be sensitive to the order of evaluation. Compared to the exact value (zero), the values given by MKL and Matlab are equally bad (or good, depending on the point of view).

The values in the file values.txt are not all given to the full number of digits that double precision permits. Correcting them caused the output KX(4:8) to become exactly zero, leaving KX(2) as the only number that is small instead of being identically zero.</description>
      <pubDate>Tue, 18 Dec 2012 20:18:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975663#M17059</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2012-12-18T20:18:00Z</dc:date>
    </item>
    <item>
      <title>Given that:</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975664#M17060</link>
      <description>Given that:
 kx(i) = K(i,:) * x(:)
.
You could define vectors kx_16 and x_16 as real*16 and accumulate kx_16, for all available values of K(i,j). You would not need to store K, but merely obtain all non-zero values and accumulate their effect.
You could then compare the error of kx_matlab and kx_mkl from kx_16 and report the sum of the absolute diference.
.
This would show which one is worse.
As you would probably calculate this in a Fortran environment, you would need to be careful to extract kx_matlab to the precision available.
You need to be careful to identify possible sources of error in the comparison and when obtaining values of K.
The results might be an interesting study.

John</description>
      <pubDate>Wed, 19 Dec 2012 07:31:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975664#M17060</guid>
      <dc:creator>John_Campbell</dc:creator>
      <dc:date>2012-12-19T07:31:20Z</dc:date>
    </item>
    <item>
      <title>I suppose that catastrophic</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975665#M17061</link>
      <description>I suppose that catastrophic cancellation could be blamed for slightly inaccurate results.It mainly occurres when two very close values in precision(nearly equal) are subtracted or added with different signs.
Moreover the exact implementation of an algorithms as beign used by Matlab and MKL can also be different thus leading to miniscule variation in the
final result.</description>
      <pubDate>Mon, 24 Dec 2012 06:29:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/an-accuracy-problem-between-MKL-and-MATLAB/m-p/975665#M17061</guid>
      <dc:creator>Bernard</dc:creator>
      <dc:date>2012-12-24T06:29:26Z</dc:date>
    </item>
  </channel>
</rss>

