c – #pragma omp parallel num_threads无效

    #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时,我不明白为什么它只执行一个线程?
程序ouptut:

   Hello world from thread = 0
   Number of threads = 1

最佳答案 在VisualStudio中只需打开OMP即可.你可以参考
https://msdn.microsoft.com/de-de/library/fw509c3b(v=vs.120).aspx

点赞