| Re: [eigen] Eigen containers cannot be vectorized |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Actually, my code can't work. I realize it just now.
A(i,j) returns something like (A.data_ + i * A.cols_ + j)
As it does not know that A.cols_ is constant, it does not vectorize...
On 12/08/2016 03:03 PM, Francois Fayard wrote:
> Hi Joseph,
>
>> what about this:
>>
>> #include <Eigen/Dense>
>>
>> void f(Eigen::Matrix<Eigen::Index, Eigen::Dynamic, Eigen::Dynamic>& A) {
>> const Eigen::Index cols = A.cols();
>> const Eigen::Index rows = A.rows();
>> for (Eigen::Index j = 0; j < cols; ++j) {
>> for(Eigen::Index i = 0; i < rows; ++i) {
>> A(i, j) = i + j;
>> }
>> }
>> }
>
> I was too quick to reply. It does not work, compiled with
>
> icpc -c -std=c++11 -O3 -xHost -DNDEBUG
>
> I can’t really explain what is going on. I have tried to walk the
> accessor (A(i, j)) through the debugger, and it is not straightforward
> code for the compiler. There is a pointer cast that might disconnect any
> optimizer. So, I can’t easily provide you with a solution.
>
> I was also surprised to see that in debug mode, bounds checking is done
> with: assert(i >=0 && i < n). This can be optimized into
> assert(static_cast<std::size_t>(i) < static_cast<std::size_t>(n)).
>
> François Fayard
> Founder & Consultant - Inside Loop
> Applied Mathematics & High Performance Computing
> Tel: +33 (0)6 01 44 06 93
> Web: www.insideloop.io <http://www.insideloop.io>
Attachment:
signature.asc
Description: OpenPGP digital signature
| Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |