1

parforコードの一部を高速化するために Matlab を使用したいと考えています。実行に必要な一部の関数は、クラス定義を含むディレクトリに存在します。したがって、次のように、必要なディレクトリと必要なファイルをプール オブジェクトに追加します。

% instantiate parallel pool object
poolobj = gcp; 
% add file containing class definition
poolobj.addAttachedFiles(fullfile(pwd,'@Gaussian','Gaussian.m'));
% add specific methods required in parfor loop
poolobj.addAttachedFiles(fullfile(pwd,'@Gaussian','logpredictive.m'));

poolobjフィールドに必要なファイルが含まれていることを確認して確認しAttachedFilesます。ただし、実行するparforと、Matlab はエラーをスローします。

An UndefinedFunction error was thrown on the workers for 'logpredictive'.
This might be because the file containing 'logpredictive' is not
accessible on the workers.  Use addAttachedFiles(pool, files) to specify
the required files to be attached.  See the documentation for
'parallel.Pool/addAttachedFiles' for more details.

編集:

以下の回答に基づいて、ディレクトリ全体を追加しようとしましたが、機能しませんでした:

poolobj.addAttachedFiles(fullfile(pwd,'@Gaussian'));
4

1 に答える 1