Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Compiler vectorize std::vector but not C vector

$
0
0

Hi,

 

I have tested the compiler regarding vectorization and I get the following weird problem. In the following code

double test80_c(double* x, double* y, int n, int nb_loops) {
    double sum{ 0.0 };
    double a{ 0.0 };
    for (int i = 0; i < nb_loops; ++i) {
        a += 1.0;
        for (int k = 0; k < n; ++k) {
            sum += std::sqrt(x[k]*x[k] + y[k]*y[k] + a);
        }
    }
    return sum;
}

double test80_cpp(const std::vector<double>& x, const std::vector<double>& y,
        int nb_loops) {
    double sum{ 0.0 };
    double a{ 0.0 };
    for (int i = 0; i < nb_loops; ++i) {
        a += 1.0;
        for (std::size_t k = 0; k < x.size(); ++k) {
            sum += std::sqrt(x[k]*x[k] + y[k]*y[k] + a);
        }
    }
    return sum;
}

the first version (C one) gets vectorized but not the second one. Note that the following Fortran code

    function test80_f(x, y, n, nb_loops) bind(c)
        use iso_c_binding
        real(dp), dimension(1:n), intent(in) :: x
        real(dp), dimension(1:n), intent(in) :: y
        integer, intent(in) :: n
        integer, intent(in) :: nb_loops
        real(dp) :: test80_f
        ! local variables
        integer :: i, k
        real(dp) :: a

        test80_f = 0.0_dp
        a = 0.0_dp
        do i = 1, nb_loops
            a = a + 1.0_dp
            do k = 1, n
                test80_f = test80_f + sqrt(x(k)**2 + y(k)**2 + a)
            end do
        end do
    end function test80_f

does not get vectorized either. Could you reproduce that on your compiler ? I am using icpc 15.0.0 20140716 under Mac OSX.

Best regards,

Francois

 


Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>