In MATLAB, How can I set code or a specific task to be executed by specific one or more core of a cpu?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
la
le 30 Déc 2014
Commenté : Reinhold Erwin Suchowitzky Toba
le 27 Juil 2023
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 commentaires
Réponse acceptée
Sean de Wolski
le 30 Déc 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 commentaires
Marco Feder
le 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".
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!