如何在MATLAB中将不同核心分组并供多个函数使用

huangapple go评论43阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月9日 18:03:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683045.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定