求助!!关于vs2005上运行openMP的问题
我想通过设置线程数来看一个程序的性能
但是每次运行一下代码的时候打印的线程数总是1
我怀疑是没有设置好vs2005的编译开关什么的
请问应该在vs2005中怎么设置编译参数呢???
谢谢谢谢谢谢谢~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
#include <stdio.h>
#include <time.h>
#include <omp.h>
void main ()
{
time_t start, finish;
static long num_steps = 1000000000;
double step;
int i;
double x, pi, sum = 0.0;
step = 1.0/(double) num_steps;
start = clock();
omp_set_num_threads(8);
printf("thread: %d \n",omp_get_num_threads());
#pragma omp parallel for reduction(+:sum) private(x) //openMP annotation for parallel
for (i=0;i < num_steps; i++)
{
x = (i+0.5)*step;
sum = sum + 4.0/(1.0+x*x);
}
pi = step * sum;
finish = clock();
printf( "Pi = %16.15f (%d steps), %ld ms\n ", pi, num_steps, finish-start);
printf("thread: %d ",omp_get_num_threads());
return;
}