Unable to read UDP data with parfeval

10 views (last 30 days)
Hi,
I am unable to call the read function inside a parfeval thread. I have attached the error for reference.
--------------------------------------------------
Here is the snippet of the code:
f = parfeval(p,@algorithmPipeline,0,app,adcBuffer,printBuffer);
-----------------------------
function algorithmPipeline(app,adcBuffer,printBuffer)
data = read(app.udpSock,1466,"uint8");
end
------------------------------------
The UDP is initialised and the values of app.udpSock are as follows.
UDPPort with properties:
IPAddressVersion: "IPV4"
LocalHost: "192.168.33.30"
LocalPort: 4098
NumBytesAvailable: 226771142
NOTE: When the algorithmPipeline is called normally without using parfeval it is working properly(There are no errors)
Thanks and Regards,
Srinivasan

Accepted Answer

Walter Roberson
Walter Roberson on 27 Sep 2021
When you use parpool (at least if you do not use the "threads" option, not sure about threads), then the workers are in a separate process. To send data to the process, MATLAB does the equivalent of save() in the controlling process, and load() in the worker process. However, that only works with some kinds of objects -- serializable objects. updport() objects are not serializable. (Generally speaking, device objects are not serializable.)
You will need to create the udpport object on the worker that you are going to run the parfeval() on.
... However, if your parpool has more than one member, then you could run into the problem that the worker you create the object on is not the one that runs your function. So you might have to create it on all workers, https://www.mathworks.com/help/parallel-computing/parfevalonall.html .. but which one will receive the data that is send to it ?

More Answers (0)

Categories

Find more on Asynchronous Parallel Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!