实验4 pi 的计算(5)
发布时间:2021-06-08
发布时间:2021-06-08
并行计算的pi的多种计算方法的实验
} printf("wall clock time = %f\n", endwtime-startwtime); fflush(stdout ); }
}
MPI_Finalize();
return 0;
}
(2)第二种方法
double f(double);
double f(double a)
{
}
int _tmain(intargc, char* argv[])
{
int done = 0, n, myid, numprocs, i,source=0,count=1; double PI25DT = 3.141592653589793238462643;
doublemypi, pi, h, sum, x;
doublestartwtime = 0.0, endwtime;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
while (!done)
{ { fflush(stdout); { } startwtime = MPI_Wtime(); fprintf(stdout, "No number entered; quitting\n" ); n = 0; if (myid == source) fprintf(stdout, "Enter the number of intervals: (0 quits) "); if (scanf("%d",&n) != 1) int b=(int)a; return (1.0 / (1.0 + 2*a)); else return (-1.0/(1.0+2*a)); if(b%2==0)
上一篇:1管理沟通概述