If, for some reason, the code has adjusted the default iostream configuration, you can get a value of 0. The code at the very bottom demonstrates this. The code that follows next will give you valid results.
Running the code that works, I get the following. Like Hristo said, a lot gets optimized out if you add the optimization flag (-O3), but it doesn't give you a perfect 0.
$ g++ test.cc -o test.exe -fopenmp
$ ./test.exe
execution time:0.00124655
$ g++ test.cc -o test.exe -fopenmp -O3
./test.exe
execution time:2.16998e-06
Here's the code I used to get meaningful results:
#include <iostream>
#include <omp.h>
int main() {
const int x = 40000;
const int y = 40000;
double cellx[x];
double celly[y];
double itime = omp_get_wtime();
for (int i=0; i < x; i++) {
cellx[i]=i*i;
}
for (int i = 0; i < y; i++) {
celly[i]=i*i;
}
std::cout<<"execution time:"<<omp_get_wtime() - itime<<std::endl;
return 0;
}
The code below will give you the value 0:
$ ./test.exe
execution time:0
#include <iostream>
#include <iomanip>
#include <omp.h>
int main() {
const int x = 40000;
const int y = 40000;
double cellx[x];
double celly[y];
double itime = omp_get_wtime();
for (int i=0; i < x; i++) {
cellx[i]=i*i;
}
for (int i = 0; i < y; i++) {
celly[i]=i*i;
}
std::cout << std::fixed << std::setprecision(0);
std::cout<<"execution time:"<<omp_get_wtime() - itime<<std::endl;
return 0;
}
You can show more precision by calling something like the following before outputting the value:
std::cout << std::scientific << std::setprecision(6);