Using getsnapshot in parfor function

1 Ansicht (letzte 30 Tage)
sle
sle am 3 Dez. 2015
Kommentiert: Walter Roberson am 3 Dez. 2015
Hello all,
I am trying to run this following code in parallel but got this error:
Error using realTime_pointGrey>(parfor body) (line 52)
An UndefinedFunction error was thrown on the workers for 'getsnapshot'. This might be because the file containing 'getsnapshot' is not accessible on the workers. Use
addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
Error in realTime_pointGrey (line 50)
parfor id = 1:4
Caused by:
Undefined function 'getsnapshot' for input arguments of type 'struct'.
I am not very familiar with using addAttachedFiles, could you please help me?
The code I am working on:
parfor id = 1:4
% Get the snapshot of the current frame
data(:,id) = reshape(double(rgb2gray(getsnapshot(vid))),size(data0,1)*size(data0,2),1);
end
data_mean = mean(data,2);

Akzeptierte Antwort

Edric Ellis
Edric Ellis am 3 Dez. 2015
This error appears to be misleading - I think the problem is that the object vid is not being transferred to the workers correctly. You could confirm this like so
class(vid) % class on the client
spmd
class(vid) % class on the workers
end
If that isn't the same thing (and I strongly suspect it isn't), then what you need to do is create vid on the workers. In other words, I would first try
spmd
vid = <create 'vid'>;
getsnapshot(vid);
end
If that works, then one approach you might take to working with vid is to use parallel.pool.Constant as described here. (Or Worker Object Wrapper for older MATLAB releases).
  1 Kommentar
Walter Roberson
Walter Roberson am 3 Dez. 2015
Though again, if you do manage to transfer the same vid into all workers, the order the different workers take the snapshot is not predetermined.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 3 Dez. 2015
If I understand correctly, the parallel workers do not have access to the image hardware devices.
With the code you posted, imagine that the workers did have access to the image hardware devices. You ask to getsnapshot() of the same video device in each of the workers. The result would, at best, depend upon the order the workers happened to execute in. What were you hoping to be able to do? Are you hoping to import images from several different devices?

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by