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