MATLAB using parfor (parallel computing toolbox) and custom packages with +

独自空忆成欢 提交于 2019-12-11 08:15:50

问题


I am working on a MATLAB program that users many other custom-made packages, often containing similarly-named files. So I have decided to use the custom package approach (http://www.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.html) to effectively get dot notation when referring to specific functions within the various packages I am using. For example, I have a package called pose that has this file structure:

MATLAB % on the MATLAB path
   --- +pose
          --- detect.m
          --- MORE STUFF
   --- +tracker
          --- MORE STUFF
   --- main.m

In my main.m file, I have a parallelized for loop:

parfor i=start:stop
    ... BLAH BLAH
    boxes = pose.detect(stuff);
    ... BLAH BLAH
end

But I keep getting the error that

MATLAB cannot determine whether "pose" refers to a function or variable. See Parallel for Loops in MATLAB, "Unambiguous Variable Names".

Looking at the MATLAB parallel programming documentation (http://www.mathworks.com/help/distcomp/programming-considerations.html), it seems like all functions that you use inside a parallel for loop must be transparent inside the for loop. But this seems in direct violation of the other parallel programming principle in MATLAB, which is that "All workers executing a parfor-loop must have the same MATLAB search path as the client".

Does anyone know how to reconcile this?


回答1:


Found the answer!

I did the solution from this webpage http://www.mathworks.com/help/distcomp/share-code-with-the-workers.html by putting the path command in the worker startup file: matlabroot\toolbox\local\startup.m

So I added the line path('/custom_dir/MATLAB/', path);, and it worked great.



来源:https://stackoverflow.com/questions/25898244/matlab-using-parfor-parallel-computing-toolbox-and-custom-packages-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!