How can I separate cores in different group and used by multiple function in MATLAB

41 views Asked by At

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.

1

There are 1 answers

0
Cris Luengo On BEST ANSWER

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.