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, 500000, 0, 1, 0 ); toc
Elapsed time is 0.064764 seconds.
So.. great victory for ParallelAccelerator.jl?
On Wednesday, October 21, 2015 at 6:46:00 PM UTC+2, Stefan Karpinski wrote:
>
> On Tue, Oct 20, 2015 at 1:07 PM, Gabriel Gellner <[email protected]
> <javascript:>> wrote:
>
>> Is it possible to tell Julia to run the vectorized code in parallel?
>> Looking at the documentation I see that you can do it easily for the looped
>> version but is there a macro or something to pass the vectorized version so
>> that is becomes parallel?
>>
>
> Not yet but once we introduce threads to the language, it will be.
>