In MATLAB, How can I set code or a specific task to be executed by specific one or more core of a cpu?
3 次查看(过去 30 天)
显示 更早的评论
I am using Matlab to simulate my project. In design of this project, several software agents work together in parallel (each agent has its own tasks), these agents cooperate together and sometimes they exchange data and messages with each other. Now the question is:in MATLAB,how these agents can carry out their tasks in parallel? In MATLAB, How can I set code or a specific task to be executed by specific one or more core of a CPU? Thanks
0 个评论
采纳的回答
Sean de Wolski
2014-12-30
If you have the Parallel Computing Toolbox, spmd is the construct you will want. You can use labindex to determine the worker and labSend,labRecieve,labBroadcast to transmit data between workers.
spmd
if labindex == 1
% First worker, do whatever
elseif labindex == 2
% Second worker do whatever
end
end
3 个评论
Marco Feder
2020-5-11
@Sean de Wolski
I'm sorry for necroposting, but since the OP asked how "a specific task to be executed by specific one or more core of a CPU?", it doesn't seem to me the question has been fully answered in the case one wants to use more cores. (I've never used PCT, so probably I'm missing something).
I mean: if one has 4 physical cores, and wants to use 2 cores to perform task1 and the other 2 to perform task2, how can this be done with the spmd construct above? It's not clear to me how this can be done just using "labindex".
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!