matlab(This error was detected while a MEX-file was running)

今天在运行caffe的matlab接口写的代码的时候。出现了一个问题:

"This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
...
A technical support engineer might contact you with further information.
MATLAB is exiting because of fatal error"

然后matlab就自己退出了。。。


在网上看了一些答案。大多是因为matlab已经过了试用阶段。或者遇到什么杀毒软件。或者matlab装的不成功。等等

但实际上,我是在linux下的server弄的matlab,不存在杀毒软件的问题。同时肯定也不存在装的不成功。因为,刚才还在用。。。而且,我从新打开matlab,写了简单的命令。说明matlab没有崩溃。

matlab(This error was detected while a MEX-file was running)_第1张图片

那时什么原因呢???这就奇了怪了。。。怎么简单的脚本能运行,复杂的就不行呢。难道是caffe除了问题?验证matcaffe没有问题。

我又从网上找了一些答案:有的说那是因为matlab访问了不该访问的内存。
于是,我top 了一下。发现没有matlab的任务(当下,其他用户没有用matlab软件,或者运行matlab程序)。
同时,从top信息中看到mem还有很多时avail状态啊。

matlab(This error was detected while a MEX-file was running)_第2张图片

但是,怎么简单的脚本能运行,复杂的就不行。提供了线索:很大程度时因为内存不行。我有查看了显存。果然,不出所料!!!显存已满。(我的显存每块4G,共4块卡)
matlab(This error was detected while a MEX-file was running)_第3张图片

  8 caffe.set_device(0);
  9 caffe.set_device(1);
 10 caffe.set_device(2);
 11 caffe.set_device(3);                                                                                                                                                    
 12 caffe.set_mode_gpu();

由于第0块显卡没有用,其他显卡有任务,因此我仅仅用第0块,修改之后

  8 caffe.set_device(0);
  9 %caffe.set_device(1);
 10 %caffe.set_device(2);
 11 %caffe.set_device(3);                                                                                                                                                    
 12 caffe.set_mode_gpu();

可以跑了。。。

你可能感兴趣的:(caffe,matlab)