- This could be because a worker crashed; if this has happened, then analyze the crash log and see whether the mex code is causing this crash or not. If the mex code is the reason, then try running the mex code locally to see if it works fine. You can refer to the following documentation link to read more about it: https://in.mathworks.com/support/search.html/answers/336076-how-do-i-troubleshoot-the-lost-connection-to-worker-x-parallel-error.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:matlab-parallel-server/index&page=1
- It might be possible that a deadlock was occurring while the workers were trying to access a particular resource. If this is the case, then you need to write thread-safe implementations. You can read more about this issue at the following link: https://in.mathworks.com/support/search.html/answers/273509-parfor-loop-just-hangs-cpu-usage-goes-to-zero.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:parallel-computing/parallel-computing-fundamentals&page=1
- Additionally, you can refer to the following link, which has some example code where "parfor" is used along with the FFTW: https://in.mathworks.com/help/coder/ug/synchronize-access-to-fftw-planning-in-generated-standalone-code.html
Issue with malloc in Mex file.
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi there,
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);
0 Commenti
Risposte (1)
Aman
il 23 Gen 2024
Hi Meddi,
As per my understanding, you have written a mex code that utilizes the FFTW library and are facing issues while using parallelization.
Without the actual code, it is quite difficult to tell the error upfront, but from the explanation that you have provided, you can try the below workarounds for debugging out the issue:
I hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!