Reputation: 31
I try to run a simple task on different machines of a cluster. My configuration has been validated (it's ok). When I run the code on the 'local' configuration, it works. But when I use the cluster configuration, I get the following error :
Error using parallel_function (line 598) Undefined function 'lafunc' for input arguments of type 'double'. Error Stack : (No remote error stack) Error in petittest (line 6) --» (petittest is my program's name) parfor it=1:200
I try to modify the code to use "dfeval" instead of the parfor loop, but I got the same kind of result (unrecognize function lafunc).
How do I get the other workers in the cluster to recognize the function lafunc that I manually defined ?
The code is the following:
%%%%%%%%%%%%%
laconfig='/home/matlab/fred/LACED_DC1.mat';
setmcruserdata('ParallelConfigurationFile',laconfig);
matlabpool open
parfor it=1:200
yo=lafunc(it);
disp(yo)
end
matlabpool close
%%%%%%%%%%%
where the lafunc function is
%%%%%%%%%%%%%%
function [y]=lafunc(x)
y=x*x;
end
%%%%%%%%%%%%%%%%%%%%%%
Thanks a lot, every piece of info is useful to me!!
Upvotes: 2
Views: 3919
Reputation: 19870
Make sure that your MATLAB script on all worker nodes running in the same working directory, and that other directories with functions you need are included in the path. So you can specifically set the working directory and path in your script:
matlabpool open
cd workdir
addpath funcdir
...
After you run matlabpool open
it will run all path related commands on all workers. See here.
You can also open matlabpool with 'FileDependencies'
parameter so all the workers will know where to look for required files. See the documentation for MATLABPOOL.
Upvotes: 7