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

标签 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;

谢谢!

最佳答案

那些是函数,所以

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/

相关文章:

c - 返回结构的函数名

c - 结构体和指针

fortran - fortran中使用openmp并行创建稀疏矩阵

openmp - 帮助解决 openmp 编译问题

c++ - GCC 不遵守 'pragma GCC diagnostic' 以消除警告

C 文件检查文件是否为空或包含 ASCII 文本

c - Powerpc 的组装遇到 Program received signal SIGSEGV Segmentation fault

c - 为什么gcc在arm汇编中分配了更多的堆栈?

c - 编译 GCC Ubuntu : undefined reference to 时出错

配置交叉编译器以使用自定义库搜索路径