实验4 pi 的计算(6)
发布时间:2021-06-08
发布时间:2021-06-08
并行计算的pi的多种计算方法的实验
MPI_Bcast(&n, count, MPI_INT, source, MPI_COMM_WORLD); if (n == 0)
done = 1;
else {
} sum = 0.0; for(int j=0;j<=n;j++) mypi = 4.0*sum; // h是º?宽¨ª度¨¨。¡ê这a样¨´得Ì?到Ì?sum += f(j); // 计?算?长¡è条¬?的Ì?高?。¡ê 面?积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;
}
(3)第三种方法
#include"stdafx.h"
#include"mpi.h"
#include<iostream>
#include"windows.h"
#include<math.h>
double f(double);
double t(double);
double f(int a)
{
int b=(int)a; doublenum; double sum=0.0;
上一篇:1管理沟通概述