Auto-vectorization in visual studio 2012 on vectors of Eigen type is not performing well

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:25:58

问题


I have std::vector of Eigen::vector3d types and when i am compiling this code using Microsoft Visual Studio 2012 having the /Qvec-report:2 flag on for reporting vectorization details. It's showing Loop not vectorized due to reason 1304 (Loop contains assignments that are of different types) as specified on the msdn page -https://msdn.microsoft.com/en-us/library/jj658585.aspx

My code is as below:

#include <iostream>
#include <vector>
#include <time.h>
#include<Eigen/StdVector>
int main(char *argv[], int argc)
{
    int tempSize=100;
/** I am aligning these vectors as specfied on http://eigen.tuxfamily.org/dox/group__TopicStlContainers.html */
    std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d>> eiVec(tempSize);
    std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d>> eiVec1(tempSize);
    std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d>> eiVec2(tempSize);

    for(int i=0;i<100;i++)
    {
        eiVec1[i] = Eigen::Vector3d::Zero();
        eiVec2[i] = Eigen::Vector3d::Zero();
    }

    Eigen::Vector3d *eV = &eiVec.front();
    const Eigen::Vector3d *eV1 = &eiVec1.front();
    const Eigen::Vector3d *eV2 = &eiVec2.front();

/** Below loop is not vectorized due to code 1304  */
    for(int i=0;i<100;i++)
    {
        eV[i] = eV1[i] - eV2[i];
    }
    return 0;
}

So i am not able to understand that how to tell compiler, this is the fixed size data and fixed size assignment will happen here.


回答1:


From the Eigen documentation

In Eigen, arithmetic operators such as operator+ don't perform any computation by themselves, they just return an "expression object" describing the computation to be performed. The actual computation happens later, when the whole expression is evaluated, typically in operator=

So eV1[i] - eV2[i] is not returning an Eigen::Vector3d - so reason 1304 applies. You might be able to cast it - but I wouldn't bet on it.




回答2:


Consider changeing eiVec1 and eiVec12 to a matrix<double, 3, 100> and doing the subtraction as eiVec = eiVec1 - eiVec2



来源:https://stackoverflow.com/questions/40084969/auto-vectorization-in-visual-studio-2012-on-vectors-of-eigen-type-is-not-perform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!