在查看一篇论文公布的Matlab源代码时,有这么一行代码:
matlabpool('open',8);
代码运行到此时,会出现错误:
Failed to open matlabpool. (For information in addition to the causing error, validate the configuration 'local' in the Configurations Manager.)
此错误提示并不太明晰,但是matlab命令行窗口又会提示:
Caused by:
Error using distcomp.interactiveclient/start (line 88)
Failed to start matlabpool.
This is caused by:
You requested a minimum of 8 workers, but the scheduler's ClusterSize property is currently set to allow
a maximum of 6 workers. To run a parallel job on more workers than this,increase the ClusterSize property setting in the 'local' configuration using the Configurations Manager. The default value for ClusterSize with a local scheduler is the number of cores on the local machine.
至此,问题已经很清楚,默认最大只有6个worker(不知道准确的翻译应该是什么),而此时需要8个worker.
二:解决方法
打开菜单Parallel--->Manage Configurations,选中local,右键选择Properties,会出现如下窗口:
图中红色圈出的就是我们需要更改的地方,此处我们填上8,之后一切正常。
三:题外话
如何直观的看出并行,我做了一个测试:
在未开启matlabpool时,查看进程管理,只有一个MATLAB.exe,但是在开启matlabpool后,有9个MATLAB.exe.!!!如下图所示:
每个都是将近100多M,看样子,落后的机器真是跑不起来了啊。
而且在主窗口的右下角还有一个图标,如下图所示:
鼠标放上去之后会提示:MATLAB pool open with 8 labs.
注:matlab环境:Win 7 64 bit + Matlab R2011b.
四:关于matlabpool
查看matlab的帮助,有如下一段:
Open or close a pool of MATLAB sessions for parallel computation matlabpool enables the parallel language features within the MATLAB language (e.g., parfor) by starting a parallel job that connects this MATLAB client session with a number of labs.