Can't pass COM object handle into spmd body

1 visualización (últimos 30 días)
matlabUser
matlabUser el 14 de Oct. de 2011
I am using an application object opened using ActiveX server,
oApp = actxserver('my.application');
in the definition of an anonymous function,
fHandle = @(x) myFunction(x,oApp);
(I am processing the data 'x' with an external application 'my.application'.)
This function handle works fine when I call it form the MATLAB client, like this:
fHandle(5)
ans =
100
However, when I call it from within spmd body,
spmd
if labindex == 1
y = fHandle(x);
end
.....
end
I am getting an error message like "Trying to reference an un-structured object", and you can see this object is oApp. So, the lab from the spmd pool does not oApp as a valid application object. I tried to open this object inside the spmd body, but I cannot define an anonymous function there (documentation says the same).
Can anybody please give me a hint how to solve this problem? -Thanks a lot!

Respuesta aceptada

matlabUser
matlabUser el 17 de Oct. de 2011
|It looks like there exists a simple solution which involves creating a COM object inside the spmd body, but avoids creating an anonymous function there. One has to create the anonymous function outside the spmd body, and indicate COM object as one of _variables_ (not parameters) like in the example code below. First you define an external function somewhere:|
function y = exFunction(x,oApp,c)
% Find the square of x and does nothing to oApp
y = c * x.^2;
% Display argument oApp to check if it is of type
% COM.Excel_Application
oApp
end
Then the script with spmd body will look like:
matlabpool open 2
% specify the additional parameter:
c = 3; % whatever values you need
%Create a Function handle of function exFunction
fhun = @(x,oApp) exFunction(x,oApp,c);
spmd
if labindex==1
R = rand(2,2)
else
%Create a COM server running Microsoft Excel
oApp = actxserver ('Excel.Application')
% Pass 'oApp' to exFunction
R = fhun(5,oApp)
end
end
matlabpool close

Más respuestas (1)

Edric Ellis
Edric Ellis el 14 de Oct. de 2011
As you've discovered, there are some limitations with passing handle-type objects into the body of SPMD blocks. This is because the workers executing the SPMD block are separate processes, potentially on separate machines. Therefore the data is effectively saved and reloaded (but without going via the disk).
Perhaps you could use my 'WorkerObjectWrapper' which is designed to help managing the lifetime of objects to be used within SPMD and PARFOR.
  1 comentario
matlabUser
matlabUser el 14 de Oct. de 2011
Thank you Edris, I will try what you suggested.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by