简体   繁体   English

集群上的Parfor:无法识别功能

[英]Parfor on a cluster : failure to recognize a function

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'. 使用parallel_function时出错(第598行)对于“ double”类型的输入参数,未定义函数“ lafunc”。 Error Stack : (No remote error stack) Error in petittest (line 6) --» (petittest is my program's name) parfor it=1:200 错误堆栈:(无远程错误堆栈)petittest(第6行)中的错误-»(petittest是我的程序的名称)parfor = 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). 我尝试将代码修改为使用“ dfeval”而不是parfor循环,但是得到了相同的结果(无法识别函数lafunc)。

How do I get the other workers in the cluster to recognize the function lafunc that I manually defined ? 如何让集群中的其他工作程序识别我手动定义的函数lafunc?

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 lafunc函数在哪里

%%%%%%%%%%%%%%

function [y]=lafunc(x)
y=x*x;
end

%%%%%%%%%%%%%%%%%%%%%%

Thanks a lot, every piece of info is useful to me!! 非常感谢,每条信息对我都很有用!!

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. 确保在同一工作目录中运行的所有工作程序节点上的MATLAB脚本,以及路径中包含具有所需功能的其他目录。 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. 运行matlabpool open ,它将在所有worker上运行所有与路径相关的命令。 See here . 这里

You can also open matlabpool with 'FileDependencies' parameter so all the workers will know where to look for required files. 您也可以使用'FileDependencies'参数打开matlabpool,以便所有工作人员都知道在哪里查找所需文件。 See the documentation for MATLABPOOL . 请参阅MATLABPOOL的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM