SPMD and Asynchronous execution of an optimization routine?

1 view (last 30 days)
I am looking to utilize the labSend, labReceive functionality with spmd in MATLAB to execute perform the following:
  1. Lab1, run a global optimization routine and pass an intermediate result to Lab2
  2. Lab2, wait for the intermediate result from Lab1 (using labProbe), once received use this result and begin a new optimization routine.
  3. Lab3,4,..., n wait for the previous result from Lab_n-1, once received use this result and begin a new optimization routine.
Problem:
Warning: An incoming message was discarded from lab 1 (tag: 1)
Warning: An incoming message was discarded from lab 1 (tag: 1)
Warning: An incoming message was discarded from lab 1 (tag: 1)
Warning: An incoming message was discarded from lab 1 (tag: 1)
Warning: An incoming message was discarded from lab 1 (tag: 1)
Data from labSend:
0.4907 0.3328 0.3625 0.5843 0.3159 0.5065 0.5100
0.4984 0.3336 0.5055 0.5216 0.5268 0.5002 0.4828
0.4907 0.3328 0.3625 0.5843 0.3159 0.5065 0.5100
0.4984 0.3336 0.5055 0.5216 0.5268 0.5002 0.4828 0.5010
which is in order with 0.04907 being the first message sent via labSend.
The last value received from labReceive:
0.5055
meaning the last 5 messages from labSend were ignored.
Now, the spmd routine is asynchronous as it 1) has to initially wait for the first intermediate result of the previous lab and 2) the optimization routine speeds up as it progresses (searching a smaller domain)
Therefore, the previous labs may send multiple messages before lab_n has the chance to process them (executing something else). This is because as the previous lab finds a new intermediate result, I execute labSend in order to provide the subsequent labs the most up-to-date data.
Question:
Is there a way to immediately process (receive) data from Lab1 if I am looking at Lab2 and just store it somewhere? Or is there a way to process only the most recent message? and ignore any queued messages?
Thanks for your help!

Accepted Answer

Edric Ellis
Edric Ellis on 11 May 2020
labSend and labReceive are designed for matched communication, and there isn't any built-in facility to receive only the most recent message. You could perhaps use a pattern like this though:
% receive only most recent message
data = labReceive(src);
while labProbe(src)
data = labReceive(src);
end
This will keep overwriting data while there is more to receive.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!