필터 지우기
필터 지우기

How to set prefdir for parpool workers?

조회 수: 2 (최근 30일)
Geoffrey Aguirre
Geoffrey Aguirre 2017년 7월 16일
답변: Faiz Gouri 2017년 7월 21일
I am running parpool jobs with 10 workers under 2016b on my Mac (Mac Pro “Twelve Core”; 3.06 GHz 6 Core Xeon X5675 x2).
Initial jobs run without error. Over time, however, workers begin to fail with the error:
Error using prefutils>loadPrefs (line 42)
Unable to read MAT-file /Users/myname/Library/Application
Support/MathWorks/MATLAB/R2016b/matlabprefs.mat. File might be corrupt.
After some searching, I found these links. They advise changing the Matlab prefdir prior to starting a parpool job so as to avoid write conflicts within the prefs file:
This advice, however, seems to regard the situation in which multiple parpools are running concurrently.
More generally, I am unable to determine how I would arrange for each worker in a parpool to start with its own, separate prefdir, and if this is even needed to fix the error that I am encountering.
Thanks for any help.

채택된 답변

Faiz Gouri
Faiz Gouri 2017년 7월 21일
This error occurs when multiple MATLAB workers attempt to access the matlabprefs.mat file simultaneously. Here is a sample code to reproduce this issue:
function parTest
if matlabpool('size')==0
matlabpool('open');
end
parfor i=1:10
pause(randn(1));
setpref('parTest','test','test');
end %parfor
end %function parTest
To avoid this problem, set preferences using "pctRunOnAll" , before the parfor loop.
function parTest
if matlabpool('size')==0
matlabpool('open');
end
pctRunOnAll setpref('parTest','test','test');
parfor i=1:10
...parfor statements go here...
end
end %function parTest
Alternatively, the problem can be avoided by increasing the pause time from "pause(randn(1))" to "pause(randn(i/100))" , where 'i' is the parfor counter variable.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by