Btw it is really cool to see julia running at 400% CPU when running a list comprehension.
I did some more benchmarks with larger N to reduce the noise a bit and the difference is actually not that great between Matlab and Julia. However, tying with Matlabs parallellized vectorized maps is great imho. julia> @time h, f = Jakes_Flat( 926, 1e-6, 5000000, 0, 1, 0 ) 0.585940 seconds (153 allocations: 495.918 MB, 12.47% gc time) ( >> tic; Jakes_Flat( 926, 1E-6, 5000000, 0, 1, 0 ); toc Elapsed time is 0.609867 seconds. On Wednesday, October 21, 2015 at 10:17:18 PM UTC+2, Kristoffer Carlsson wrote: > > For fun (and science) I tried out the new package > https://github.com/IntelLabs/ParallelAccelerator.jl for this problem. > > Here is the code: > > function Jakes_Flat( fd, Ts, Ns, t0 = 0, E0 = 1, phi_N = 0 ) > # Inputs: > # > # Outputs: > N0 = 8; # As suggested by Jakes > N = 4*N0+2; # An accurate approximation > wd = 2*pi*fd; # Maximum Doppler frequency > > ts = collect(t0 + (0:Ns-1)*Ts) > tf = ts[end] + Ts; > Ns = collect(1:N0) > > coswt = [ cosvec(ts, wd)'; cosmat(ts, Ns, wd, N) ] > h = E0/sqrt(2*N0+1)*exp(im*[ phi_N pi/(N0+1)*(1:N0)']) * coswt > return h, tf; > end > > @acc function cosvec(ts, wd) > Float64[sqrt(2)*cos(wd*t) for t in ts] > end > > @acc function cosmat(ts, Ns, wd, N) > Float64[2*cos(wd*cos(2*pi/N*n)*t) for n in Ns, t in ts] > end > > > Benchmarking this I get: > > julia> @time Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 ) > 0.004779 seconds (115 allocations: 4.965 MB) > > and without calling the accelerated functions (by putting @noacc in front > of the function calls, I get): > > julia> @time Jakes_Flat_noacc( 926, 1e-6, 50000, 0, 1, 0 ) > 0.019072 seconds (75 allocations: 8.396 MB) > > The matlab code on my computer runs at: > > >> tic; Jakes_Flat( 926, 1E-6, 50000, 0, 1, 0 ); toc > Elapsed time is 0.009936 seconds. > > So.. great victory for ParallelAccelerator.jl? > > On Sunday, October 18, 2015 at 1:17:50 PM UTC+2, Vishnu Raj wrote: >> >> Although Julia homepage shows using Julia over Matlab gains more in >> performance, my experience is quite opposite. >> I was trying to simulate channel evolution using Jakes Model for wireless >> communication system. >> >> Matlab code is: >> function [ h, tf ] = Jakes_Flat( fd, Ts, Ns, t0, E0, phi_N ) >> %JAKES_FLAT >> % Inputs: >> % fd, Ts, Ns : Doppler frequency, sampling time, number of samples >> % t0, E0 : initial time, channel power >> % phi_N : initial phase of the maximum Doppler frequeny >> % sinusoid >> % >> % Outputs: >> % h, tf : complex fading vector, current time >> >> if nargin < 6, phi_N = 0; end >> if nargin < 5, E0 = 1; end >> if nargin < 4, t0 = 0; end >> >> N0 = 8; % As suggested by Jakes >> N = 4*N0 + 2; % an accurate approximation >> wd = 2*pi*fd; % Maximum Doppler frequency[rad] >> t = t0 + [0:Ns-1]*Ts; % Time vector >> tf = t(end) + Ts; % Final time >> coswt = [ sqrt(2)*cos(wd*t); 2*cos(wd*cos(2*pi/N*[1:N0]')*t) ]; >> h = E0/sqrt(2*N0+1)*exp(j*[phi_N pi/(N0+1)*[1:N0]])*coswt; >> end >> Enter code here... >> >> My call results in : >> >> tic; Jakes_Flat( 926, 1E-6, 50000, 0, 1, 0 ); toc >> Elapsed time is 0.008357 seconds. >> >> >> My corresponding Julia code is >> function Jakes_Flat( fd, Ts, Ns, t0 = 0, E0 = 1, phi_N = 0 ) >> # Inputs: >> # >> # Outputs: >> N0 = 8; # As suggested by Jakes >> N = 4*N0+2; # An accurate approximation >> wd = 2*pi*fd; # Maximum Doppler frequency >> t = t0 + [0:Ns-1]*Ts; >> tf = t[end] + Ts; >> coswt = [ sqrt(2)*cos(wd*t'); 2*cos(wd*cos(2*pi/N*[1:N0])*t') ] >> h = E0/sqrt(2*N0+1)*exp(im*[ phi_N pi/(N0+1)*[1:N0]']) * coswt >> return h, tf; >> end >> # Saved this as "jakes_model.jl" >> >> >> My first call results in >> julia> include( "jakes_model.jl" ) >> Jakes_Flat (generic function with 4 methods) >> >> julia> @time Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 ) >> elapsed time: 0.65922234 seconds (61018916 bytes allocated) >> >> julia> @time Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 ) >> elapsed time: 0.042468906 seconds (17204712 bytes allocated, 63.06% gc >> time) >> >> For first execution, Julia is taking huge amount of time. On second call, >> even though Julia take considerably less(0.042468906 sec) than first( >> 0.65922234 sec), it's still much higher to Matlab(0.008357 sec). >> I'm using Matlab R2014b and Julia v0.3.10 on Mac OSX10.10. >> >> - vish >> >
