<?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 Dynamic Allocated Matrix and FFT routine in MKL in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Dynamic-Allocated-Matrix-and-FFT-routine-in-MKL/m-p/896099#M10875</link>
    <description>Hi everybody,&lt;BR /&gt;&lt;BR /&gt;I need to perform a 2D FFT on a dynamically allocated matrix of MKL_Complex8.&lt;BR /&gt;Let us assume that Dim is the variable containing the dimension of the square matrix I want to process, to handle the matrix DimxDim I use a double pointer structure such as the following code:&lt;BR /&gt;&lt;BR /&gt;DFTI_DESCRIPOR* a;&lt;BR /&gt;int dimension[2];&lt;BR /&gt;dimension[0]=Dim;&lt;BR /&gt;dimension[1]=Dim;&lt;BR /&gt;&lt;BR /&gt;MKL_Complex8** A,**B;&lt;BR /&gt;A=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8*));&lt;BR /&gt;B=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8*));&lt;BR /&gt;&lt;BR /&gt;for (it k=0;k&lt;DIM&gt;&lt;/DIM&gt; A&lt;K&gt;=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8);&lt;BR /&gt; B&lt;K&gt;=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8);&lt;BR /&gt; for (j=0;j&lt;DIM&gt;&lt;/DIM&gt; A&lt;K&gt;&lt;J&gt;=...//Initialization of Akj element&lt;BR /&gt; B&lt;K&gt;[]j=0;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then I perform a 2D FFT with the following code:&lt;BR /&gt;&lt;BR /&gt;DftiCreateDescriptor( &amp;amp;a, DFTI_SINGLE, DFTI_COMPLEX, 2,dimension );&lt;BR /&gt;status = DftiSetValue( a, DFTI_PLACEMENT, DFTI_NOT_INPLACE );&lt;BR /&gt;DftiCommitDescriptor( a );&lt;BR /&gt;status = DftiComputeForward ( a, A,B);&lt;BR /&gt;&lt;BR /&gt;THe code is compiled correctly and no errors appear but when I check the B matrix after the processing I do not get the correct result and the strange thing is that B is not anymore a matrix (if I try to access to B&lt;P&gt;&lt;Q&gt; after FFT I get an error).&lt;BR /&gt;&lt;BR /&gt;How can I manage dinamically allocated matrix with MKL FFT? Where is the issue in my approach?&lt;BR /&gt;Thanks in advance for any help.&lt;BR /&gt;&lt;BR /&gt;Bye,&lt;BR /&gt;&lt;BR /&gt;Pietro&lt;BR /&gt;&lt;/Q&gt;&lt;/P&gt;&lt;/K&gt;&lt;/J&gt;&lt;/K&gt;&lt;/K&gt;&lt;/K&gt;</description>
    <pubDate>Mon, 25 May 2009 09:45:04 GMT</pubDate>
    <dc:creator>pietro_vinettigmail_</dc:creator>
    <dc:date>2009-05-25T09:45:04Z</dc:date>
    <item>
      <title>Dynamic Allocated Matrix and FFT routine in MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Dynamic-Allocated-Matrix-and-FFT-routine-in-MKL/m-p/896099#M10875</link>
      <description>Hi everybody,&lt;BR /&gt;&lt;BR /&gt;I need to perform a 2D FFT on a dynamically allocated matrix of MKL_Complex8.&lt;BR /&gt;Let us assume that Dim is the variable containing the dimension of the square matrix I want to process, to handle the matrix DimxDim I use a double pointer structure such as the following code:&lt;BR /&gt;&lt;BR /&gt;DFTI_DESCRIPOR* a;&lt;BR /&gt;int dimension[2];&lt;BR /&gt;dimension[0]=Dim;&lt;BR /&gt;dimension[1]=Dim;&lt;BR /&gt;&lt;BR /&gt;MKL_Complex8** A,**B;&lt;BR /&gt;A=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8*));&lt;BR /&gt;B=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8*));&lt;BR /&gt;&lt;BR /&gt;for (it k=0;k&lt;DIM&gt;&lt;/DIM&gt; A&lt;K&gt;=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8);&lt;BR /&gt; B&lt;K&gt;=(MKL_Complex8*)malloc(Dim*sizeof(MKL_Complex8);&lt;BR /&gt; for (j=0;j&lt;DIM&gt;&lt;/DIM&gt; A&lt;K&gt;&lt;J&gt;=...//Initialization of Akj element&lt;BR /&gt; B&lt;K&gt;[]j=0;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then I perform a 2D FFT with the following code:&lt;BR /&gt;&lt;BR /&gt;DftiCreateDescriptor( &amp;amp;a, DFTI_SINGLE, DFTI_COMPLEX, 2,dimension );&lt;BR /&gt;status = DftiSetValue( a, DFTI_PLACEMENT, DFTI_NOT_INPLACE );&lt;BR /&gt;DftiCommitDescriptor( a );&lt;BR /&gt;status = DftiComputeForward ( a, A,B);&lt;BR /&gt;&lt;BR /&gt;THe code is compiled correctly and no errors appear but when I check the B matrix after the processing I do not get the correct result and the strange thing is that B is not anymore a matrix (if I try to access to B&lt;P&gt;&lt;Q&gt; after FFT I get an error).&lt;BR /&gt;&lt;BR /&gt;How can I manage dinamically allocated matrix with MKL FFT? Where is the issue in my approach?&lt;BR /&gt;Thanks in advance for any help.&lt;BR /&gt;&lt;BR /&gt;Bye,&lt;BR /&gt;&lt;BR /&gt;Pietro&lt;BR /&gt;&lt;/Q&gt;&lt;/P&gt;&lt;/K&gt;&lt;/J&gt;&lt;/K&gt;&lt;/K&gt;&lt;/K&gt;</description>
      <pubDate>Mon, 25 May 2009 09:45:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Dynamic-Allocated-Matrix-and-FFT-routine-in-MKL/m-p/896099#M10875</guid>
      <dc:creator>pietro_vinettigmail_</dc:creator>
      <dc:date>2009-05-25T09:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Allocated Matrix and FFT routine in MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Dynamic-Allocated-Matrix-and-FFT-routine-in-MKL/m-p/896100#M10876</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;Hi Pietro,&lt;/P&gt;
&lt;P&gt;I would not recommend you double-subscript syntax for dynamically allocated arrays. This syntax is good for static arrays, where compiler knows the size of the array and can insert offset computation automatically for you. Instead, I would suggest you to compute the offsets explicitly, and optionally use preprocessor define to hide the offset computation and make the code more readable. An example:&lt;/P&gt;
&lt;P&gt;MKL_Complex8 *A, *B; // not **A, **B&lt;BR /&gt;MKL_LONG dimension[2]; // MKL_LONG, not int!&lt;BR /&gt;A = malloc( sizeof(A[0]) * dimension[0] * dimension[1] );&lt;BR /&gt;B = /* similarly */;&lt;BR /&gt;#define A(i,j) A[(i)* dimension[1] + (j)]&lt;BR /&gt;#define B(i,j) B[(i)* dimension[1] + (j)]&lt;BR /&gt;for(...) { A(i,j) = ... ; }&lt;BR /&gt;DftiComitDescriptor(..., 2, dimension);&lt;BR /&gt;DftiComputeForward(..., A,B); // this will work, because both A and B point to actual data, not to the tables of pointers. When B is a table of pointers, FFT overwrites them and thus produces errors you have seen.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Dima&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2009 11:21:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Dynamic-Allocated-Matrix-and-FFT-routine-in-MKL/m-p/896100#M10876</guid>
      <dc:creator>Dmitry_B_Intel</dc:creator>
      <dc:date>2009-05-25T11:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Allocated Matrix and FFT routine in MKL</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Dynamic-Allocated-Matrix-and-FFT-routine-in-MKL/m-p/896101#M10877</link>
      <description>&lt;BR /&gt;With your suggestions, now everything works properly!&lt;BR /&gt;&lt;BR /&gt;Many thanks Dima.&lt;BR /&gt;&lt;BR /&gt;Bye,&lt;BR /&gt;&lt;BR /&gt;Pietro&lt;BR /&gt;</description>
      <pubDate>Mon, 25 May 2009 13:51:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Dynamic-Allocated-Matrix-and-FFT-routine-in-MKL/m-p/896101#M10877</guid>
      <dc:creator>pietro_vinettigmail_</dc:creator>
      <dc:date>2009-05-25T13:51:24Z</dc:date>
    </item>
  </channel>
</rss>

