BTW, all that is (briefly) described here:
http://docs.julialang.org/en/latest/manual/profile/#memory-allocation-analysis

Petr, if you nevertheless found my more detailed explanation useful, please 
weave it into the documentation and submit a pull request (click-and-edit 
instructions here: 
https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#improving-documentation)

--Tim

On Thursday, January 08, 2015 10:38:03 PM Andreas Noack wrote:
> Im not sure, but I don't think this allocation is of the same kind as the
> global variable issue from last mail. Sometimes allocation in connection
> with the arguments or the function it self is written in front of the first
> code line in the function whatever that is. You could try to insert a dummy
> line, e.g. tmp = 1 before the loop and see if the allocation moves to that
> line.
> 
> 2015-01-08 22:34 GMT-05:00 Petr Krysl <[email protected]>:
> > Sorry:  I forgot that  this function got called thousands of times.  I
> > guess in that case calling the size()  function  might result in some
> > allocation which would then get magnified by the number of calls.  (Am I
> > on
> > the right track?)
> > 
> > On Thursday, January 8, 2015 at 7:19:52 PM UTC-8, Petr Krysl wrote:
> >> Andreas,,
> >> 
> >> Good point about the global scope. What I was  really trying to
> >> 
> >> understand was  this observation:
> >>         - function getconn!{T<:FESet}(self::T,conn::JFIntMat,j::JFInt)
> >>   
> >>   5959808     for i=1:size(self.conn,2)
> >>   
> >>         0         conn[i]=self.conn[j,i];
> >>         -     end
> >>         0     return self
> >>         - end
> >> 
> >> Isn't  the size  here in  the local context, and also  of a definite
> >> type?
> >> 
> >> Petr
> >> 
> >> On Thursday, January 8, 2015 at 7:09:35 PM UTC-8, Andreas Noack wrote:
> >>> The reason is the usual global variable problem. Because n is global the
> >>> type is not inferred well and the loop is therefore not well optimized.
> >>> This doesn't happen in local scope e.g.
> >>> 
> >>> julia> let
> >>> 
> >>>        m = 1000000
> >>>        
> >>>        @allocated for i = 1:m end
> >>>        
> >>>        end
> >>> 
> >>> 0
> >>> 
> >>> and it can also be avoided if you specify the type in the loop range
> >>> 
> >>> julia> @allocated for i = 1:n::Int
> >>> 
> >>>        end
> >>> 
> >>> 0
> >>> 
> >>> 2015-01-08 22:02 GMT-05:00 Petr Krysl <[email protected]>:
> >>>> julia> a=rand(1000000);
> >>>> 
> >>>> julia> n=length(a);
> >>>> 
> >>>> julia> @allocated for j=1:n
> >>>> 
> >>>>        end
> >>>> 
> >>>> 63983688
> >>>> 
> >>>> 64 MB to run this loop?  Is that expected?
> >>>> 
> >>>> Thanks for any insight.
> >>>> 
> >>>> Petr

Reply via email to