提问人:HotbrewGX 提问时间:11/4/2022 更新时间:11/4/2022 访问量:141
获取“对'omp_get_wtime'的未定义引用
Getting "undefined reference to 'omp_get_wtime'
问:
我正在尝试运行下面的代码,但我一直收到错误“未定义对omp_get_wtime的引用”
`
#include <omp.h>
#include <stdio.h>
static long num_steps = 1024*1024*1024;
#define MIN_BLK 1024*1024*256
double pi_comp(int Nstart,int Nfinish,double step)
{ int i,iblk;
double x, sum = 0.0,sum1, sum2;
if (Nfinish-Nstart < MIN_BLK){
for (i=Nstart;i< Nfinish; i++){
x = (i+0.5)*step;
sum = sum + 4.0/(1.0+x*x);
}
}
else{
iblk = Nfinish-Nstart;
sum1 = pi_comp(Nstart, Nfinish-iblk/2,step);
sum2 = pi_comp(Nfinish-iblk/2, Nfinish, step);
sum = sum1 + sum2;
}return sum;
}
int main ()
{
int i;
double step, pi, sum;
double init_time, final_time;
step = 1.0/(double) num_steps;
init_time = omp_get_wtime();
sum = pi_comp(0,num_steps,step);
pi = step * sum;
final_time = omp_get_wtime() - init_time;
printf(" for %ld steps pi = %f in %f secs\n",num_steps,pi,final_time);
` 我尝试将omp_get_wtime变成双精度,但它也给了我上面代码的错误消息。
答: 暂无答案
评论
-fopenmp
/openmp
-lgomp