#include <stdio.h>
#include <time.h>
#include <omp.h>
int main(void)
{
static long num_steps=1000000000;
double step;
int i;
double x,pi,walltime,sum=0.0;
step=1.0/(double)num_steps;
omp_set_num_threads(NUM_THREADS);
time_t start;
start=time(NULL);
#pragma omp parallel for reduction(+:sum)private(x)
for(i=0;i<num_steps;i++)< p="">
{
x=(i+0.5)*step;
sum+=4.0/(1.0+x*x);
}
pi=sum*step;
printf("Pi=%21.20f(%d steps)\n",pi,num_steps);
walltime=time(NULL)-start;
printf("It cost %f sec",walltime);
return 0;
}
Openmp并行简单算例1
最新推荐文章于 2022-05-17 23:53:36 发布