How to use a Com server handle in parfor?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
When I use a com server handle in the parfor, I get the error "Attempt to reference field of non-structure array".
Here is a sample of the code:
h=actxserver('......');
parfor i=1:4
b1=h.Do-something
c=b1{1}{1}
end
where Do-something generates an output in variant-type variable b1. Using "for" I can get the value for the variable of interest c but with "parfor" I get the error.
0 Commenti
Risposte (2)
Walter Roberson
il 16 Dic 2013
My understanding is that each parfor worker is in a different process. The complete active COM server does not get copied to each process. This is similar to the way that you cannot do graphics inside a parfor, as only the parent process has the connection to the graphics session.
If you were to use SPMD then you could have one of the labs act as a server for the other labs, fielding requests via labsend() from the other labs, labreceive() on the one lab, get the responses from the server, and pass the responses back with labsend(). Or you could perhaps open a separate activex within each lab.
0 Commenti
Edric Ellis
il 16 Dic 2013
As Walter says, each worker is a separate MATLAB process. Also, each variable is transferred to the workers as if it had been saved to disk and then loaded again (although that's not exactly how it happens in practice). After this transfer, handle-type variables are no longer "connected". Does it work to do this:
parfor i = 1:4
h = actxserver('...');
...
end
? (If so, you might get further benefit by using a worker object wrapper around it - especially if you need 'h' in multiple PARFOR loops).
2 Commenti
Edric Ellis
il 17 Dic 2013
Because the actxserver object appears not to be transmitted correctly from the client to the workers, you need to build it on the workers. With WorkerObjWrapper, here's one way you could do that:
wrapper = WorkerObjWrapper(@actxserver, '...');
parfor i = 1:4
h = wrapper.Value;
... use h ...
end
Vedere anche
Categorie
Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!