Re: [eigen] Eigen containers cannot be vectorized |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Eigen containers cannot be vectorized*From*: Joseph Mirabel <joseph.mirabel@xxxxxxx>*Date*: Thu, 8 Dec 2016 14:43:15 +0100

Hi, 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; } } } Best rgds, Joseph On 12/08/2016 02:24 PM, Francois Fayard wrote: > Hi, > > I have found that Eigen containers cannot be vectorized. For instance, > the following code: > > #include <Eigen/Dense> > > void f(Eigen::Matrix<Eigen::Index, Eigen::Dynamic, Eigen::Dynamic>& A) { > for (Eigen::Index j = 0; j < A.cols(); ++j) { > for(Eigen::Index i = 0; i < A.rows(); ++i) { > A(i, j) = i + j; > } > } > } > > is not vectorized by the Intel compiler. It says that the iteration > count cannot be computed before the execution of the loop. > > It is due to the fact that A is made of: > Eigen::Index* data_; > Eigen::Index cols_; > Eigen::Index rows_; > The compiler has no way of knowing that data_ does not point to rows_. > As a consequence, it does not know that the operation A(i, j) = i + j > does not change the number of rows of A. As a consequence, the loop is > not countable and cannot be vectorized. > > One way to fix this, would be to store the number of columns as a > pointer. If cols_ becomes a Eigen::Index* such that the number of > columns is cols_ - data_, the problems get fixed, and compilers can know > vectorize the inner loop. > > Best regards, > > 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> > > PS: I have found that if you change the type to double, it does not get > vectorized too, but I have no idea why.

**Attachment:
signature.asc**

**Follow-Ups**:**Re: [eigen] Eigen containers cannot be vectorized***From:*Francois Fayard

**Re: [eigen] Eigen containers cannot be vectorized***From:*Francois Fayard

**References**:**[eigen] Eigen containers cannot be vectorized***From:*Francois Fayard

**Messages sorted by:**[ date | thread ]- Prev by Date:
**RE: [eigen] Eigen containers cannot be vectorized** - Next by Date:
**Re: [eigen] Eigen containers cannot be vectorized** - Previous by thread:
**Re: [eigen] Eigen containers cannot be vectorized** - Next by thread:
**Re: [eigen] Eigen containers cannot be vectorized**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |