How to have multiple matlab instances access MEX function files
4 views (last 30 days)
Show older comments
Christopher Grose
on 8 Dec 2018
Answered: James Tursa
on 8 Dec 2018
I am using C/C++ based MEX files to accelerate some matlab functions. However, a problem is that my codes are ultimately meant to run in parallel with multiple matlab instances on shared networks. In particular, my codes need to be run many times but with different input parameters, so the same MEX file needs to be loaded with each MATLAB instance. With this, I encounter the following type of error:
Error using mex
LINK : fatal error LNK1104: cannot open file 'biharmonicPaddedC2.mexw64'
So the problem is that multiple MATLAB instances are not allowed to access the same mex file. The only way I can think of getting around this is by making separate identical C source files, but with different file names, for each matlab instance. Is there an easier way??
I am using Windows 10 and R2018a, although I would need a solution that would also work on linux systems.
0 Comments
Accepted Answer
James Tursa
on 8 Dec 2018
Multiple instances of MATLAB can certainly access and run the same mex routine. But based on the fact that you have a LINK error, it looks like you are trying to compile the mex routine in one instance while another instace is using the file. This will cause the problems you are observing since you are trying to overwrite a file that is in use. The solution is to compile the routine ahead of time, and then let your multiple instances of MATLAB access the pre-compiled mex routine. Is there a reason you are trying to compile the mex routine in each instance?
0 Comments
More Answers (0)
See Also
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) 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!