How can I plot multiple plots on the same figure using parfor
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I am running an FEA code and the plotting is what takes most of the time as I am plotting 13000 elements.
Basically, I am trying to leverage the parallel computing and the gpu to optimize the plotting of this example (simplified example):
tic
x = linspace(1,10);
parfor i=1:20
y(i,:)=x.^((i+1)/i);
end
figure
hold on
for i = 1:20
plot(x,y(i,:))
end
hold off
cputime=toc
I got the gpu running already by using gpuArray the following way:
tic
x = gpuArray(linspace(1,10));
parfor i=1:20
y(i,:)=x.^((i+1)/i);
end
figure
hold on
for i = 1:20
plot(x,y(i,:))
end
hold off
gputime=toc
but how do I use the parfor for the plot function?
if I do this:
tic
xx = linspace(1,10,1000);
parfor i=1:20
yy(i,:)=xx.^((i+1)/i);
end
figure
hold on
parfor i = 1:20
plot(xx,yy(i,:))
end
hold off
cpuparalleltime=toc
I get a empty figure
moreover, the fastest running code seems to consistently be the single threaded cpu task.
Thank you everybody
0 Kommentare
Antworten (1)
Walter Roberson
am 5 Dez. 2021
You cannot do that directly. The workers do not have access to the display, and also do not have concurrent access to the graphics objects already created.
What you can do is:
figs = cell(4,1);
parfor K = 1 : 4
figs{K} = figure();
ax = axes('Parent', figs{K});
h = plot(ax, rand(1,20));
end
This creates independent figures, but after the figures are created the figure structure (and all its children) are copied back to the client. At that point you can merge them all together by extracting the axes children and copyobj() them into the axes you want them all to appear in.
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!