필터 지우기
필터 지우기

Incorrect results from parfor

조회 수: 3 (최근 30일)
Anthony
Anthony 2014년 1월 6일
댓글: Anthony 2014년 1월 9일
hi, thanks in advance for your help. i am constructing a function which contains a parfor loop, which i am unfamiliar with. Although it runs, the results are incorrect; if i replace the 'parfor' with 'for' (nothing else changed), then the results are correct, with much longer running time. fun_wn and fun_idf_HS are two user-defined functions. The new function just prints out their values when i and j satisfies certain condition. (symptom: x and y_sp{j} are printed out correctly, but feval(fun_1,x,y_sp{j}) and feval(fun_2,y_sp{j}) are not.) thanks a looot!
function output = fun_wn_HS4(x)
global d_HS4_o prescore_HS4 vocabulary_HS4
fun_1 = @fun_wn;
fun_2 = @fun_idf_HS;
output = zeros(size(d_HS4_o,1),1);
parfor i=1:size(d_HS4_o,1)
y_sp = strtrim(strsplit(d_HS4_o{i},' '));
for j=1:length(y_sp)
if i==506 && j==13
x
y_sp{j}
feval(fun_1,x,y_sp{j})
feval(fun_2,y_sp{j})
end
end
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 7일
Unless the user is passing function names to you, use
fun_1(x,y_sp{j});
fun_2{y_sp{j});
instead of using feval()
  댓글 수: 5
Edric Ellis
Edric Ellis 2014년 1월 7일
GLOBAL data is not automatically transferred from the MATLAB client to the workers running the body of the PARFOR loop. So, you either need to do this manually, or ideally you'd re-work the functions to rely on explicit input arguments.
Anthony
Anthony 2014년 1월 9일
i see... will try, thanks a lot!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by