实验4 pi 的计算(8)
发布时间:2021-06-08
发布时间:2021-06-08
并行计算的pi的多种计算方法的实验
fflush(stdout); { } startwtime = MPI_Wtime(); fprintf(stdout, "No number entered; quitting\n" ); n = 0; if (scanf("%d",&n) != 1)
}
MPI_Bcast(&n, count, MPI_INT, source, MPI_COMM_WORLD); if (n == 0)
done = 1;
else {
} sum = 0.0; sum2=0.0; for(int j=0;j<=n;j++) {sum += f(j); sum2+=t(j); } mypi = 4*(sum - sum2); // 这a样¨´得Ì?到Ì?面?积y。¡ê MPI_Reduce(&mypi, &pi, count, MPI_DOUBLE, MPI_SUM, source, if (myid == source) { printf("pi is approximately %.16f, Error is %.16f\n", pi, fabs(pi - endwtime = MPI_Wtime(); // 主¡Â进?程¨¬计?时º¡À。¡ê // 计?算?长¡è条¬?的Ì?高?。¡ê MPI_COMM_WORLD); // 所¨´有®D进?程¨¬的Ì?工¡è作Á¡Â汇?总Á¨¹ PI25DT)); printf("wall clock time = %f\n", endwtime-startwtime); fflush(stdout ); }
}
MPI_Finalize();
return 0;
}
上一篇:1管理沟通概述