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

채택된 답변

Sean de Wolski
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
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개)

카테고리

Help CenterFile Exchange에서 Reinforcement Learning에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by