Azzera filtri
Azzera filtri

Matrix Dimension Error with Parfor

9 visualizzazioni (ultimi 30 giorni)
Tricia
Tricia il 19 Mar 2012
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;

Risposte (1)

Edric Ellis
Edric Ellis il 20 Mar 2012
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.

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by