英文:
How can I separate cores in different group and used by multiple function in MATLAB
问题
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.
英文:
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
得分: 0
MATLAB文档 表示这是不可能的:
你不能直接在另一个parfor循环内部嵌套parfor。一个parfor循环可以调用包含parfor循环的函数,但你不会获得额外的并行性。
和
你不能嵌套parfor循环,因为并行化只能在一个级别上执行。
因此,如果不重写函数,你无法实现你想要的功能。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论