simulating in parfor and geting a vector

6 visualizaciones (últimos 30 días)
Besi Sejdijaj
Besi Sejdijaj el 22 de Jun. de 2017
Respondida: Edric Ellis el 22 de Jun. de 2017
I'm trying to speed up my simulation by incorporating parfor, but I do not seem able to return vectors. what basically will happen is that I define a system of odes (lorenz equations) and every parfor iteration would than just have a different set of initial conditions and calculate a path of like 100 steps. I use convhull to get the volume of each new sphere and save those in a vector and I want to do some postprocessing on this matrix of vectors.
paths = 5;
o=10;
b=8/3;
r = 28;
dt=0.001;
radius = 10^-10;
volumedata = zeros(1020, 1020);
parfor i = 1:paths
volumedataa=[];
%random location and initializing
p=35*rand;
j=35*rand;
k=35*rand;
[x,y,z]=sphere(10);
xpar=radius.*x(:)+p;ypar=radius.*y(:)+j;zpar=radius.*z(:)+k;
volumeworkerdata = [];
for j = 1:100
%next location for all points
xpar=xpar+(o.*(ypar-xpar)).*dt;
ypar=ypar+(r.*xpar-ypar-xpar.*zpar).*dt;
zpar=zpar+(xpar.*ypar-zpar.*b).*dt;
%find volume
v=[xpar ypar zpar];
[tri, volume] = convhull(v);
volumeworkerdata = [volumeworkerdata volume];
end
volumedata(i,:) = volumeworkerdata;
end
I keep getting errors and was hopeing that one of you would know how to get this working or if there is a better way to do this in parallel

Respuestas (1)

Edric Ellis
Edric Ellis el 22 de Jun. de 2017
It looks like your volumeworkerdata array isn't the right size to assign into a row of volumedata. I would make the following changes:
% replace:
volumeworkerdata = [];
% with
volumeworkerdata = zeros(1, 1020);
And also:
% replace:
volumeworkerdata = [volumeworkerdata volume];
% with:
volumeworkerdata(j) = volume;
It looks like your inner for loop might not have the correct bounds.

Community Treasure Hunt

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

Start Hunting!

Translated by