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

Possible Optimization bug

$
0
0

For the following code:

#include <iostream>
#include <vector>
int main(int argc, char *argv[])
{
    int const dimension = 2;
    int const number_of_nodes = 20;
    std::vector<double> x(number_of_nodes*dimension);
    for (int n=0; n<number_of_nodes; ++n)
    {
        x[0+dimension*n] = 0.01*n;
        x[1+dimension*n] = 0.02*n;
    }
    for (int i=0; i<40; ++i)
        std::cout << "x["<< i << "]: "<< x[i] << std::endl;
    return 0;
}

I get the wrong output with -O3:

x[0]: 0
x[1]: 0
x[2]: 0.01
x[3]: 0.02
x[4]: 0
x[5]: 0
x[6]: 0.03
x[7]: 0.06
x[8]: 0
x[9]: 0

...

I get the correct output with -O2:

x[0]: 0
x[1]: 0
x[2]: 0.01
x[3]: 0.02
x[4]: 0.02
x[5]: 0.04
x[6]: 0.03
x[7]: 0.06
x[8]: 0.04
x[9]: 0.08

I get the same results with versions 15.0.090 and 15.0.3. This does not occur with 14.0.4.

Any help would be appreciated.

 

Thanks.

 

 

 

 

 


Viewing all articles
Browse latest Browse all 1616

Trending Articles