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] <javascript:>>:
>
>> 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
>>
>
>