<?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 MODERATOR, Please Delete!! C++, cheking allocation of complex array with FFTW wrappers in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MODERATOR-Please-Delete-C-cheking-allocation-of-complex-array/m-p/1162958#M28033</link>
    <description>&lt;P&gt;Moderator, can you delete this topic?!&lt;/P&gt;

&lt;P&gt;After some hours debugging, I was doing improper error checking on other parts of the code that led me to believe that an if() testing a fftw wrapped array was being evaluated true, but it was not the case.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;=============&lt;/P&gt;

&lt;P&gt;Good afternoon, everybody.&lt;/P&gt;

&lt;P&gt;I have a 1D FFT implementation, originally written for FFTW, and am crash-testing the code to catch memory allocation problems before running the transform. In&amp;nbsp; the code below I declare the complex array and condition the creation of the plan to the allocation of the array, and if all goes fine, run the transform.&lt;/P&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;// using 32bit precision, I don't need more than this
fftwf_complex	*fft_complex_1D;
fftwf_plan	plan_fwfft_1D;

// Allocates the complex array
fft_complex_1D = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * array_length_fft_1D);

// Creates the plan if the allocation worked
if (fft_complex_1D != NULL)
    plan_fwfft_1D = fftwf_plan_dft_r2c_1d(static_cast&amp;lt;int&amp;gt;(array_length_fft_1D), in_fft_float_1D, fft_complex_1D, FFTW_ESTIMATE);

// If the plan was created successfully, run it
if (plan_fwfft_1D != NULL)
    fftwf_execute(plan_fwfft_1D);&lt;/PRE&gt;

&lt;P&gt;The variable array_length_fft_1D is a size_t provided by user and in_fft_float_1D is an array previously declared and initialized. When I use values up to 2^29 for the length, it will work fine, but when I test the memory allocation with a value that I know my machine can't allocate, such as 2^31, I should get the line "if (fft_complex_1D != NULL)" evaluated to false. But it evaluates to true.&lt;/P&gt;

&lt;P&gt;Then the next test, if the plan was created, the transform doesn't execute because "if (plan_fwfft_1D != NULL)" evaluates to false. Printing the value of fft_complex_1D gives 0000000000000000, so indeed it couldn't allocate the complex array of the specified length.&lt;/P&gt;

&lt;P&gt;Do you see anything wrong here, or is there any consideration you want to make about the first "if" evaluating to true when, apparently, it shouldn't?&lt;/P&gt;</description>
    <pubDate>Sun, 29 Jul 2018 12:53:13 GMT</pubDate>
    <dc:creator>Silva__Saulo</dc:creator>
    <dc:date>2018-07-29T12:53:13Z</dc:date>
    <item>
      <title>MODERATOR, Please Delete!! C++, cheking allocation of complex array with FFTW wrappers</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MODERATOR-Please-Delete-C-cheking-allocation-of-complex-array/m-p/1162958#M28033</link>
      <description>&lt;P&gt;Moderator, can you delete this topic?!&lt;/P&gt;

&lt;P&gt;After some hours debugging, I was doing improper error checking on other parts of the code that led me to believe that an if() testing a fftw wrapped array was being evaluated true, but it was not the case.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;=============&lt;/P&gt;

&lt;P&gt;Good afternoon, everybody.&lt;/P&gt;

&lt;P&gt;I have a 1D FFT implementation, originally written for FFTW, and am crash-testing the code to catch memory allocation problems before running the transform. In&amp;nbsp; the code below I declare the complex array and condition the creation of the plan to the allocation of the array, and if all goes fine, run the transform.&lt;/P&gt;

&lt;PRE class="brush:cpp; class-name:dark;"&gt;// using 32bit precision, I don't need more than this
fftwf_complex	*fft_complex_1D;
fftwf_plan	plan_fwfft_1D;

// Allocates the complex array
fft_complex_1D = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * array_length_fft_1D);

// Creates the plan if the allocation worked
if (fft_complex_1D != NULL)
    plan_fwfft_1D = fftwf_plan_dft_r2c_1d(static_cast&amp;lt;int&amp;gt;(array_length_fft_1D), in_fft_float_1D, fft_complex_1D, FFTW_ESTIMATE);

// If the plan was created successfully, run it
if (plan_fwfft_1D != NULL)
    fftwf_execute(plan_fwfft_1D);&lt;/PRE&gt;

&lt;P&gt;The variable array_length_fft_1D is a size_t provided by user and in_fft_float_1D is an array previously declared and initialized. When I use values up to 2^29 for the length, it will work fine, but when I test the memory allocation with a value that I know my machine can't allocate, such as 2^31, I should get the line "if (fft_complex_1D != NULL)" evaluated to false. But it evaluates to true.&lt;/P&gt;

&lt;P&gt;Then the next test, if the plan was created, the transform doesn't execute because "if (plan_fwfft_1D != NULL)" evaluates to false. Printing the value of fft_complex_1D gives 0000000000000000, so indeed it couldn't allocate the complex array of the specified length.&lt;/P&gt;

&lt;P&gt;Do you see anything wrong here, or is there any consideration you want to make about the first "if" evaluating to true when, apparently, it shouldn't?&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jul 2018 12:53:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MODERATOR-Please-Delete-C-cheking-allocation-of-complex-array/m-p/1162958#M28033</guid>
      <dc:creator>Silva__Saulo</dc:creator>
      <dc:date>2018-07-29T12:53:13Z</dc:date>
    </item>
  </channel>
</rss>

