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

distributed computingdistributed tasksmulti agentparallel computing

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

Best Answer

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