Multithreading to control several devices through matlab realtime
Afficher commentaires plus anciens
Hey People
I am an experimentalist physicist and I have built an extensive set of functions in matlab to control my experiment. In general my experiment involves controlling several different equipment and I have interfaced all of them have built classes for them. All has been good so far and I am very happy about the performance. But now I need to control several of these equipment in parallel and that is where I am stuck. I searched on the web for multi-threading matlab, and I found alot of stuff about multithreaded computing in matlab. However I did not find anything where I could have several threads and pass messages between them. I appreciate any kind of hint or tips.
Réponses (1)
Walter Roberson
le 7 Mar 2016
0 votes
The Parallel Computing Toolbox "spmd" facility is more or less that. You use labSend() and labReceive() to transfer data between workers.
4 commentaires
Walter Roberson
le 8 Mar 2016
thread_functions = {@read_accelerator, @write_rainbow, @etch_flatulence}
num_threads = length(thread_functions);
spmd (num_threads)
thread_functions{K}();
end
The actual code would be slightly more complicated due to the need to add the functions to the workers as the automatic location of routines works statically (what it can see in the body of the functions) not based upon function handles. But this is not a difficult change once you know it needs to be done.
AJ1
le 8 Mar 2016
Walter Roberson
le 12 Mar 2016
By the way, I saw some information a couple of days ago indicating that you need to feval() function handles in parallel processing rather than just call them. At the moment I do not remember the reasoning.
At the moment the only way I can think of to run asychronously and still have access to the command line is to use parfeval(), but I don't think that allows communication between workers.
The only way I can think of at the moment to do shared variables between workers is to use the File Exchange contribution "sharedmatrix" which uses operating system shared memory primitives.
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!