<?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: differences between c standard library and MKL in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855160#M6923</link>
    <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
&lt;P&gt;Hagai has not yet explained what is wanted. A careful implementation of tanhl() should work to 20 significant digits, if that is what is wanted. Current icc includes the -fp:extended switch to request intermediate long double precision, but that would go only part way. With Microsoft compilers and that version of "the C standard library," there is no support for long double as a distinct data type. There may exist implementations where tanh() and tanhl() share a careful long double implementation, but Hagai has given no indication which library this is. The MKL functions under discussion clearly are limited to double, with no possibility of extended accuracy.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Nov 2008 13:38:27 GMT</pubDate>
    <dc:creator>TimP</dc:creator>
    <dc:date>2008-11-05T13:38:27Z</dc:date>
    <item>
      <title>differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855153#M6916</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have some differences between the c standard library and mkl when using vdTanh and tanh.&lt;/P&gt;
&lt;P&gt;
&lt;PRE&gt;[cpp]double val = 0.020630512405774085;
double e1 = tanh(val);
double e2;

vdTanh(1, &amp;amp;val, &amp;amp;e2);[/cpp]&lt;/PRE&gt;
&lt;/P&gt;
&lt;P&gt;The results are different in the last 2 digits of the double. Any ideas why this happens?&lt;/P&gt;
&lt;P&gt;I am trying to compare some code which was written without MKL to a code with MKL. Should I have such differences?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Hagai.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Nov 2008 12:19:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855153#M6916</guid>
      <dc:creator>hagai</dc:creator>
      <dc:date>2008-11-02T12:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855154#M6917</link>
      <description>&lt;P&gt;Make sure you are aligning the first value of your arrays (or, in this case your variable) to the 16-byte boundary to guarantee accuracy. See the section marked Aligning Data for Numerical Stability in the Users Guide for more details.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Newton&lt;BR /&gt;--------&lt;/P&gt;</description>
      <pubDate>Sun, 02 Nov 2008 18:20:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855154#M6917</guid>
      <dc:creator>newton_particle</dc:creator>
      <dc:date>2008-11-02T18:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855155#M6918</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - Hagai.&lt;A href="https://community.intel.com/en-us/profile/406441"&gt;&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;
&lt;DIV class="dp-highlighter"&gt;&lt;OL class="dp-cpp"&gt;
&lt;LI class="alt"&gt;&lt;SPAN&gt;&lt;SPAN class="datatypes"&gt;double&lt;/SPAN&gt;&lt;SPAN&gt; val=0.020630512405774085; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN class="datatypes"&gt;double&lt;/SPAN&gt;&lt;SPAN&gt; e1=tanh(val); &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class="alt"&gt;&lt;SPAN&gt;&lt;SPAN class="datatypes"&gt;double&lt;/SPAN&gt;&lt;SPAN&gt; e2; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class="alt"&gt;&lt;SPAN&gt;vdTanh(1,&amp;amp;val,&amp;amp;e2); &lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;FYI: the precise answer to the above is: 0.02062758600 // I ran it through Maple and Google and got the same answer.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Newton&lt;BR /&gt;--------&lt;/P&gt;
&lt;P&gt;(Q) Is there not an edit post button on this forum?? or am I going blind?? :o&lt;/P&gt;</description>
      <pubDate>Sun, 02 Nov 2008 18:33:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855155#M6918</guid>
      <dc:creator>newton_particle</dc:creator>
      <dc:date>2008-11-02T18:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855156#M6919</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;The Edit button was turned on for many of us, with a general correction of permissions last week. If you still don't see it, you might ask the forum administrators.&lt;/P&gt;
&lt;P&gt;With the regard to the difference you quote, MKL math functions would not be using extended precision, so a relative difference on the order of DBL_EPSILON would be expected. Asking for more digits in printf() doesn't influence the compiler in its choice of math functions. You can make as many "last digits" wrong as you choose, within the limitations of your printf() library, by choosing to display more digits.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Nov 2008 20:50:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855156#M6919</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2008-11-02T20:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855157#M6920</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/367365"&gt;tim18&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;With the regard to the difference you quote, MKL math functions would not be using extended precision, so a relative difference on the order of DBL_EPSILON would be expected.&lt;EM&gt; &lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;I often find that there is a variation on the last 2 digits relate to an either/or combination of processor type, and alignment issues. Both of which can cause the issue Hagai is describing. For example, the box Im currently using hosts an Athlon 64 FX-## processor which also presents the issue described.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The output I pasted above was produced using Maple to 100dp, so it is actually a precise value in Hagai's example. It's a useful check as it is calculated with an arbitrary length floating point simulation that gets around these issues (at a cost of speed). But yes, your point about console output rounding is a good note.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The issue from alignment (or other) error is worth identifyin, especially in iteration scenarios, where the error can be compounded. In financial applications, for example, this is a 'very' serious issue.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Newton&lt;BR /&gt;--------&lt;/P&gt;</description>
      <pubDate>Sun, 02 Nov 2008 21:14:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855157#M6920</guid>
      <dc:creator>newton_particle</dc:creator>
      <dc:date>2008-11-02T21:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855158#M6921</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;Thanks for your responses. I tried using aligned values but that didn't change the result. I am not using printf or any other kind of output printing, I just watch the result in the debugger.&lt;/P&gt;
