我正在试验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;
}
Run Code Online (Sandbox Code Playgroud)