I am currently writing a matlab program. There's a function, denote it as myfunc(..)
. myfunc
has a parfor
which requires 4 CPUs. I need to run myfunc
for 3 times, and it happens that my PC has 12 cores. But when I try to use parfor
like:
parfor lp
myfunc()
end
Only the outmost parfor will be used.
I wonder is there any other way to separate cores in groups, for example each group has 4 cores, and there should be 3 groups in total, which allow me to use all 12 cores simultaneously.
All the cpus should be occupied. Because myfunc is a complicated function which means I can not change that easily, just consider that as a built-in function. I need to focus on the group.
The MATLAB documentation says that this is not possible:
You cannot nest parfor directly within another parfor-loop. A parfor-loop can call a function that contains a parfor-loop, but you do not get any additional parallelism.
and
You cannot nest parfor-loops because parallelization can be performed at only one level.
So, it is just not possible to do what you want to do without rewriting the function.