MATLAB繪制曼德勃羅Mandelbrot集,并利用GPU加速
???? 本文主要參考MATLAB幫助文件,Illustrating Three approaches to GPU Computing: The Mandelbrot Set,也可在網(wǎng)頁https://ww2.mathworks.cn/help/parallel-computing/illustrating-three-approaches-to-gpu-computing-the-mandelbrot-set.html上看到同樣的內(nèi)容,代碼如下:
????? 本機配置:CPU AMD Ryzen5 3600,GPU:RTX 3060,在maxIterations = 500;gridSize = 2000;xlim = [-1.5, 0.6];ylim = [ -1.2, 1.2];的條件下,生成的圖片如下,計算耗時分別是9.89s,2.448s(4倍),0.232s(42.7倍),0.068s(144.6倍),

????? 可以用colormap函數(shù)改顏色,可選參數(shù)有parula,jet,hsv,hot,cool,spring,summer,
autumn,winter,gray,bone,copper,pink,lines,colorcube,prism,flag,white


count = log(count); 取對數(shù)運算不是必須,但能提高圖像對比度,不取對數(shù)的效果如下,可以看出周圍小分支的清晰度下降

pctdemo_processMandelbrotElement.cu、.m、.ptx···在MATLAB安裝路徑下,內(nèi)容分別如下:

????????使用GPU時容易遇到如下報錯:The CUDA driver must recompile the GPU libraries because your device is more recent than the libraries.Recompiling can take several minutes. Learn more.
????????來自MATLAB官方網(wǎng)站的解答(https://ww2.mathworks.cn/matlabcentral/answers/437756-how-can-i-recompile-the-gpu-libraries):
This is a known issue with CUDA 9.1 and the new Turing generation of GPUs. You don't need to do anything except ignore the initial warning or error.
There are multiple issues. The warning about recompiling of libraries is spurious and not relevant. The error from cublas is one-time only. And there is an equivalent error in cuDNN. A permanent workaround is to put the following into your startup.m file:
????? ?一共有兩個startup.m文件,分別是
C:\Program
Files\Polyspace\R2019a\toolbox\fixedpoint\fixedpointtool\+fxptui\Startup.m,
C:\Program
Files\Polyspace\R2019a\toolbox\matlab\external\interfaces\python\+python\+internal\startup.m,
????? 我在這兩個文件中都加了warning
off parallel:gpu:device:DeviceLibsNeedsRecompiling ……,然而沒用,警告還是會彈出。
????? 用其它形式的迭代公式生成的圖形。






