Why do I obtain an error when using a shared library or standalone application generated using MATLAB Compiler from MATLAB code containing PARFOR loops in Parallel Computing Toolbox 4.1 (R2009a)?

1 view (last 30 days)
I have a MATLAB function called parforTest.m which contains a PARFOR loop. I am compiling this function into a C-shared library. The DLL that is generated is in the same folder as the MATLAB function parforTest.m. When I attempt to call into this DLL from a driver application, I receive the following error:
??? Error using ==> parallel_function at 594
Error in ==> remoteParallelFunction>iDeserializeByteBuffer at 65
Previously accessible file "C:\work\parforTest.m" is
now inaccessible.
Error in ==> parforTest at 3
However, when I move the DLL and the driver application to a folder other than the one containing parforTest.m, I am able to execute the code successfully.
The same behavior can be observed with a standalone executable created using MATLAB Compiler.
Why does this occur?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 30 Jul 2009
This is the expected behavior when using a PARFOR loop in a compiled application. When you start a MATLABPOOL, all the workers "cd" to the client's working directory which in this case is the "C:\Work" directory. When the worker needs to evaluate the shared library function "mlfParforTest", it looks for a file called "parforTest.m", finds it in the current directory and tries to run it. However, since this function is not the compiled version, the worker fails and the error is obtained.
However, if the client, and therefore, the workers are in a different directory when the application starts then this error does not occur. The above mentioned workaround can be used if the workers are on the local machine.
If the workers are on a different machine, then to ensure that this file is available to all the workers, specify FileDependencies when opening a MATLABPOOL as shown below:
matlabpool('open', 'FileDependencies', {'parforTest.m'});
This will ensure that all the workers will have the file.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!