Ah, that seems likely.

I tried pre-allocating a vector for the current slice outside the loop,
which I'm filling using an explicit element-by-element copy. Doing this AND
using A_mul_B!() brings the performance up to when I was doing the matrix
multiply myself.

I guess when the ArrayView stuff is implemented then I wouldn't need to
pre-allocate the temporary holding place for the slice.

Is there anything in the works so that C[:] = A * B would be
equivalent to A_mul_B!(C,
A, B)? I'm trying to figure out whether there's something about my use-case
here that makes it unusual, as it seems like doing any linear algebra
inside of a tight-loop requires you to use the A_mul_B functions.

Thanks for the help, John!

-s


On Sat, Mar 8, 2014 at 4:13 PM, John Myles White
<[email protected]>wrote:

> That seems right. Is most of the memory allocation happening in y[:, i]?
>
>  -- John
>
> On Mar 8, 2014, at 4:11 PM, Spencer Russell <[email protected]> wrote:
>
> Hmm, replacing slope = A * y[:, i] with A_mul_B!(slope, A, y[:, i:i])gave a 
> very slightly reduced memory allocation and about the same speed. Am
> I using it correctly?
>
> -s
>
>
> On Sat, Mar 8, 2014 at 3:39 PM, John Myles White <[email protected]
> > wrote:
>
>> Looks like A_mul_B! should work for you to avoid memory allocation.
>>  -- John
>>
>>
>> On Mar 8, 2014, at 3:38 PM, Spencer Russell <[email protected]> wrote:
>>
>> I'm learning a little numerical ODE stuff, so I whipped up an
>> implementation of the Euler algorithm.
>>
>> It accepts systems of 1st-order equations, and the code was clean and I
>> was happy, and all was right in the world. Then I noticed that for small
>> step sizes it was allocating a very large amount of memory. It seems that
>> the allocation is happening in the matrix math, because when I wrote out
>> the matrix multiplication explicitly I got about a 30x speedup and huge
>> reduction in memory allocation (50MB instead of 2GB).
>>
>> This feels like a bit of a nuclear option, and makes what was really nice
>> general code into something much uglier. Is there a better solution?
>>
>> https://gist.github.com/ssfrr/4f5ecfaf462bb5b487db
>>
>> -s
>>
>>
>>
>
>

Reply via email to