&lt;P&gt;Could it just be that MKL and the standard library use different precision?&lt;/P&gt;
&lt;P&gt;This is the new code:&lt;/P&gt;
&lt;P&gt;
&lt;PRE&gt;[cpp]	double* pval = reinterpret_cast&lt;DOUBLE&gt;(MKL_malloc(sizeof(double), 16 ));
	double* pe1 = reinterpret_cast&lt;DOUBLE&gt;(MKL_malloc(sizeof(double), 16 ));
	double* pe2 = reinterpret_cast&lt;DOUBLE&gt;(MKL_malloc(sizeof(double), 16 ));
	*pval = 0.020630512405774085;
	*pe1 = tanh(*pval);
	vdTanh(1, pval, pe2);
	
	bool ret = *pe1 == *pe2;
	MKL_free(pval);
	MKL_free(pe1);
	MKL_free(pe2);
	return ret;
[/cpp]&lt;/DOUBLE&gt;&lt;/DOUBLE&gt;&lt;/DOUBLE&gt;&lt;/PRE&gt;
&lt;/P&gt;
&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2008 10:01:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855158#M6921</guid>
      <dc:creator>hagai</dc:creator>
      <dc:date>2008-11-05T10:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855159#M6922</link>
      <description>&lt;P&gt;Hi Hagai,&lt;BR /&gt;&lt;BR /&gt;I was only half paying attention in my previous posts. In your tests you are calling vector math functions. If you check in the Reference Manual for the section on VML Service Functions, you will see that there are 3 levels of accuracy available, via the SetMode() function:&lt;BR /&gt;&lt;BR /&gt;VML_HA -&amp;gt; High accuracy versions of VML functions will be used.&lt;BR /&gt;VML_LA -&amp;gt; Low accuracy versions of VML functions will be used.&lt;BR /&gt;VML_EP -&amp;gt; Enhanced Performance accuracy versions of VML functions will be used.&lt;BR /&gt;&lt;BR /&gt;The other factors, previously mentioned, can also play a part (CPU + Alignment). Beyond that, it is highly unlikely you will get a match by testing for equality as floating point numbers cannot reliably be compared for exact equality ( &lt;A href="http://teaching.idallen.com/cst8110/97s/floating_point.html" target="_blank"&gt;http://teaching.idallen.com/cst8110/97s/floating_point.html&lt;/A&gt; ).&lt;BR /&gt;&lt;BR /&gt;An example of where this problem frequently comes up is testing Asserts in tools like NUnit. To deal with this problem you must specify a tolerance for floating point comparisons; using: GlobalSettings.DefaultFloatingPointTolerance&lt;BR /&gt;&lt;BR /&gt;As floating point values are only approximations of real numbers, you can never universally achieve true precision; only a value that is for all practical purposes good enough.&lt;BR /&gt;&lt;BR /&gt;*If* you have a particular scientific/mathematical need for arbitrary levels of floating point precision, that are far beyond that of 32/64-bit precision, then your only real option is to use more specialized libraries, such as: the GMP MP Bignum Library ( &lt;A href="http://gmplib.org/" target="_blank"&gt;http://gmplib.org/&lt;/A&gt; ); or the MPFR library ( &lt;A href="http://www.mpfr.org/" target="_blank"&gt;http://www.mpfr.org/&lt;/A&gt; ).&lt;BR /&gt;&lt;BR /&gt;Can I ask why float precision is so important to you?&lt;BR /&gt;&lt;BR /&gt;Newton&lt;BR /&gt;--------&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2008 13:03:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855159#M6922</guid>
      <dc:creator>newton_particle</dc:creator>
      <dc:date>2008-11-05T13:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855160#M6923</link>
      <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
&lt;P&gt;Hagai has not yet explained what is wanted. A careful implementation of tanhl() should work to 20 significant digits, if that is what is wanted. Current icc includes the -fp:extended switch to request intermediate long double precision, but that would go only part way. With Microsoft compilers and that version of "the C standard library," there is no support for long double as a distinct data type. There may exist implementations where tanh() and tanhl() share a careful long double implementation, but Hagai has given no indication which library this is. The MKL functions under discussion clearly are limited to double, with no possibility of extended accuracy.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2008 13:38:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855160#M6923</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2008-11-05T13:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855161#M6924</link>
      <description>&lt;DIV style="margin:0px;"&gt;Hello. Different math libraries can give different results. But two different libraries give the same result more often if they have upper error bound more tight (for example MUER, maximum ulp error requirement). For example Intel Compilers LIBM MUER is about 0.55 ulp for most functions. VML HA functions MUER is 0.55-1.0 ulp, VML LA functions MUER is 4.0 ulp.&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Nov 2008 13:55:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855161#M6924</guid>
      <dc:creator>Eugeny_G_Intel</dc:creator>
      <dc:date>2008-11-05T13:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: differences between c standard library and MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855162#M6925</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Precision is important to me because I want to compare my results to someone else's code, which uses the standard library rather than MKL. I worked around this by dividing the difference by the value, but it's not good enough.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2008 14:48:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/differences-between-c-standard-library-and-MKL/m-p/855162#M6925</guid>
      <dc:creator>hagai</dc:creator>
      <dc:date>2008-11-05T14:48:41Z</dc:date>
    </item>
  </channel>
</rss>

