<?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 Does &amp;quot;Sometimes it doesn't in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074970#M22503</link>
    <description>&lt;P&gt;Does "&lt;SPAN style="font-size: 12px;"&gt;Sometimes it doesn't exit&lt;/SPAN&gt;" means that&amp;nbsp;&lt;SPAN style="color: rgb(0, 0, 0); font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 13.008px; background-color: rgb(248, 248, 248);"&gt;djacobi didn't return? Or it returned but CPU usage was still high?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2017 08:13:43 GMT</pubDate>
    <dc:creator>Jing_Xu</dc:creator>
    <dc:date>2017-04-07T08:13:43Z</dc:date>
    <item>
      <title>djacobi doesn't exit</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074969#M22502</link>
      <description>&lt;P&gt;(Nonlinear Least Squares Problem without Constraints)&lt;BR /&gt;
	I have implemented a C# TrustRegion Algotithm using MKL API (eg. dtrnlspbc_solve, djacobi ...) for our purposes.&lt;BR /&gt;
	It works very well but sometimes no.&lt;/P&gt;

&lt;P&gt;Sometimes it doesn't exit, it seems djacobi remains in loop (at least it seems debugging).&amp;nbsp;&lt;BR /&gt;
	In the attached image you can see the CPU usage, I've executed the method three times.&lt;BR /&gt;
	The first time the method terminate, the CPU usage is restored to the previous value,&amp;nbsp;&lt;BR /&gt;
	and so the second time.&amp;nbsp;&lt;BR /&gt;
	But the third time something remains in usage!&lt;/P&gt;

&lt;P&gt;I have created a dedicated class with a method that execute the algorithm as a Thread.&lt;BR /&gt;
	After 60 seconds, if the solver hadn't finished it kills the thread, but it doesn't work.&lt;/P&gt;

&lt;P&gt;I've tried different tricks but anyone of this solved the problem.&lt;/P&gt;

&lt;P&gt;Any suggestion?&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	Thank you very much&lt;/P&gt;

&lt;P&gt;Below the solver main loop ...&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:csharp;"&gt;while (!bSuccessful)
            {
                if (mbShowMessages) Console.WriteLine("Step " + iStep.ToString());

                if (RCI_Solve(ref handle, fvec, fjac, ref iRCI_Request) != TR_SUCCESS)
                {
                    Console.WriteLine("RCI_Solve() retun error!");
                    RCI_FreeBuffers();
                    iError = 1;
                    goto end;
                }
                bSuccessful =
                    iRCI_Request == -1 || iRCI_Request == -2 || iRCI_Request == -3 ||
                    iRCI_Request == -4 || iRCI_Request == -5 || iRCI_Request == -6;

                if (iRCI_Request == 1)
                {
                    if (mbShowMessages) Console.WriteLine("go objective_function()");
                    objective_function(ref m, ref n, x, fvec);
                }
                if (iRCI_Request == 2)
                {
                    if (mbShowMessages) Console.WriteLine("go djacobi()");
                    int iRes = djacobi(objective_function, ref n, ref m, fjac, x, ref jac_eps);
                    if (iRes != TR_SUCCESS)
                    {
                        if (iRes == TR_INVALID_OPTION)
                        {
                            Console.WriteLine("error in djacobi: invalid options.");
                        }
                        else if (iRes == TR_OUT_OF_MEMORY) 
                        {
                            Console.WriteLine("error in djacobi: out of memory.");
                        }
                       
                        RCI_FreeBuffers();
                        iError = 1;
                        goto end;
                    }

                }

                if (iStep &amp;gt; MAX_STEP)
                {
                    Console.WriteLine(string.Format("Too many external loop! (max {0})", MAX_STEP));
                    RCI_FreeBuffers();
                    iError = 1;
                    goto end;
                }

                iStep++;
            }&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 13:41:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074969#M22502</guid>
      <dc:creator>Gianluca_G_1</dc:creator>
      <dc:date>2017-04-05T13:41:48Z</dc:date>
    </item>
    <item>
      <title>Does "Sometimes it doesn't</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074970#M22503</link>
      <description>&lt;P&gt;Does "&lt;SPAN style="font-size: 12px;"&gt;Sometimes it doesn't exit&lt;/SPAN&gt;" means that&amp;nbsp;&lt;SPAN style="color: rgb(0, 0, 0); font-family: Consolas, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 13.008px; background-color: rgb(248, 248, 248);"&gt;djacobi didn't return? Or it returned but CPU usage was still high?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 08:13:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074970#M22503</guid>
      <dc:creator>Jing_Xu</dc:creator>
      <dc:date>2017-04-07T08:13:43Z</dc:date>
    </item>
    <item>
      <title>Yes it didn't return. In this</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074971#M22504</link>
      <description>&lt;P&gt;&lt;BR /&gt;
	Yes it didn't return. In this case I kill the thread, but it seems it is still working.&lt;/P&gt;

