Since you are on -dev you could try the new @inline macro and see if that helps.
On Thu, Oct 2, 2014 at 4:51 PM, Jürgen Bohnert <[email protected]> wrote: > Hi everyone, > > I'm new to using julia and I would be grateful if anyone could shed some > light on the following performance-issue that I cannot explain. > For some reason wrapping 2 for-loops into a separate function and then > calling that function is 2 times slower than executing the for-loops > directly. > > *My goal:* > Perform timeconsuming but easily parallelizable operation '*operator*' > over moderate/large parameter-space on a SINGLE Machine with multiple > cores. -> Put loops into function and call '*pmap*' on that. > > function operator(x::Float64, y::Float64, extraparameters::Float64 ...) > # ... Does something > # returns Float64 scalar > end > > The function '*operator*' works like a charm and fast. > > *What I did:* > Execution over a parameter-space: *x::Array{Float64, 1}, > y::Array{Float64, 1}* > via the function '*loops_simple*' (below) > > function loops_simple(different_arguments ...) > > # generate x::Array{Float64, 1} and y::Array{Float64, 1} and > extraparameters > # preallocate output container > output = Array(Float64, (length(x), length(y))) > > t = time() > > for i=1:length(y) > for j=1:length(x) > output[j,i] = operator(x[j], y[i], extraparameters ...) > end > end > > t = time() - t > println("time taken: $t") > > return output > end > > This runs really fast as expected. Trouble comes as soon as I stuff the > loops into a separate function '*wrapper*' (for easier parallel execution > but I didn't get that far.). > > function wrapper(x::Array{Float64, 1}, y::Array{Float64, 1}, > extraparameters::Float64 ...) > output = Array(Float64, (length(x), length(y))) > for i=1:length(y) > for j=1:length(x) > output[j,i] = operator (x[j], y[i], extraparameters ...) > end > end > end > > > Now calling: > > function loops_wrapped(different_arguments ...) > # generate x::Array{Float64, 1} and y::Array{Float64, 1} and > extraparameters > t = time() > output = wrapper (x, y, extraparameters ...) > t = time() - t > println("time taken: $t") > > return output > end > > the process ends up taking twice the time of the '*loops_simple*' case. > Can anyone explain what I'm doing wrong? > > Thanks in advance. > > I'm running julia Version 0.4.0-dev+584; Commit 114abf4; x86_64-linux-gnu >
