MATLAB R2016a 無法啓動並行池

最近在用 MATLAB 跑仿真,但是不知怎麼回事,之前並行計算 parfor 用的好好的,昨天突然就不能用了,一直報錯無法啓動並行池,報錯原因還特別奇怪。在網上找了一大堆教程互相抄來抄去,沒一個能用的。最後還是在官網論壇找到了一個答案成功解決問題。

先給我的博客打個廣告,歡迎光臨
https://glooow1024.github.io/
https://glooow.gitee.io/

1. 問題描述

我用的是 MATLAB R2016a,當我運行帶有 parfor 的代碼時,左下角會有如下提示,表示無法啓動並行池,而正常情況應該是右邊這幅圖

報錯情況 正常情況
在這裏插入圖片描述 在這裏插入圖片描述

當我點擊查看 more details 時,會報如下的錯誤,參數不對?這不是自帶函數嗎?

在這裏插入圖片描述

然後我參考了網上的教程,查看 Home->Parallel->Manage Cluster Profiles,但是網上教程說如果是下面這個樣子

我的錯誤是這樣的 網上只有這樣的
在這裏插入圖片描述 在這裏插入圖片描述

很顯然我的第一步 cluster connection test(parcluster) 就 fail 了,我按照網上的說法運行下面這句話也沒用

distcomp.feature( 'LocalUseMpiexec', false )

最後幸運的是在官網論壇找到了一篇可以解決我的問題的回答,下面給出解決方法。

2. 解決方法

參考鏈接:https://www.mathworks.com/matlabcentral/answers/92124-why-am-i-unable-to-use-parpool-with-the-local-scheduler-or-validate-my-local-configuration-of-parall

我用 第 5 步(Clear the local scheduler data folder) 解決了我的問題,不過下面還是貼出來完整的 debug 過程

2.1 檢查 license

運行命令檢查 Parallel Computing Toolbox 的 license 正確

license checkout Distrib_Computing_Toolbox

如果得到的回答是 ans=1,則說明 license 沒問題。否則需要添加 license。

2.2 確保你的 MATLAB 版本與 PCT 版本匹配

運行命令 ver 查看,如果不匹配則無法使用。這種情況 … 建議重裝。

2.3 Disable local mpiexec

運行下面的命令

distcomp.feature( 'LocalUseMpiexec', false )

這也是網上絕大部分教程的方法,不過對我就不適用,如果對你也不適用的話,往下繼續看。

2.4 Check your local scheduler configuration

這一部分我貼出原文吧,大概是說如果你修改了默認配置,則可以重置他們。

There are no changes that need to be made in order to use the local scheduler, but if you have made changes to the configuration, you may want to reset these. This can be done by creating a new local scheduler configuration. To do so,

  1. Go to the Parallel menu in MATLAB and select “Manage Cluster Profiles…” (“Manage Configurations…” for R2011b or earlier)
  2. Click on Add > Custom > Local (for older releases: From the File menu, select New > Local Configuration)
  3. Click the radio option in the default column to set this as the default configuration

Once complete, close the Manage Configuration windows and try again.

2.5 Clear the local scheduler data folder

出現無法啓動並行池的原因也可能是本地的 local scheduler data 有問題,可以把他刪除。刪除的步驟爲

  1. 運行命令

    >>prefdir
    ans =
    C:\Users\Administrator\AppData\Roaming\MathWorks\MATLAB\R2016a
    

    然後我們就可以在路徑 C:\Users\Administrator\AppData\Roaming\MathWorks\MATLAB 下面找到文件夾 local_scheduler_data 或者 local_cluster_jobs

  2. 關閉 MATLAB

  3. 將上面的文件夾 local_scheduler_data 或者 local_cluster_jobs 重命名或者直接刪除

  4. 重啓 MATLAB,試着開啓並行池

我做完這一步就能解決問題了,如果還不行,原文還給出了其他可能的原因,後面的我就直接貼出來原文了。

2.6 Ensure that hostname resolution works on your computer

In order to use the local scheduler, your computer’s own hostname must be resolvable. To confirm this, run the following command in MATLAB:

!hostname

This will give you your computer’s hostname. You must be able to resolve this hostname to the computer’s IP address. To test this you can run:

!ping <hostname>

Where is the output of the hostname command above. If the results indicate the wrong IP address or say that your computer is an “unknown host”, there is a network issue on your computer that needs to be resolved in order to use the local scheduler. In that case, ask your network administrator for help.

2.7 Check to see if you have a startup.m file on the MATLAB path

It may be causing an error, even if it works fine in MATLAB when run as code.

To see if you have a startup.m file on the MATLAB path run the below command in MATLAB:

which startup.m

Either delete or move that file outside of the MATLAB path.

If you are still unable to run parpool, run a validation of your local scheduler configuration and submit this to support. To validate:

  1. Go to the Parallel menu in MATLAB and select “Manage Cluster Profiles…” (“Manage Configurations…” for R2011b or earlier)
  2. Highlight your local scheduler configuration and click the “Validate” button (“Start Validation” for R201b or earlier)
  3. Once the validation completes, click the “details” link to see the results

You can then forward your output of validation, the results of the tests below, and your license number to support here: http://www.mathworks.com/support/contact_us/index.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章