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!