Home:ALL Converter>My program does not run properly when compiled with icc

My program does not run properly when compiled with icc

Ask Time:2018-05-28T16:25:15         Author:Adriano Marques Garcia

Json Formatter

I'm having a problem with icc and so far I've not found any solution. My program runs normally when compiled with gcc, but apparently does not perform any operation when compiled with icc. No runtime errors occur. The program just ends very fast (a few milliseconds), but was expected to take a few seconds (about 11 seconds for n = 1 billion). However it works okay if I print the total at the end.

It's a small code:

# include <stdlib.h>
# include <stdio.h>

double f(double x){
    double pi = 3.141592653589793;
    double value;
    value = 50.0 / (pi * (2500.0 * x * x + 1.0));
    return value;
}
int main (int argc, char *argv[]){
    double a = 0.0, b = 10.0, total = 0.0, x;
    unsigned long int i, n = 1000000000;

    for(i = 0; i < n; i++){
        x = ((n - i - 1) * a + (i) * b) / (n - 1);
        total = total + f(x);
    }
    total = (b - a) * total / (double) n;

    //printf("%f\n", total);
    return 0;
}

I also checked that it actually runs the loop and calls the function n times.

Does anyone know what could be causing this problem?

Thanks!

Author:Adriano Marques Garcia,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50562050/my-program-does-not-run-properly-when-compiled-with-icc
yy