I use Eigen::Array in my program. Depending on array size compiling with -march=native on GCC doesn't have any effect or actually slower. I'm not realy experienced with Eigen or C++, but I thought -march=native should enable simd vectorization which in turn should lead to faster execution. Am I wrong? And where should I look for problem?
If I strip down my code the core of it would look something like this:
using Matrix = Eigen::Array<Float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
Matrix swarm_matrix;
Matrix pbest_matrix;
Matrix velocities_matrix;
// Initialize matrices and do some stuff
for(size_t iteration = 0; iteration < iterations_number; ++iteration)
{
for(size_t particle_index = 0; particle_index < particles_number; ++particle_index)
{
velocities_matrix.row(particle_index) =
w * velocities_matrix.row(particle_index) +
c1 * (pbest_matrix.row(particle_index) - swarm_matrix.row(particle_index)) +
c2 * (pbest_matrix.row(gbest_index) - swarm_matrix.row(particle_index));
swarm_matrix.row(particle_index) =
swarm_matrix.row(particle_index) +
velocities_matrix.row(particle_index);
// Do some other stuff
}
}