我的openMP版本没有提供任何速度提升.我有一个双核机器,CPU使用率总是50%.所以我尝试了Wiki中给出的示例程序.看起来openMP编译器(Visual Studio 2008)不会创建多个线程.
这是该计划:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
int th_id, nthreads;
#pragma omp parallel private(th_id)
{
th_id = omp_get_thread_num();
printf("Hello World from thread %d\n", th_id);
#pragma omp barrier
if ( th_id == 0 ) {
nthreads = omp_get_num_threads();
printf("There are %d threads\n",nthreads);
}
}
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
Hello World from thread 0
There are 1 threads
Press any key to continue . . .
Run Code Online (Sandbox Code Playgroud) openmp ×1