Numerical integration with the GPU? Trapz appears to be unsupported in arrayfun, are there any alternatives?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
PetterS
am 19 Mär. 2015
Bearbeitet: Edric Ellis
am 20 Mär. 2015
I’ve recently discovered GPU computing in Matlab and it’s been helping me a lot with speeding up slow calculations, so I want to implement it wherever I can now. I have been sending things to the GPU by creating a function file of what I want to calculate and then calling it with arrayfun. But I can’t figure out how to send this slow formula to the GPU:
for minute=1:1440
for beta = 1:181
q=trapz(TotalTilted(minute,beta,:));
Amp(minute,beta,:)=TotalTilted(minute,beta,:)*IntegratedRadiation(minute,beta)/q;
end
end
Whatever I have been trying so far it’s been telling me: “argument contains unsupported or unknown function 'trapz'”
Like the GPU doesn’t support trapz, but according to the documentation I’ve seen trapz should be possible on the GPU: http://www.mathworks.com/help/distcomp/run-built-in-functions-on-a-gpu.html
However, from what I can see trapz is not listed under supported functions for arrayfun which I suspect could be the problem. Is there a different way to do numerical integration with arrayfun? Or does anyone know how I could go about calculating this formula on the GPU with a different approach other than arrayfun?
0 Kommentare
Akzeptierte Antwort
Edric Ellis
am 20 Mär. 2015
Bearbeitet: Edric Ellis
am 20 Mär. 2015
In this case, I think you can simply use the vectorized version of trapz, and then apply arrayfun to expand IntegratedRadiation and q in the third dimension:
q = trapz(TotalTilted, 3);
Amp = arrayfun(@(a, b, c) a * b / c, TotalTilted, IntegratedRadiation, q);
2 Kommentare
Edric Ellis
am 20 Mär. 2015
Bearbeitet: Edric Ellis
am 20 Mär. 2015
Ah sorry, you're quite right. Actually, you can simply use arrayfun here. I'll update the answer - arrayfun on the GPU performs the dimension-expansion that bsxfun normally does - so in fact it operates like a generalisation of bsxfun. On the CPU, this dimension-expansion doesn't happen, so you need to use bsxfun for functions of two variables, or repmat. Actually, if your data was on the CPU, in this case you could do simply:
q2 = IntegratedRadiation ./ q;
Amp = bsxfun(@times, TotalTilted, q2);
On the GPU you're probably better off with the single arrayfun call.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!