Use of parfor to reduce computational time

1 次查看(过去 30 天)
I have a function with 100000 element array and i want to use parfor loop to reduce computaional time. Here is the code
global allNucleiDrops;
if (~isempty(allNucleiDrops))
nMax = length(allNucleiDrops);
for nCount = 1:1:nMax
index = allNucleiDrops(nCount);
nMolecules = Type_3(index);
if (nMolecules > 1 )
tspan = [tInitial tFinal];
oldSize = pSize(index);
oldVol = nMolecules*pP.volumeOfMolecule;
conc = (nMolecules/c.NA)/dP.volume;
[t,N] = ode45(@(t,N) 4*pi*pP.diffusivity*c.NA*pP.volumeOfMolecule*conc*((3*oldVol)/(4*pi))^(1/3), tspan, oldVol);
tLenght = length(N(:,1));
for tCount = tLenght:-1:1
newVol = N(tCount);
newSize = newVol/pP.volumeOfMolecule;
changeMolecule = newSize-oldSize;
if (changeMolecule > 0)
if (changeMolecule <= nMolecules)
pSize(index) = newSize;
Type_3(index) = Type_3(index) - changeMolecule;
break;
end
end
end
clear N t;
end
end
end
  7 个评论
Walter Roberson
Walter Roberson 2019-8-28
Because you can calculate the ode analytically you can calculate the value you need instead of looping to find it.
Walter Roberson
Walter Roberson 2019-8-29
newSize = oldSize at tFinal =
1/12*(2*Pi^(2/3)*oldVol^(1/3)*conc*6^(1/3)*pP^2*diffusivity*c*NA*
volumeOfMolecule*tInitial+oldSize*pP.volumeOfMolecule-oldVol)*6^(2/3)/Pi^(2/3)/
oldVol^(1/3)/conc/pP^2/diffusivity/c/NA/volumeOfMolecule

请先登录,再进行评论。

回答(0 个)

类别

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