@kw_martin wrote:
I’ve been looking at some different filter approaches for analyzing ECG signals using Matlab and have recently implemented them in julia in order to get a speed improvement. I have not been seeing the expected improvements and have tracked the issue down to the time for multiplying complex matrices. I have made some simple examples in both cases to evaluate the times. The julia example is rough as I am new to julia.
#!/usr/local/bin/julia module TmMlt ENV["CMPLXROOT"] = "/home/martin/Dropbox/Matlab/Complex/KM_ComplexFilterToolbox" using MAT, LinearAlgebra, Printf, BenchmarkTools tms = zeros(Float64,2,1) f(a,b) = a*b for n = [64 128 256 512 1024] a = ones(Complex, n, n); b = ones(Complex, n, n); tm1 = time(); f(a,b); tm2 = time(); @printf("n: %u, time: %f\n",n,tm2 - tm1) end end n = 1024 a = ones(Complex, n, n); b = ones(Complex, n, n); @btime f(a,b)
which gave me:
julia> include("TmMlt.jl") WARNING: replacing module TmMlt. n: 64, time: 0.018154 n: 128, time: 0.238965 n: 256, time: 1.620080 n: 512, time: 13.005956 n: 1024, time: 126.109016 127.565 s (2152726530 allocations: 64.16 GiB)
The matlab script I ran was:
function tmMltplys() for n=[64 128 256 512 1024 2048 4096] fprintf('For n=%d ',n); a = rand(n,n) + j*rand(n,n); b = rand(n,n) + j*rand(n,n); c = mlt(a,b); end function c = mlt(a, b) % multiply two matrices tic c = a*b; toc end end
which gave:
>> tmMltplys For n=64 Elapsed time is 0.000240 seconds. For n=128 Elapsed time is 0.000493 seconds. For n=256 Elapsed time is 0.001726 seconds. For n=512 Elapsed time is 0.013201 seconds. For n=1024 Elapsed time is 0.150515 seconds. For n=2048 Elapsed time is 0.741310 seconds. For n=4096 Elapsed time is 5.980977 seconds. >>
I couldn’t go over n=1024 in julia as it took too long. I must be doing something drastically wrong as the julia times for multiplying two comlex matrices are over 1000 times longer than matlab times. I also coded a julia multiply using for loops; these times were very similar (slightly faster) than just using the simple function shown above. If anyone can help identify what I am doing wrong, it would be much appreciated. Thanks.
-Ken
Posts: 5
Participants: 4