In MATLAB, How can I set code or a specific task to be executed by specific one or more core of a cpu?

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 30 Dez. 2014
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 Kommentare
Marco Feder
Marco Feder am 11 Mai 2020
@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".

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by