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

1 次查看(过去 30 天)
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.

回答(1 个)

Swatantra Mahato
Swatantra Mahato 2021-7-9
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 个评论
Kristen Bruchko
Kristen Bruchko 2021-8-10
编辑:Kristen Bruchko 2021-8-10
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Write C++ Functions Callable from MATLAB (MEX Files) 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by