[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: implement a SOR like routine efficiently
From: |
Przemek Klosowski |
Subject: |
Re: implement a SOR like routine efficiently |
Date: |
Tue, 16 Nov 2004 10:40:17 -0500 (EST) |
I need to implement the following loop efficiently:
for i = 2:n-1
for j = 2:n-1
a(i,j) = a(i-1,j) + a(i+1,j) + a(i,j+1) + a(i,j-1)
end
end
The loop is not vectorizable, as it has a carried dependence. If I run
this loop as it is, it is very slow ( in my program n is 256 and
Well, as written, the loop is not vectorizable; but the expression is
suspiciously close to an 'averaging' kernel. I just wanted you to
confirm that a convolution of a and [0 1 0; 1 0 1; 0 1 0] would not be
an acceptable solution:
a(2:n-1,2:n-1) = conv2(a, [0 1 0; 1 0 1; 0 1 0],'valid');
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------