MATLAB: Do I receive an error using LOADLIBRARY when I use two workers in a single machine using Distributed Computing Toolbox 3.1 (R2007a)

Parallel Computing Toolbox

I am running a set of tasks on 8 workers. On workers that were sharing a machine, I observed the following errors sporadically:
Error using ==> loadlibrary at 295
The mfile describing your library could not be found possible Perl or file system error.
and
Error using ==> loadlibrary at 282
Call to Perl failed. Possible error processing header file.
Output of Perl command:
Can not open file PTDLL.i because No such file or directory at C:\Program Files\MATLAB\R2007a\MDCE\toolbox\matlab\general\private\prototypes.pl line 32.

Best Answer

In the call to LOADLIBRARY, a *.i file is generated when LCC is called to preprocess the header file of the dll. This file is placed in a temporary folder and may be deleted later. The issue is due to these temporary files being overwritten when two workers are run on the same machine.
To avoid this, you can use the MATLAB file prototype option while using LOADLIBRARY instead of the header. When LOADLIBRARY is used with MATLAB file prototyping option, MATLAB generates an file called a prototype file. This file can then be used on subsequent calls to LOADLIBRARY in place of a header file. The prototyping needs to be done only once and not at run-time and hence would avoid the temporary file conflict that could be causing the error.