Why this piece of parallel code in MATLAB does not work ?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all, I am using pmode tool in MATLAB for parallel execution. I have situation where if there are two cores work in parallel and I want their internal results to be broadcast so other cores will know what each core is doing with own variables.
Please, the following code demonstrate the problem I am facing.
Kind regards Ammar -------------------------------------------------
itr=1;
while itr<=4
if labindex==1
X=itr;
itr=itr+1;
labBroadcast(1,X);
labBroadcast(1,itr);
elseif labindex==2
Y=itr;
itr=itr+1;
labBroadcast(2,Y);
labBroadcast(2,itr);
else
X=labBroadcast(1);
Y=labBroadcast(2);
itr=labBroadcast(1);
itr=labBroadcast(2);
end
end
---------------------------------------- The error message is
Warning: An incoming message was discarded from lab 2 (tag: 400003) Warning: An incoming message was discarded from lab 1 (tag: 400003)
0 commentaires
Réponses (1)
Steven Lord
le 18 Mai 2017
I believe that the causes for the two warning messages is that the worker with labindex == 1 (worker 1) does not have any code indicating it is to receive the data from the variable Y being broadcast by the worker with labindex == 2 (worker 2.) Nor does worker 2 have any code indicating it is to receive the data being broadcast by worker 1.
Based on the last paragraph in the Description section of the documentation page for the labBroadcast function I think you'll need to be very careful about the ordering of the labBroadcast calls to send and receive on workers 1 and 2. Otherwise you might end up with worker 1 waiting to send its information until it receives information from worker 2 and vice versa.
2 commentaires
Steven Lord
le 18 Mai 2017
By my understanding of the function, broadcasting involves one worker "speaking" and each of the other workers "listening". If one or more of the other workers aren't listening, you will receive the warning that the non-speaking, non-listening workers didn't receive the message.
Perhaps if you describe what you're trying to do in more detail, someone may be able to offer suggestions about whether pmode is the right tool or if something else, like parfor, spmd, or other parts of Parallel Computing Toolbox may be a better fit.
Voir également
Catégories
En savoir plus sur Parallel Computing Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!