Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How can I store dates as arrays for further process when using Matlab GPU computing?
조회 수: 1 (최근 30일)
이전 댓글 표시
In the following attached code, I would like to record the variable Z in the while loop as array for further process, for example, finding the max value of Z in the array. But the dynamic array is not supported in the arrayfun for GPU computing. How to solve this problem?
function test_GPU_computing
maxIterations=500;
gridSize=1500;
xlim=[-0.75, -0.73];
ylim=[ 0.12, 0.14];
t=tic();
x=gpuArray.linspace( xlim(1), xlim(2), gridSize );
y=gpuArray.linspace( ylim(1), ylim(2), gridSize );
[xGrid,yGrid] = meshgrid( x, y );
count=arrayfun( @tar_fun,xGrid, yGrid, maxIterations );
count=gather(count);
gpuArrayfunTime=toc(t)
figure(3)
imagesc(x,y,count)
reset(gpuDevice(1))
function count=tar_fun(x0,y0,maxIterations)
z0=complex(x0,y0);
z=z0;
count=1;
while (count <= maxIterations) && (abs(z) <= 2)
count=count+1;
z=z*z+z0;
end
count=log(count);
댓글 수: 0
답변 (2개)
Walter Roberson
2018년 12월 15일
It does not need to be dynamic. You have maxIterations, so you can create it that size. When you need the "dynamic" version of it, index to the number actually used.
댓글 수: 3
Walter Roberson
2018년 12월 17일
Unfortunately my OS is too old to support the CUDA driver needed for R2018b :(
Edric Ellis
2018년 12월 17일
If you know the reduction operation you wish to perform on z, then you might be able to update a "running total" as the while loop proceeds, like so:
function [count,maxZ]=tar_fun(x0,y0,maxIterations)
z0=complex(x0,y0);
z=z0;
count=1;
% Initialize maxZ
maxZ = complex(0);
while (count <= maxIterations) && (abs(z) <= 2)
z=z*z+z0;
% Update the value of maxZ
if count == 1 || abs(z) > abs(maxZ)
maxZ = z;
end
count=count+1;
end
count=log(count);
댓글 수: 1
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!