Maybe i should use @profile evolution first. I just test the below example:
m = Array(Float64, 1)
for i in 1:n
empty!(m)
...
push!(m, new_m)
end
and find that a variable is allocated in every loop. I just guess that my
code is badly pre-allocated just like this example.
I'm going to profile it.
在 2016年3月29日星期二 UTC+8下午10:06:40,Yichao Yu写道:
>
> On Tue, Mar 29, 2016 at 10:00 AM, 博陈 <[email protected] <javascript:>>
> wrote:
> > Actually, I know the arrays allocated in every loop, my problem is that
> I
> > don't know the strategy to pre-allocate such arrays.
> > In short, this is the pre-allocating problem of arrays like array a
> > described below:
> >
> >
> > n = 1024; nt = 1000;
> > dt = 0.1
> > a = Array(Float64, n, n)
> > for i in 1:nt
> > t = i*dt
> > for j in eachindex(a)
> > a[j] = exp(pi * t) * a0
> > end
> > ....... scripts to use a[j] for a single i........
> > end
> >
> > In my problem, such arrays are hard to pre-allocate, do you have any
> > suggestions?
>
> The code above shouldn't have any allocation in the loop?
> Can you point out the part of the code that allocates a lot in loops?
>
> >
> > 在 2016年3月29日星期二 UTC+8下午9:27:27,Stefan Karpinski写道:
> >>
> >> Have you tried:
> >>
> >> (a) calling @code_typewarn on your function
> >> (b) using the built-in profiler?
> >>
> >>
> >
>