The error you're receiving is a bit surprising - that probably means that all your workers crashed somehow.
In any case, the syntax you're using to combine parfeval with save is not right. Firstly, save doesn't return any output arguments, so you need to specify 0 for the number of outputs. Secondly, and more importantly, save accepts the names of variables that you want to save, and extracts the values from the enclosing workspace. This makes it tricky to use with parfeval. You basically need to wrap the call to save in another function. You probably then want to wrap load in a similar function. Like this:
x = rand(3);
fileName = fullfile(tempdir, 'file.mat');
f = parfeval(@mySave, 0, fileName, x);
wait(f);
f = parfeval(@myLoad, 1, fileName);
x2 = fetchOutputs(f);
assert(isequal(x, x2))
function mySave(fname, value)
save(fname, 'value');
end
function value = myLoad(fname)
data = load(fname);
value = data.value;
end
This shows you how to save and load on the workers. It's not clear to me that this is actually a terribly useful thing to do though - you might well find that it takes so long to send the data to the worker prior to saving it that it doesn't gain you any benefit. Saving data from the workers is probably only useful if you're doing other work prior to the save.
0 Comments
Sign in to comment.