OpenMP 测试程序

#include <omp.h> #include <stdio.h> int main(int argc, char * argv[]) { int nthreads, tid, x; int nthrds = 4; x = 0; omp_set_num_threads(nthrds); #pragma omp parallel private(tid) { tid = omp_get_thread_num(); printf("Hello world from OMP thread %d/n",tid); } #pragma omp parallel shared(x) { #pragma omp critial x = x + 1; } printf("x = %d /n", x); return 0; }

 

result:

[root@localhost ~]# gcc hello.c -o hello -fopenmp [root@localhost ~]# ./hello Hello world from OMP thread 3 Hello world from OMP thread 0 Hello world from OMP thread 1 Hello world from OMP thread 2 x = 4 [root@localhost ~]#

 

你可能感兴趣的:(thread,测试,gcc,include,parallel)