Boost logo

Ublas :

Subject: Re: [ublas] [uBlas] Fastest way to change sing of matrix
From: Nasos Iliopoulos (nasos_i_at_[hidden])
Date: 2013-04-16 12:48:53


Hello,
As a matter of fact in this case uBlas should be able to avoid any
unnecessary copies even without noalias. A quick debug stepping I did
shows that it indeed avoids copying temporaries because everything is
routed through the assign_temporary member- which is essentially just a
pointer exchange facility.

Examination of the assembly output though reveals that at least gcc
doesn't seem to properly optimize the negation, presumably because it
can't drill down the current expression template mechanism. I suspect
that noalias provides a more friendly expression tree for the compiler
to optimize rather than anything else for this specific code snippet.

FYI:
gcc assembly output for negation:
pure C : 57 lines
A=-A: 142 lines
noalias(A)=-A: 61 lines

Has anybody tried something similar on another compiler?

Best,
-Nasos

On 04/16/2013 11:28 AM, dariomt wrote:
> oswin krause <oswin.krause <at> ruhr-uni-bochum.de> writes:
>
>> oh i somehow missed the part in the bracket. sorry. While you are right
>> that it strictly violates the assumption, you know that blas1 calls
>> (aside from transpose) can't alias.
>>
>>>>> As i assume A to be a small matrix:
>>> I did say it is very large.
>>>
>>>>> noalias(A)=-A
>>>>> fixes everything.
>>> Doesn't that suggestion break the assumptions of noalias? From the docs: "If
>>> you know for sure that the left hand expression and the right hand
>>> expression have no common storage". Well, the lhs and the rhs both reference
>>> the same matrix object!
>>>
>>> How is that guaranteed to work?
> OK, thanks for the suggestion.
>
> Now that I hear people talking about improving Ublas, it would be great if
> Ublas could detect aliasing automagically and apply noalias() without user
> intervention.
>
> Regards
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: athanasios.iliopoulos.ctr.gr_at_[hidden]