Bug report - I don't know this error or it's normal

Bug report - I don't know this error or it's normal

Ritratto di AlexanderKomarov

I optimized my code and after that some operation. I have a mistake of accuracy with original version.
I wrote this example that repeats a mistake of the accuracy. But I don't know this bug or it's normal.

#include <iostream>
#include <stdlib.h>
#include <vector>
#include <stdio.h>
using namespace std;
double bringHistSpec(const double *my_hist) {
    const int NLI = 256;
    int n = 1000;
   double sump_ = 300;
   double p[NLI];
   for (int i = 0; i < NLI; i++) {
      p[i] = my_hist[i];
   }
   for (int i = 0; i < NLI; i++) {
      p[i]=p[i] * n / sump_;
   }
   double sump = 0.0;
   for (int i = 0; i < NLI; i++) {
      sump += p[i];
   }
   return sump;
}
double bringHistSpecOrig(const double *my_hist) {
   const int NLI = 256;
   int n = 1000;
   double sump_ = 300;
   double p[NLI];
   for (int i = 0; i < NLI; i++) {
   p[i] = my_hist[i];
   }
   //for (int i = 0; i < NLI; i++) {
   // p[i]=p[i] * n / sump_;
   //}
   double sump = 0.0;
   for (int i = 0; i < NLI; i++) {
      p[i]=p[i] * n / sump_;
      sump += p[i];
   }
   return sump;
}
int main() {
   const int sizeX = 177;
   const int sizeY = 198;
   int dataSize = sizeX * sizeY;
   std::vector<double> data(dataSize);
   std::vector<double> dataOrig(dataSize);
   for (int i = 0; i < dataSize; i++) {
      data[i] = rand() % 256;
      dataOrig[i] = data[i];
   }
   vector<double> my_hist(256);
   for (size_t i = 0; i < my_hist.size(); i++) {
      my_hist[255 - i] = int(1. / (255. * 255. * 255.) * pow(i, 4) + 0.5);
   }
   double outNewFunction = bringHistSpec(&my_hist[0]);
   double outOrigFunction = bringHistSpecOrig(&my_hist[0]);
   printf("new %.12fn", outNewFunction);
   printf("orig %.12fn", outOrigFunction);
   return 0;
}

icc -O2 -g3 -no-vec -Wall -c -fmessage-length=0 -MMD -MP -MF"src/FR2013Tests.d" -MT"src/FR2013Tests.d" -o"src/FR2013Tests.o" "../src/FR2013Tests.cpp" 
icc version 13.1.2 (gcc version 4.6.0 compatibility)  - composer_xe_2013.4.183
OpenSuse 12.1

I ran this program with O1 there is not mistake, with O3 there is mistake.
I ran this program with O2 and without "-no-vec" there is mistake, with O3 and without "-no-vec" there is not mistake. 

Can somebody help me? 

 

5 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Tim Prince

You could expect small changes in numerical results when you vectorize with -no-prec-div so as to permit reciprocal-math optimizations, and when you vectorize sum reductions.  The option -fp-model source would imply -prec-div, and prevent vectorized sum reduction.

Ritratto di AlexanderKomarov

Thanks for the answer. I tried to run my program with this options(-prec-div and -fp-model), but i have old problem again. 

This is output my program:

new 43789.999999999992724
orig 43790.000000000014552

How I understand my problem is bug of compiler. Am I right? If yes, What should I do next?

Ritratto di QIAOMIN Q. (Intel)

can you try the compiler's latest version from the registeration center?

 "with O3 and without "-no-vec" there is not mistake. "looks confusing ,could you provide the full options ?

You mean the add '-fp-model source' is of no help to the outcome's correctness?

 

Ritratto di AlexanderKomarov

I'm sorry. I wasn't right to use "-fp-model". With options, there is not mistake. I think it's not bug. Thanks for help.

But with O3 and without "-no-vec", without "-fp-model source", there is not mistake.

With O2 and without "-no-vec", without "-fp-model source", there is mistake.

Accedere per lasciare un commento.