gpt4 book ai didi

c++ - 警告 #2901 : [omp] OpenMP is not active; all OpenMP directives will be ignored

转载 作者:行者123 更新时间:2023-12-03 12:44:56 24 4
gpt4 key购买 nike

我目前正在尝试使用 OpenMP 进行并行计算。我写了以下基本代码。但是它返回以下警告:

警告 #2901:[omp] OpenMP 未激活;所有 OpenMP 指令都将被忽略。

更改线程数不会更改所需的运行时间,因为 omp.h 由于某些我不清楚的原因而被忽略。

有人可以帮帮我吗?

#include <stdio.h>
#include <omp.h>
#include <math.h>

int main(void)
{
double ts;
double something;
clock_t begin = clock();

#pragma omp parallel num_threads(4)
#pragma omp parallel for

for (int i = 0; i<pow(10,7);i++)
{
something=sqrt(123456);
}

clock_t end = clock();
ts = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Time elpased is %f seconds", ts);
}

最佳答案

为了获得 OpenMP 支持,您需要明确告诉您的编译器。

  • g++gccclang 需要选项 -fopenmp
  • mvsc 需要选项 /openmp(更多信息 here 如果您使用 visual studio)

关于c++ - 警告 #2901 : [omp] OpenMP is not active; all OpenMP directives will be ignored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66598541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com