Why do I get error when I use loadlibrary inside an SPMD block in MATLAB 7.12 ( R2011a)?
1 view (last 30 days)
Show older comments
I am using LOADLIBRARY to load a library on SPMD workers.
matlabpool open local 4
spmd
loadlibrary('testDLL2')
end
When I execute this code on my MATLAB I receive the following error:
Lab 1:
Warning: File not found or permission denied
> In loadlibrary>deltempfiles at 636
In loadlibrary at 436
In remoteBlockExecution at 47
??? Error using ==> spmd_feval at 8
Error detected on lab(s) 1
Caused by:
Failed to preprocess the input file.
Output from preprocessor is:The process cannot access the file because it is being used by
another process.
Error stack:
loadlibrary.m at 441
Accepted Answer
MathWorks Support Team
on 4 Nov 2011
This is a limitation of SPMD and LOADLIBRARY when used together on a shared file system.
When LOADLIBRARY is executed it runs preprocessor to parse the library header file. During the pre-processor execution LOADLIBRARY generates temporary files, which are destroyed after LOADLIBRARY operation completes.
The LOADLIBRARY always generates files with the same filename when loading a specific library.
When LOADLIBRARY is executed inside of SPMD on a MATLAB pool of N workers, there are N instances of LOADLIBRARY executing concurrently. These instances create a race condition for generating and deleting the temporary files. This race condition leads the error in question.
To work around this issue, the loading of libraries has to be serialized on the workers using the LABBARRIER command as shown in the example below:
spmd
for i = 1:numlabs
if i == labindex
loadlibrary('testDLL2')
end
labBarrier
end
end
spmd
calllib('testDLL2','addTwoNumbers',5,6)
end
0 Comments
More Answers (0)
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!