How to use a Com server handle in parfor?
Mostrar comentarios más antiguos
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.
Respuestas (2)
Walter Roberson
el 16 de Dic. de 2013
0 votos
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.
Edric Ellis
el 16 de Dic. de 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 comentarios
ParallelCom
el 16 de Dic. de 2013
Editada: ParallelCom
el 17 de Dic. de 2013
Edric Ellis
el 17 de Dic. de 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
Categorías
Más información sobre Parallel for-Loops (parfor) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!