1

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?

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.