<?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 Hi, Tao Yu, in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-doubled-when-calling-zgetrf-in-Csharp/m-p/1042369#M20778</link>
    <description>&lt;P&gt;Hi, Tao Yu,&lt;/P&gt;

&lt;P&gt;Thanks for the sharing. &amp;nbsp;I verify with MKL developers, the &amp;nbsp;function&amp;nbsp;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;ZGETRF and ZGETRS only, use very low extra memory, about few dozens of megabytes. &amp;nbsp;So t&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;he issue might be related to Marshalling.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Best Regards,&lt;/P&gt;

&lt;P&gt;Ying&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;P.s i should seen the kind of report some places, but can't find it, &amp;nbsp;you may search in the forum.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;It should not related, but you can try to add mkl_thread_free_buffers&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;() in your code and see if there is any changes. )&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jun 2014 06:33:20 GMT</pubDate>
    <dc:creator>Ying_H_Intel</dc:creator>
    <dc:date>2014-06-19T06:33:20Z</dc:date>
    <item>
      <title>Memory doubled when calling zgetrf in Csharp,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-doubled-when-calling-zgetrf-in-Csharp/m-p/1042367#M20776</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm solving a large complex dense matrix (10k*10k) in Csharp by calling&amp;nbsp;zgetrf first to LU-decompse the matrix.&amp;nbsp;If I understand correctly, zgetrf will do a in-place LU-decomposition. So there should be no extra copies produced.&amp;nbsp;But the memory usage becomes doubled (from 1.6G to more than 3G) when zgetrf is running. Can someone kindly tell me the reason? It would be great if I can figure out a solution to avoid the extra memory usage.&lt;/P&gt;

&lt;P&gt;Here is the code&lt;/P&gt;

&lt;PRE class="brush:csharp;"&gt;class Program
    {
        

        static void Main(string[] args)
        {
            int n1 = 10000;
            int n2 = n1 * n1;
            complex[] A = new complex[n2];
            complex[] b = new complex[n1];

            for (int i = 0; i &amp;lt; n1; i++)
            {
                for (int j = 0; j &amp;lt; n1; j++)
                {
                    int ij = j * n1 + i;
                    A[ij].r = i + 1;
                    A[ij].i = j + 1;
                }
                b&lt;I&gt;.r = i + 1;
                b&lt;I&gt;.i = i + 2;
            }

            int info = 0;
            int[] ipiv = new int[n1];
            MKL.LU_decomposition(A, ref n1, ref n2, ipiv, ref info);
            MKL.LU_solve(A, b, ref n1, ref n2, ipiv, ref info);
        }


        [SuppressUnmanagedCodeSecurity]
        public sealed class MKL
        {
            private MKL() { }

            [DllImport("customMKL_Sequential.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]
            public static extern void LU_decomposition([In, Out] complex[] A, ref int n1, ref int n2, [In, Out] int[] ipiv, ref int info);

            [DllImport("customMKL_Sequential.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]
            public static extern void LU_solve([In] complex[] A, [In, Out] complex[] b, ref int n1, ref int n2, [In] int[] ipiv, ref int info);
        }


        [StructLayout(LayoutKind.Sequential)]/* Force sequential mapping */
        public struct complex
        {
            [MarshalAs(UnmanagedType.R8, SizeConst = 64)]
            public double r;
            [MarshalAs(UnmanagedType.R8, SizeConst = 64)]
            public double i;
        };
    }&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;PRE class="brush:fortran;"&gt;subroutine LU_decomposition (A, n1, n2, ipiv, info)
    implicit none
    !dec$ attributes dllexport :: LU_decomposition
    !dec$ attributes alias:'LU_decomposition' :: LU_decomposition

    integer, intent(in) :: n1, n2
    integer, intent(inout) :: info
    integer, dimension(n1), intent(inout) :: ipiv
    complex(8), dimension(n2), intent(inout) :: A
    
    call zgetrf(n1, n1, A, n1, ipiv, info)
end subroutine
    
    
subroutine LU_solve (A, b, n1, n2, ipiv, info)
    implicit none
    !dec$ attributes dllexport :: LU_solve
    !dec$ attributes alias:'LU_solve' :: LU_solve

    integer, intent(in) :: n1, n2
    integer, intent(inout) :: info
    integer, dimension(n1), intent(in) :: ipiv
    complex(8), dimension(n2), intent(inout) :: A
    complex(8), dimension(n1), intent(inout) :: b
    
    call zgetrs('N', n1, 1, A, n1, ipiv, b, n1, info)
end subroutine&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks alot in advance&lt;BR /&gt;
	&lt;BR /&gt;
	&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2014 23:03:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-doubled-when-calling-zgetrf-in-Csharp/m-p/1042367#M20776</guid>
      <dc:creator>Yi_L_1</dc:creator>
      <dc:date>2014-06-17T23:03:51Z</dc:date>
    </item>
    <item>
      <title>This looks an interesting</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-doubled-when-calling-zgetrf-in-Csharp/m-p/1042368#M20777</link>
      <description>&lt;P&gt;This looks an interesting topic. I don’t know the root cause of the problem. But I did some investigations to provide some other tips. I run two programs and monitor the memery usage:&lt;/P&gt;

&lt;OL&gt;
	&lt;LI&gt;CSharp application (exe) calling Fortran dll (same with Yi L.). See&amp;nbsp;usage history. The first step is when the matrix and vector are allocated, and the next step starts when executing the LU decomposition.&lt;span class="lia-inline-image-display-wrapper" image-alt="CSharp.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/6961iCE44FA4965595467/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="CSharp.jpg" alt="CSharp.jpg" /&gt;&lt;/span&gt;&lt;/LI&gt;
	&lt;LI&gt;Fortran application (exe)&amp;nbsp;calling Fortran dll (same data with the CSharp one). See the memory usage history. There is no extra memory usage when it starts to execute the&amp;nbsp;&amp;nbsp;LU decomposition.&lt;span class="lia-inline-image-display-wrapper" image-alt="Fortran.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/6962iD35942AA83290008/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="Fortran.jpg" alt="Fortran.jpg" /&gt;&lt;/span&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;So I guess the problem might comes from passing data by crossing platform (from managed to native). Hope to get detailed explanation from experts in this forum.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2014 08:59:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-doubled-when-calling-zgetrf-in-Csharp/m-p/1042368#M20777</guid>
      <dc:creator>Yu__Tao</dc:creator>
      <dc:date>2014-06-18T08:59:56Z</dc:date>
    </item>
    <item>
      <title>Hi, Tao Yu,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-doubled-when-calling-zgetrf-in-Csharp/m-p/1042369#M20778</link>
      <description>&lt;P&gt;Hi, Tao Yu,&lt;/P&gt;

&lt;P&gt;Thanks for the sharing. &amp;nbsp;I verify with MKL developers, the &amp;nbsp;function&amp;nbsp;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;ZGETRF and ZGETRS only, use very low extra memory, about few dozens of megabytes. &amp;nbsp;So t&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;he issue might be related to Marshalling.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Best Regards,&lt;/P&gt;

&lt;P&gt;Ying&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;P.s i should seen the kind of report some places, but can't find it, &amp;nbsp;you may search in the forum.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;It should not related, but you can try to add mkl_thread_free_buffers&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;() in your code and see if there is any changes. )&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2014 06:33:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Memory-doubled-when-calling-zgetrf-in-Csharp/m-p/1042369#M20778</guid>
      <dc:creator>Ying_H_Intel</dc:creator>
      <dc:date>2014-06-19T06:33:20Z</dc:date>
    </item>
  </channel>
</rss>

