Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

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

Komarov__Alexander
321 Views

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.

[cpp]

#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 = my_hist;
   }

   for (int i = 0; i < NLI; i++) {
      p=p * n / sump_;
   }

   double sump = 0.0;
   for (int i = 0; i < NLI; i++) {
      sump += p;
   }
   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 = my_hist;
   }

   //for (int i = 0; i < NLI; i++) {
   // p=p * n / sump_;
   //}

   double sump = 0.0;
   for (int i = 0; i < NLI; i++) {
      p=p * n / sump_;
      sump += p;
   }
   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 = rand() % 256;
      dataOrig = data;
   }

   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 %.12f\n", outNewFunction);
   printf("orig %.12f\n", outOrigFunction);

   return 0;
}

[/cpp]

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? 

 

0 Kudos
4 Replies
TimP
Honored Contributor III
321 Views

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.

0 Kudos
Komarov__Alexander
321 Views

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?

0 Kudos
QIAOMIN_Q_
New Contributor I
321 Views

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?

 

0 Kudos
Komarov__Alexander
321 Views

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.

0 Kudos
Reply