2 years ago

#74643

test-img

user49626

Issue with malloc in Mex file

I have C code which uses FFTW's FFT function. I need to mex the C code, call it and give inputs from matlab and get C performance plots. But ,here the problem is "malloc" fuction used by fftw's functions. As shown below in method 1, I used FFTW's malloc functions to create input and output array. While in method 2, I used mxMalloc functions (FFTW's malloc functions are not compulsory but recommended to use them, as it will take care of data aligment and which will be helpful for SIMD). With method 1, unable to use parfor. Getting error message as, "All workers are aborted during the execution of parfor loop" and with normal "for" loop method 1 is working fine. Note that, fft function is not called but just IO's are created and deallocated.

Eventhough method 2 is used for allocating memory, FFTW's FFT function uses there functions. 1)fftwf_plan_dft_1d 2)fftwf_execute 3)fftwf_destroy_plan. The function "fftwf_plan_dft_1d" uses malloc as shown here. Because of it I'm unable to use FFTW's FFT function inside parfor.

How to handle this problem? Is there any way to use FFTW ?.

%Method 1
fftwf_complex* inputArray = ffwtf_malloc(1024*sizeof(fftwf_complex));
fftwf_complex* outputArray = ffwtf_malloc(1024*sizeof(fftwf_complex));
//fft_function_call is commented.
fftwf_free(inputArray);
fftwf_free(outputArray);


%Method 2
fftwf_complex* inputArray = mxMalloc(1024*sizeof(fftwf_complex));
fftwf_complex* outputArray = mxMalloc(1024*sizeof(fftwf_complex));
//fft_function_call is commented.
mxFree(inputArray);
mxFree(outputArray);

matlab

malloc

mex

0 Answers

Your Answer

Accepted video resources