I'm using Julia 0.4.6. 

This piece of code is part of a very big project, and posting the full 
context is too complex. I'll try to see if I can concoct a simpler example 
that also displays this weird allocation behavior.

Uri

On Saturday, August 20, 2016 at 4:45:25 PM UTC+3, Erik Schnetter wrote:
>
> My guess is that Julia cannot determine all the types of the variables and 
> expressions used in this first if statement. This is surprising, because it 
> should. I've tried locally with Julia 0.4 and Julia 0.5, using 
> code_warntype and code_native, and couldn't find a problem.
>
> Which Julia version are you using?
>
> Can you post a complete example that exactly reproduces the problem?
>
> -erik
>
>
> On Sat, Aug 20, 2016 at 7:46 AM, Uri Patish <[email protected] 
> <javascript:>> wrote:
>
>> Whops, the copy paste got messed. Here it is, 
>>
>> typealias ElementSize Tuple{Int, Int, Int}
>>
>> Uri
>>
>> On Friday, August 19, 2016 at 3:06:10 PM UTC+3, Uri Patish wrote:
>>>
>>> Hi, I have to following types, 
>>>
>>> typealias ElementSize 
>>>
>>> typealias Element Array{Float64, 3}
>>>
>>> type ElementBuffer
>>> size::ElementSize
>>> alloc::ElementSize
>>> data::Element
>>> end
>>>
>>> The following function is called many times,
>>>
>>> function set_size!(bf::ElementBuffer, sz::ElementSize, 
>>> load_old_data::Bool = true)
>>>   if (bf.alloc[1] < sz[1]) || (bf.alloc[2] < sz[2]) || (bf.alloc[3] < 
>>> sz[3])
>>>     old_data = bf.data
>>>     bf.alloc = map(max, bf.alloc, sz)
>>>     bf.data = Element(bf.alloc)
>>>     if load_old_data
>>>       load_body!(bf, old_data)
>>>     end
>>> end
>>> bf.size = sz
>>>   nothing
>>> end
>>>
>>> I've seen there is a lot of memory allocation going on, so I've 
>>> benchmarked the former code using Julia's track-allocation=user option. The 
>>> result was suprising, 
>>>
>>>         - function set_size!(bf::ElementBuffer, sz::ElementSize, 
>>> load_old_data::Bool = true)
>>> 1710097664   if (bf.alloc[1] < sz[1]) || (bf.alloc[2] < sz[2]) || 
>>> (bf.alloc[3] < sz[3])
>>>         0     old_data = bf.data
>>>   2894592     bf.alloc = map(max, bf.alloc, sz)
>>>  59783056     bf.data = Element(bf.alloc)
>>>         0     if load_old_data
>>>         0       load_body!(bf, old_data)
>>>         -     end
>>>         - end
>>>         0 bf.size = sz
>>>         0   nothing
>>>         - end
>>>
>>> After running the code in debug, I've seen that there is an allocation 
>>> happening every time the alloc field is accessed. If I change the field 
>>> type from a tuple to an array this phenomenon disappears. I can't figure 
>>> out why this allocation is happening, any ideas?
>>>
>>> Uri
>>>
>>>
>
>
> -- 
> Erik Schnetter <[email protected] <javascript:>> 
> http://www.perimeterinstitute.ca/personal/eschnetter/
>

Reply via email to