This error means that the library you are trying to call is not available in parallel workers.
Although, you have added required files to the parallel pool using 'AttachedFiles', the reason why this error is thrown is that those libraries are not loaded in parallel workers.
In order to have libraries available in those workers, please load libraries in each worker.
So, to fix this issue, please use loadlibrary to load libraries in each worker. clear all;
addpath(fullfile(matlabroot,'extern','examples','shrlib'))
struct.p1 = 4; struct.p2 = 7.3; struct.p3 = -290;
parpool('AttachedFiles',{'shrlibsample.mexw64','shrlibsample.h','shrlibsample.c', 'shrhelp.h'});
parfor i=1:4
if ~libisloaded('shrlibsample')
loadlibrary('shrlibsample')
end
[res,st] = calllib('shrlibsample','addStructByRef',struct);
end
unloadlibrary shrlibsample
Best Answer