Effacer les filtres
Effacer les filtres

Matrix Dimension Error with Parfor

9 vues (au cours des 30 derniers jours)
Tricia
Tricia le 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;

Réponses (1)

Edric Ellis
Edric Ellis le 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.

Catégories

En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by