gpt4 book ai didi

c++ - #pragma omp parallel num_threads 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:10:04 25 4
gpt4 key购买 nike

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

void main(int argc, int *argv[]){


#pragma omp parallel num_threads(3)
{

int tid = omp_get_thread_num();
printf("Hello world from thread = %d \n",tid);
if(tid == 0){
int nthreads = omp_get_num_threads();
printf("Number of threads = %d\n",nthreads);
}
}

}

我正在学习OpenMP,我不明白为什么我指定了线程数3,它只执行一个线程?程序输出:

   Hello world from thread = 0
Number of threads = 1

最佳答案

您需要使用-fopenmp 编译您的程序。

g++ a.cc -fopenmp

关于c++ - #pragma omp parallel num_threads 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24417145/

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