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.
Matrix Dimension Error with Parfor
3 次查看(过去 30 天)
显示 更早的评论
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;
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!