&lt;P&gt;Gianluca&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 08:57:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074971#M22504</guid>
      <dc:creator>Gianluca_G_1</dc:creator>
      <dc:date>2017-04-07T08:57:05Z</dc:date>
    </item>
    <item>
      <title>It seems that every time I</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074972#M22505</link>
      <description>&lt;P&gt;It seems that every time I execute the procedure the cpu time increases.&lt;/P&gt;

&lt;P&gt;After three times it doesn't return.&lt;/P&gt;

&lt;P&gt;any idea?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 13:32:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074972#M22505</guid>
      <dc:creator>Gianluca_G_1</dc:creator>
      <dc:date>2017-04-07T13:32:54Z</dc:date>
    </item>
    <item>
      <title>How do you call MKL functions</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074973#M22506</link>
      <description>&lt;P&gt;How do you call MKL functions in C#?&lt;/P&gt;

&lt;P&gt;A workaround is calling these MKL functions inside a cpp file, then build it to be a dll. In C#, you may call the functions implemented in the dll to avoid calling MKL functions directly in C#.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 00:54:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074973#M22506</guid>
      <dc:creator>Jing_Xu</dc:creator>
      <dc:date>2017-04-11T00:54:41Z</dc:date>
    </item>
    <item>
      <title>It is long time I don't work</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074974#M22507</link>
      <description>&lt;P&gt;It is long time I don't work with c++, that it will take me too many time.&lt;/P&gt;

&lt;P&gt;But do you know this problem?&amp;nbsp;&lt;/P&gt;

&lt;P&gt;If I share with you a c# console program &amp;nbsp;example, could you help me?&amp;nbsp;&lt;/P&gt;

&lt;P&gt;We can use an ufficial support channel, we have a regular licence of Parallel studio XE.&lt;/P&gt;

&lt;P&gt;Gianluca&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 10:09:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074974#M22507</guid>
      <dc:creator>Gianluca_G_1</dc:creator>
      <dc:date>2017-04-11T10:09:45Z</dc:date>
    </item>
    <item>
      <title>Sometimes, it is better to</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074975#M22508</link>
      <description>&lt;P&gt;Sometimes, it is better to break up the problem into smaller pieces. Let us set aside the complexities of mixed language calls between C#, C++ and MKL. What is the nature of this objective function for which it takes ~60 seconds to compute the Jacobian? How many functions make up the SSQ expression, how many variables, and what is the time for one SSQ evaluation?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 11:59:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074975#M22508</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2017-04-11T11:59:01Z</dc:date>
    </item>
    <item>
      <title>Image a button on a Form that</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074976#M22509</link>
      <description>&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;Image a button on a Form that I click every time I need the calculation.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;The question is that the method works well the first time I call it. Also the second time but the third not.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;It doesn't depend on the complexity of "obj func" at least it seems like this.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Below &amp;nbsp;L3_Function(), one case of objective function with 5 variables.&lt;/P&gt;

&lt;P&gt;It gives a Soil Model Resistivity aproximation. If you please I can be more precise.&lt;/P&gt;

&lt;PRE class="brush:csharp;"&gt;public void L3_Function(ref int m, ref int n, [In] IntPtr xp, [Out] IntPtr fp)
        {
            double[] x = new double&lt;N&gt;;
            Marshal.Copy(xp, x, 0, n);
            double[] f = new double&lt;M&gt;;
            Marshal.Copy(fp, f, 0, m);

            double rho1 = x[0];
            double rho2 = x[1];
            double rho3 = x[2];
            double h1 = x[3];
            double h2 = x[4];
            double w = 1;

            for (int i = 0; i &amp;lt; m; i++)
            {
                w = Math.Sqrt(mlMeasures&lt;I&gt;.NumA);
                if (mbApplyMWeight)
                {
                    w = Math.Sqrt((1.0 / m + Math.Abs(i / m - 1 / 2)) * mlMeasures&lt;I&gt;.NumA);
                }

                f&lt;I&gt; = (1 - L3_RhoCalc(mlMeasures&lt;I&gt;.A, rho1, rho2, rho3, h1, h2) / mlMeasures&lt;I&gt;.RhoM) * w;
            }

            Marshal.Copy(f, 0, fp, m);
        }

        public double L3_RhoCalc(double a, double rho1, double rho2, double rho3, double h1, double h2)
        {          
            double dRe2 = AdpGauss.ThreeLayers(a, rho1, rho2, rho3, h1, h2);
            return dRe2;
        }

