On Oct 13, 11:00 am, Vince Hradil <vincehra...@gmail.com> wrote:
> On Oct 13, 10:08 am, Vince Hradil <vincehra...@gmail.com> wrote:
>
>> On Oct 13, 9:44 am, arp...@gmail.com wrote:
>
>>> It seems that very large matrix, e.g.1.0e6*1.0e5*100 operations, such
>>> as multiplication and matrix multiplication, in IDL is very slow.
>>> Anyone know how to speed up large matrix operations ?
>
>> Multiplication should be pretty fast. Matrix multiplication can be
>> slow if you have to transpose the matrices. This can be sped up by
>> using MatrixMultiply() instead of # or ##. Perhaps Temporary() can be
>> used to avoid allocation of extra memory. I think David has the best
>> ideas, though.
>
> oops, that should be MATRIX_MULTIPY()
So much for that theory...
Hardware:
IDL> print, !version
{ x86 Win32 Windows Microsoft Windows 7.0 Oct 25 2007 32 64}
Results:
% TEST: Allocating A array
% TEST: took 0.14000010 sec
% TEST: Allocating B array
% TEST: took 0.21899986 sec
% TEST: A#B
% TEST: took 40.878000 sec
% TEST: matrix_multipy(A,B)
% TEST: took 42.284000 sec
% TEST: transpose(A)#B
% TEST: took 42.645000 sec
% TEST: matrix_multipy(A,B,/atranspose)
% TEST: took 43.449000 sec
% TEST: transpose(temporary(A))#B
% TEST: took 43.387000 sec
% TEST: matrix_multipy(temporary(A),B,/atranspose)
% TEST: took 50.029000 sec
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;
pro test
nel = 2000L
t0 = systime(1)
message, 'Allocating A array', /info
a = randomu(seed,[nel,nel])
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
t0 = systime(1)
message, 'Allocating B array', /info
b = randomu(seed,[nel,nel])
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
t0 = systime(1)
message, 'A#B', /info
c = a#b
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
t0 = systime(1)
message, 'matrix_multipy(A,B)', /info
c = matrix_multiply(a,b)
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
t0 = systime(1)
message, 'transpose(A)#B', /info
c = transpose(a)#b
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
t0 = systime(1)
message, 'matrix_multipy(A,B,/atranspose)', /info
c = matrix_multiply(a,b,/atranspose)
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
ahold = a
t0 = systime(1)
message, 'transpose(temporary(A))#B', /info
c = transpose(temporary(a))#b
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
a = ahold
t0 = systime(1)
message, 'matrix_multipy(temporary(A),B,/atranspose)', /info
c = matrix_multiply(temporary(a),b,/atranspose)
message, 'took '+strtrim(systime(1)-t0,2)+' sec', /info
return
end
|