Thanks for the comments! Based on both your comments, I've made the 
following changes:

   1. I eliminated the dictionary structure (I only did this as a matter of 
   organization). There are no longer any dictionaries, and those "parameters" 
   and "distributions" are all now passed directly as function arguments. 
   2. I eliminated the type declarations from my function arguments (since 
   there are no longer any dictionaries).  
   3. I surrounded the majority of the code with a "run_sim()" function. 
   Now, it looks like this:

include("dist_o_i.jl")
include("calc_net.jl")
include("update_w.jl")
include("set_up_sim.jl")
include("simulation.jl")

function run_sim( )
  include("set_up.jl")
  v1 = [-3 0.5 0.5]

  term_condition = false
  iter = 0

  while !term_condition

    v2 = [-1.5 0 1.5 0]

    s_array, w_array, b_array = simulation( v1, v2, D, T, I_val, max_b,
      w_max, gamma_val, controls, Prob_o, signals )

    iter = iter + 1

    if iter >= 1
      term_condition = true
    end

  end
end

@time run_sim()


Unfortunately, these adjustments have not changed the performance. Running 
twice, I got:

elapsed time: 39.365116756 seconds (20316825420 bytes allocated, 37.92% gc 
time)
elapsed time: 39.856962087 seconds (20239718784 bytes allocated, 38.50% gc 
time)

Spencer: Re: your point about running "simulation.jl" before timing 
it...yes. That's the reason I provided multiple "elapsed time" results, to 
show that I'm running the function a few times and getting the same 
performance. With my latest alterations, I'm running "@time run_sim()" 
multiple times, and seeing (roughly) the same performance each time. 

Any other ideas? Is there something about the matrix or vector 
multiplication that could be slowing it down? Maybe it has to do with the 
arrays in which I'm storing the data? 



On Saturday, September 19, 2015 at 1:18:54 PM UTC-5, Spencer Russell wrote:
>
> Hi Adam,
>
> Welome to Julia! 
>
> Just to check - are you calling your `simulation(…)` function before you 
> time it? Otherwise your timing will include the time it takes to compile 
> the function, which happens the first time it’s called with a given set of 
> argument types.
>
> Your `param` dict is of type (Any, Any), which means that the compiler 
> doesn’t know anything about the type of objects inside it. You’re doing a 
> lot of access into the dict in your inner loops, which causes similar 
> issues to accessing global variables. It will probably speed things up if 
> you declare it at `params{String, Float64}()` instead (or whatever the type 
> of the parameters is), or give the parameters as arguments to your 
> simulation function (probably best).
>
> -s
>
> On Sep 19, 2015, at 12:44 PM, Adam <[email protected] <javascript:>> 
> wrote:
>
> Hi, I'm a novice to Julia but have heard promising things and wanted to 
> see if the language can help with a problem I'm working on. I have some 
> Matlab code with some user-defined functions that runs a simulation in 
> about ~1.4 seconds in Matlab (for a certain set of parameters that 
> characterize a small problem instance). I translated the code into Julia, 
> and to my surprise the Julia code runs 5x to 30x slower than the Matlab 
> code. I'll be running this code on much larger problem instances many, many 
> times (within some other loops), so performance is important here. 
>
> I created a GitHub gist that contains a stripped-down version of the Julia 
> code that gets as close to (as I can find) the culprit of the problem. The 
> gist is here: https://gist.github.com/anonymous/010bcbda091381b0de9e. A 
> quick description: 
>
>    - set_up.jl sets up parameters and other items.
>    - set_up_sim.jl sets up items particular to the simulation.
>    - simulation.jl runs the simulation.
>    - calc_net.jl, dist_o_i.jl, and update_w.jl are user-defined functions 
>    executed in the simulation. 
>
>
> On my laptop (running in Juno with Julia version 0.3.10), this code yields:
> elapsed time: 43.269609577 seconds (20297989440 bytes allocated, 38.77% gc 
> time)
> elapsed time: 38.500054653 seconds (20291872804 bytes allocated, 40.41% gc 
> time)
> elapsed time: 40.238907235 seconds (20291869252 bytes allocated, 39.44% gc 
> time)
>
> Why is so much memory used, and why is so much time spent in garbage 
> collection?
>
> I'm familiar with 
> http://docs.julialang.org/en/release-0.3/manual/performance-tips/ and 
> have tried to follow these tips to the best of my knowledge. One example of 
> what might be seen as low-hanging fruit: I tried removing the type 
> declarations from my functions, but this actually increased the run-time of 
> the code by a few seconds. Also, other permutations of the column orders 
> pertaining to D, T, and I led to slower performance. 
>
> I'm sure there are several issues at play here-- I'm just using Julia for 
> the first time. Any tips would be greatly appreciated. 
>
>
>

Reply via email to