Hello,
I am newbie to Julia and I was testing Julia for the computational complexity of small program, as listed on https://julialang.org/.
I run the same program in sequential loop and surprisingly, at least to me, the sequential computing output quickly.
The screen shot of both formats with elapsed time is shown as followings.
Using tic() and toc() will measure compile time. One should use BenchmarkTools.jl.
Note also that these two programs are not equivalent. The parallel form performs a summation (since you’ve inserted a (+)), while the sequential form does not.
The codes don’t do the same thing. The parallel code is reducing (summing up) the results of rand on nheads. Th sequetial code is just generating random numbers and not storing it or summing it…
Also, to time things properly in Julia you should put your code in a function, call it once, so it gets compiled and then time.
I better way to time a function f would be to use the @time macro. Like this:
@time f()
EDIT: A true better way is to use the Benchmark tools as said above.
Yes, I mistakenly forget to count the number of heads in writing the sequential version.
The parallel code for counting the number of heads, the code @ https://julialang.org/, completes the execution in 2.323782322 seconds on quadcore i5-6300u. The sequential one completes in 2.459187005 seconds. These figures are obtained using tic, toc routine.
I shall make use of the BenchmarkTools as I learn the tools.
Anyway, thanks all of you for your kind support.
asif
But - are you adding processes via addprocs when you run the parallel code? If not, all you’re seeing is the overhead of setting up a parallel job to run on a single processor.
Dear sbromberger I forget you mention about the function in your very first post.
However, I perceived that writing @parallel shall automatically distribute the processing across all of the available CPU.
Anyway I shall look at the function to use in the future.
Thank you sbromberger for your time and valued comments.