Mexhost out of process crashed or destroyed outside of Matlab after 3 runs

7 views (last 30 days)
I am trying to run my mex function using the out of process matlab mexhost function. I am using the following wrapper to call my mex function.
function [t,y] = myfunction(x0,tspan)
persistent mh
if ~(isa(mh,'matlab.mex.MexHost') && isvalid(mh))
mh = mexhost;
end
[t,y] = feval(mh,"myfunctionMEX",x0,tspan);
end
I can use this wrapper 3 times before my function crashes and gives the error "Error executing C++ MEX function 'myfunctionMEX'. 'MATLABMexHost' with process ID '20172' crashed or was destroyed outside MATLAB." Can anyone help figure out why I can only run this a few times? I am trying to call it 4 times within the same script, but can only make it through 3 times without crashing. I am not calling clear or delete that would intentionally destroy the process.

Answers (1)

Swatantra Mahato
Swatantra Mahato on 9 Jul 2021
Hi Kristen,
This issue might be caused by a known bug where the MEX function out-of-process execution runs out of memory when called too frequently. You can find the bug report here
One possible workaround is to reduce the frequency at which the MEX function is being invoked. The goal is to buy enough time for the MEX process to free up memory at a rate that is sustainable. This can be done by calling "pause" shortly before or after each invocation of the MEX function.
Note that the duration may need to be adjusted to suit each individual application.
Hope this helps
  2 Comments
Kristen Bruchko
Kristen Bruchko on 10 Aug 2021
Edited: Kristen Bruchko on 10 Aug 2021
Unfortunately, the pause function does not seem to help, even if called for a few minutes between each mex function call. I also still see the problem if I am not using the out-of-process function.
Swatantra Mahato
Swatantra Mahato on 12 Aug 2021
Can you share the functions you are using so I can reproduce the issue at my end?
Thanks

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!