我一直在使用openmp获取错误的ID和线程数

时间:2017-03-27 09:39:35

标签: c gcc openmp

#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;

谢谢!

1 个答案:

答案 0 :(得分:5)

这些是功能,所以

int numberOfThreads = omp_get_num_threads;

必须是

int numberOfThreads = omp_get_num_threads();

int ID = omp_get_thread_num;

必须是

int ID = omp_get_thread_num();