MATLAB Answers

0

Client to worker communication in Matlab

Asked by Anurag Kamal on 13 Jun 2019
Latest activity Commented on by Anurag Kamal on 13 Jun 2019
Is there a way to let the cleint send data back to parallel workers in Matlab. Using a queue make the data sending from worker to the client easy, but vice versa is proving diffcult.
I am trying to use a ascii file that is written by the client for the workers to read, but simulataneous accessing of the file is giving me an error.
Error using startSimulation>mainCore (line 440)
"File temp/current.txt is in use by another process or thread. You should be able to load data once the other process or thread has released the file."
Is there a way to wait for the file to be readable (waitfor doesn't work), or implemeting a easy semaphore code to do this? I am open to implementing any ideas, there has to be a communication between client and workers both ways.

  2 Comments

It would be helpful if you could post a minimal reproduction to demonstrate the problem. I presume you must be using parfeval to trigger execution on the workers - because otherwise the client would be blocked executing the parfor or spmd block otherwise... Could you perhaps only schedule the parfeval calls after the client has completed?
Well, I am using parfor, adn this is how the pseudo code looks like
mainscript()
initialize queue;
aftereach(queue,@purgefunc)
parfor i=1:3
results(i)=start_sim(params, queue)
end
end mainscript()
purgefunc(data)
if data==!
plot(results)
end if
end purgefunc
startsim(params, queue)
while t<tf // final simulation time
send.queue(data)
end
end
Now as the loop on workers is continuously running, how do I send data from client to worker.

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by Walter Roberson
on 13 Jun 2019

"You can construct the queue on the workers and send it back to the client to enable communication in the reverse direction. However, you cannot send a queue from one worker to another. Use spmd, labSend, or labReceive instead."

  1 Comment

if the workers are in a loop, how can they send a variable back to the client. Sending the pollable queue by the queue doesn't work, I tried it.

Sign in to comment.