public static double ThreeLayers(double a, double rho1, double rho2, double rho3, double h1, double h2)
        {
            double dError = MAX_ERROR;
            int iStep = STEP_BASE;
            int iCount = 0;
            double dLeft = 0;
            double dRight = 0;
            double dInt = 0; //Integral Value
            double dIntPrev = 0; //Integral Previous Value

            double dNi12 = (rho2 - rho1) / (rho2 + rho1);
            double dNi23 = (rho3 - rho2) / (rho3 + rho2);

            double[] w = new double[] { 5d / 9d, 8d / 9d, 5d / 9d };
            double[] x = new double[] { -1d * Math.Sqrt(3d / 5d), 0d, Math.Sqrt(3d / 5d) };

            #region CalcLeft
            while (dError &amp;gt; EPSILON)
            {
                if (iCount &amp;gt; MAX_ITERATIONS)
                    break;

                dLeft = 0;
                //Console.WriteLine("&amp;gt; Step = " + iStep.ToString());
                for (int i = 0; i &amp;lt; iStep; i++)
                {
                    for (int j = 0; j &amp;lt; 3; j++)
                    {
                        double t = (x&lt;J&gt; + 2 * i + 1) / (2 * iStep);
                        //Console.WriteLine(string.Format("t({0},{1}) =  {2}", i, j, t.ToString()));
                        double k31 = (dNi12 + dNi23 * Math.Pow(Math.E, -2 * t * h2)) / (1 + dNi12 * dNi23 * Math.Pow(Math.E, -2 * t * h2));
                        double b3 = k31 * Math.Pow(Math.E, -2 * t * h1) / (1 - k31 * Math.Pow(Math.E, -2 * t * h1));
                        double f = b3 * (RciWrapper.Bessel(t * a) - RciWrapper.Bessel(2 * t * a));
                        dLeft += f * w&lt;J&gt;;
                    }
                }

                dLeft /= 2 * iStep;
                dInt = dLeft;

                if (iCount &amp;gt; 0)
                {
                    dError = Math.Abs(1 - dIntPrev / dInt);
                    //Console.WriteLine(iCount.ToString() + "&amp;gt; AdpGauss Error: " + dError.ToString());
                }

                dIntPrev = dInt;
                iStep *= 2;
                iCount++;
            }
            #endregion

            #region CalcRight
            dError = MAX_ERROR;
            iStep = 1;
            iCount = 0;
            while (dError &amp;gt; EPSILON)
            {
                if (iCount &amp;gt; MAX_ITERATIONS)
                    break;

                dRight = 0;
                for (int i = 0; i &amp;lt; iStep; i++)
                {
                    for (int j = 0; j &amp;lt; 3; j++)
                    {
                        double t = (x&lt;J&gt; + 2 * i + 1) / (2 * iStep);
                        double k31 = (dNi12 + dNi23 * Math.Pow(Math.E, -2 * (1 / t) * h2)) / (1 + dNi12 * dNi23 * Math.Pow(Math.E, -2 * (1 / t) * h2));
                        double b3 = k31 * Math.Pow(Math.E, -2 * (1 / t) * h1) / (1 - k31 * Math.Pow(Math.E, -2 * (1 / t) * h1));
                        double f = b3 * (RciWrapper.Bessel((1 / t) * a) - RciWrapper.Bessel(2 * (1 / t) * a));
                        dRight += (f * w&lt;J&gt;) / (t * t);
                    }
                }

                dRight /= 2 * iStep;

                dInt = dRight;

                if (iCount &amp;gt; 0)
                {
                    dError = Math.Abs(1 - dIntPrev / dInt);
                    //Console.WriteLine(iCount.ToString() + "&amp;gt; AdpGauss Error: " + dError.ToString());
                }

                dIntPrev = dInt;
                iStep *= 2;
                iCount++;
            }
            #endregion

            return rho1 + 4 * rho1 * a * (dLeft + dRight);
        }&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/M&gt;&lt;/N&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 12:19:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074976#M22509</guid>
      <dc:creator>Gianluca_G_1</dc:creator>
      <dc:date>2017-04-11T12:19:56Z</dc:date>
    </item>
    <item>
      <title>Could you provide your</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074977#M22510</link>
      <description>&lt;P&gt;Could you provide your complete code, please? Or a complete sample code.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 02:11:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074977#M22510</guid>
      <dc:creator>Jing_Xu</dc:creator>
      <dc:date>2017-04-12T02:11:40Z</dc:date>
    </item>
    <item>
      <title>Is it possible to send it in</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074978#M22511</link>
      <description>&lt;P&gt;Is it possible to send it in a confidential way?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 10:21:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/djacobi-doesn-t-exit/m-p/1074978#M22511</guid>
      <dc:creator>Gianluca_G_1</dc:creator>
      <dc:date>2017-04-12T10:21:45Z</dc:date>
    </item>
  </channel>
</rss>

