How to solve linear equation for 3 unkowns using SOR in GPU

2 次查看(过去 30 天)
I am trying to find the motion (u,v,w) for each pixel in my frame by solving the linear system Ax=b
A is a 3 by 3 ... each element for example A (1,1) is equivalent to the frame size ... let's say ( 512 X 512)
A = [ A B C ; D E F ; G H I]
x is unknown need to be estimated ( u,v,w) ... u , v and w should be ( 512 X 512)
b is a 3 by 1 matrix and each element is equivalent to the frame size as well
b= [ J K L]
I am trying to solve this system using the SOR iteration method so I have this provided function
problems:
-In this code I have to use omega = 1 otherwise I got the wrong answer totaly !
-How can I solve this system using the SOR iteration method?
-How can I improve it to use GPU to speed up?
Any assistance will be so appreciated
function [u,v,w,error]=SORstep(A,B,C,D,E,F,G,H,I,J,K,L,omega,du_temp,dv_temp,dw_temp) % du_temp, dv_temp, dw_temp previouse estimation
u=((1.0-omega).*du_temp)+(omega./A).*(J-(B.*dv_temp+C.*dw_temp));
v=((1.0-omega).*dv_temp)+(omega./E).*(K-(D.*u+F.*dw_temp));
w=((1.0-omega).*dw_temp)+(omega./I).*(L-(G.*u+H.*v));
error = norm([u;v;w]-[du_temp;dv_temp;dw_temp])./norm([u;v;w]);
end

回答(2 个)

Matt J
Matt J 2019-9-18
Not sure why you would be using an iterative method when an analytical solution is available.
A=gpuArray.rand(3,3,512^2);
b=gpuArray.rand(3,1,512^2);
x=pagefun(@mldivide, A,b);
u=reshape(x(1,:),512,512);
v=reshape(x(2,:),512,512);
w=reshape(x(3,:),512,512);
  2 个评论
Seereen
Seereen 2019-9-18
I need iteration because it is very big system! ... I have to solve 262144 equations .. right?
so I think iterative method help in this case
Matt J
Matt J 2019-9-18
The language of your post is confusing. You should not say your A matrix is 3x3 when it is in fact 262144 x 262144...

请先登录,再进行评论。


Matt J
Matt J 2019-9-19
If you have the Parallel Computing Toolbox, you can make all the variables in your SORstep function
A,B,C,D,E,F,G,H,I,J,K,L,omega,du_temp,dv_temp,dw_temp
into gpuArrays. Then, all the matrix arithmetic done in your SORstep function will be done on the GPU.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by