Use coder to convert parfor-loop to mex, but mex version is much slower
1 view (last 30 days)
I convert a function containing a parfor-loop into a mex file to get some speed up. But the mex version of this function is 5x times slower than the matlab's version.
Before running, I used parpool(20) to setup a parallel pool mannully. When mex version of function is running, the CPU load is increased but the parallel workers are not working (the pool status in the left-bottom corner of matlab is blue instead of green) . Besides, the pool automatically shutdown when the mex function is still running.
It seems the parfor-loop after codegen does not work. Is there any way that I can check if these workers are running?
When I use mex-version of parfor, there is a matlab process that have a CPU usage of 4000%, but when I use the m-code version of parfor, there are 20 processes with CPU usage of 100%. It seems parfor after codegen uses multi-thread instead of multi-process. And this multi-thread is much slower than multi-process.