#include "stdio.h"
#include "omp.h"
void main() {
omp_set_num_threads(4);
#pragma omp parallel
{
int numberOfThreads = omp_get_num_threads;
int ID = omp_get_thread_num;
printf("%d %d \n",ID,numberOfThreads);
}
}
我得到的答案是:
4196016 4196064
4196016 4196064
4196016 4196064
4196016 4196064
我使用以下命令编译程序:
gcc -O3 -fopenmp -Wall test.c
我只收到一些警告信息:
test.c: In function ‘main’:
test.c:8:24: warning: initialization makes integer from pointer
without a cast [enabled by default]
int numberOfThreads = omp_get_num_threads;
^
test.c:9:11: warning: initialization makes integer from pointer
without a cast [enabled by default]
int ID = omp_get_thread_num;
谢谢!
最佳答案
那些是函数,所以
int numberOfThreads = omp_get_num_threads;
必须是
int numberOfThreads = omp_get_num_threads();
和
int ID = omp_get_thread_num;
必须是
int ID = omp_get_thread_num();
关于c - 我一直在使用 openmp 获取错误的 ID 和线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43042898/