필터 지우기
필터 지우기

Matrix Dimension Error with Parfor

조회 수: 9 (최근 30일)
Tricia
Tricia 2012년 3월 19일
I am running the following code
function output = replicateerror2(network,sample)
global stoich_matrix ngas
load(network,'stoich_matrix','BE_DFT','ngas');
load(sample,'sample_bound_low','sample_bound_up');
load('work\lhsfile','lhs');
[nspecies,nreact] = size(stoich_matrix);
[nparam,ndtst] = size(lhs);
range = sample_bound_up - sample_bound_low;
BE_DFT = BE_DFT;
lhs = lhs;
sample_bound_low = sample_bound_low;
output = zeros(nreact,ndtst);
parfor i = 1:ndtst
param = sample_bound_low + range.*lhs(:,i);
BE = [zeros(ngas,1); param(1:(nspecies-ngas-1)); 0];
BE_fit = BE - BE_DFT;
output(:,i) = microkin(BE_fit);
end
end
function test = microkin(BE_fit
global stoich_matrix
test = stoich_matrix'*BE_fit;
end
The code runs fine with a for loop or if there is no matlabpool open. However, when I open a matlab pool I get the following error:
Inner matrix dimensions must agree.
associated with the line
test = stoich_matrix'*BE_fit;

답변 (1개)

Edric Ellis
Edric Ellis 2012년 3월 20일
You cannot use GLOBAL data together with PARFOR in this way. The MATLAB workers in your pool are separate processes and therefore they have different GLOBAL workspaces. More details here. In particular, MATLAB's LOAD function is not "transparent" -that is, it causes variables to come into existence in a way that PARFOR cannot understand. I would suggest the following: place your PARFOR loop in another sub-function that takes as arguments 'stoich_matrix', 'ngas' etc., and stop using GLOBAL data.

카테고리

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