#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);
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的答案是:
4196016 4196064
4196016 4196064
4196016 4196064
4196016 4196064
Run Code Online (Sandbox Code Playgroud)
我用以下命令编译程序:
gcc -O3 -fopenmp -Wall test.c
Run Code Online (Sandbox Code Playgroud)
我只收到一些警告信息:
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;
Run Code Online (Sandbox Code Playgroud)
谢谢!
那些是功能,所以
int numberOfThreads = omp_get_num_threads;
Run Code Online (Sandbox Code Playgroud)
一定是
int numberOfThreads = omp_get_num_threads();
Run Code Online (Sandbox Code Playgroud)
和
int ID = omp_get_thread_num;
Run Code Online (Sandbox Code Playgroud)
一定是
int ID = omp_get_thread_num();
Run Code Online (Sandbox Code Playgroud)