我正在尝试使用OpenMP。我编写了一些代码来检查它的性能。在一个带有Kubuntu 11.04的4核单个Intel CPU上,使用OpenMP编译的以下程序比不使用OpenMP编译的程序慢约20倍。为什么?
我使用g++ -g -O2 -funroll-loops -fomit-frame-pointer -march=native -fopenmp进行编译。
#include <math.h>
#include <iostream>
using namespace std;
int main ()
{
long double i=0;
long double k=0.7;
#pragma omp parallel for reduction(+:i)
for(int t=1; t<300000000; t++){
for(int n=1; n<16; n++){
i=i+pow(k,n);
}
}
cout << i<<"\t";
return 0;
}