Pergunta

I want to read a large amount of files, process each of them and save the results for each of them in a .mat file. The processing of each file is independent from the others, so I'd like to try using parfor. I have written the following Matlab script file:

load filelist
obj = package.name.SomeObject();
matlabpool local 5
parfor i=1:length(filelist)
    result = obj.compute(filelist{i});
    [~, name, ~] = fileparts(filelist{i});
    save(['~/path/' name], 'result');
end % file loop
matlabpool close

When I try to run it on my computer, a Matlab pool is intialized (connected to 5 workers), but then the following error message occurs:

Error using parallel_function (line 589)
Undefined function or variable "cleaner".

Error in readfiles (line 14)
parfor i=1:length(filelist)

Error in run (line 64)
evalin('caller', [script ';']);

Do you know where the problem could be?

Foi útil?

Solução

I don't know why (there might be a connection to this issue), but the problem was solved by enclosing the code inside a function and calling that function (instead of calling the script file by run script.m). It also required creating a parsave function (see explanation here).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top