Use of parfor to reduce computational time
1 view (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 28 Aug 2019
Because you can calculate the ode analytically you can calculate the value you need instead of looping to find it.
Walter Roberson
on 29 Aug 2019
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
Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!