Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6998 Discussions

MODERATOR, Please Delete!! C++, cheking allocation of complex array with FFTW wrappers


Moderator, can you delete this topic?!

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.



Good afternoon, everybody.

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  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.

// 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<int>(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)

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.

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.

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?

0 Kudos
0 Replies