OpenMP在Mac上运行单线程,线程号不为0

时间:2019-07-18 06:14:20

标签: c++ macos clang openmp

我试图将openmp应用于for循环,但是当max_num_thread为4时,似乎只有一个线程正在运行。尽管我将num_threads设置为4,但是它仍然没有作用;

代码:

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


int main()
{
    omp_set_num_threads(4);
    #pragma omp parallel for// num_threads(7)
    for(int i = 0; i < 10; i++)
    {
        printf("thread id:%d\n",omp_get_num_threads());
        printf("thread num:%d\n",omp_get_max_threads());
    }

    printf("thread num:%d\n",omp_get_max_threads());

    //gmp_printf("%Zd\n",result_array[n-1]);
    return 0;
}

编译器命令:

g++ bn_p.cpp -o bn_p.out -lgmpxx -lgmp -Xpreprocessor -fopenmp -lomp //actually g++ is clang on mac

0 个答案:

没有答案