gpt4 book ai didi

gcc - 我得到 omp_get_num_threads 在 gcc 中总是返回 1(在 icc 中工作)

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

我有这个老问题,但网上没有答案对我有用,代码是:

#include "stdio.h"
#include "omp.h"

main ()
{
omp_set_num_threads(4); //initialise thread count for 4 core cpu
int j;
printf ("%d\n", omp_get_max_threads());
printf ("%d\n", omp_get_num_threads());
#pragma omp parallel for
for (int j=0; j<10; ++j)
{
printf ("%d\n", omp_get_num_threads());
int threadNum;
threadNum = omp_get_thread_num();
printf("This is thread %d\n", threadNum);
}
}
return 0;
}

在 G++ 4.4.5、linux 2.6.32-5-amd64 中,它产生:
4
1
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0

如果我们转向 ICC 12.1.0,它会给我:
4
1
4
This is thread 0
4
This is thread 0
4
This is thread 0
4
This is thread 1
4
This is thread 1
4
This is thread 1
4
This is thread 2
4
This is thread 2
4
This is thread 3
4
This is thread 3

有任何想法吗?

最佳答案

您几乎可以肯定在编译时忘记使用 -fopenmp flag

关于gcc - 我得到 omp_get_num_threads 在 gcc 中总是返回 1(在 icc 中工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11071116/

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