Hi Alex,

Great to see more people using Julia for scientific simulations!

Making copies of your offspring is indeed likely to be detrimental to your 
model's performance--especially if (presumably) you wish to repeat the 
simulation many times to obtain accurate estimates of whatever behavior you 
are interested in. However, I don't think that simply changing the pointer 
will allow you to obtain the best performance since this is likely to lead 
to issues when you start pre-allocating memory to the population arrays 
that contain your individuals. Especially when you repeat the simulation 
many times over, pre-allocating will likely lead to huge performance gains. 
Assuming your population size is fixed, I would suggest something like the 
following:

function siminsects(repetitions, populationsize, offspringsize)
  world = Array(TPop, populationsize)
  newpop = Array(Tpop, offspringsize)
  for i_rep in 1:repetitions

  end
end

function runonce()
  
end



Op maandag 7 september 2015 19:08:50 UTC+2 schreef alexande...@gmail.com:
>
> Hello everybody,
>
> I'm comparably new to Julia, but not completely new to programming. Yet, 
> I'm a biologist by training, so please excuse potentially dumb questions in 
> advance :)
>
> I am working in evolutionary ecology, programming individual-based 
> simulations. I have now transferred a (very) simple program that simulates 
> insect populations into Julia and am so far happy with its performance and 
> style (I really fell in love with Julia). Yet, I do have a performance 
> problem when it comes to copying a complex object. First of all my basic 
> type structure:
>
> type TInd # an individual
>   ld::Float64
>   disp::Bool
> end
>
> type TPop # a single population
>     ind::Array{TInd,1}
> end
>
> world = TPop[] # just to mention, this is NOT a global variable, but in 
> my main simulation function to create multiple populations
>
> You see that I have a set (world) of populations (TPop), each being 
> defined as arrays of individuals. During reproduction, I create a second 
> Array of individuals, that stores the (mutating) offspring. So far so good. 
> Yet, since I assume discrete generations, after each individual in a 
> population has reproduced, the parental population is to be replaced by the 
> offspring. I have implemented that like this:
>
> newpop = TInd[]
>
> # ... then the new population gets filled with offspring ...
>
> world[p].ind = deepcopy(newpop)
>
> Of course, this solution is working, but it is really slow. And since I do 
> actually not need a copy of the newpop, but just want it to overwrite the 
> original population, I guessed there might probably be a faster and more 
> elegant solution (without complex workarounds, just somehow adjusting the 
> pointers!?)? From what I've seen the model will probably run faster than in 
> C++ as soon as I find the answer :)))
>
> I appreciate any help, thanks a lot in advance!
>
> All the best,
> Alex
>

Reply via email to