- 论坛徽章:
- 0
|
谢谢楼上各位,了解了精度的问题。
现在我想了解什么造成这么大的运行时间差别呢 ?
Enter the number of intervals: (0 quits) 1000000000
安装文件自带的程序单进程运行:
C:\Documents and Settings\Administrator>mpiexec "C:\Program Files\MPICH2\examples\cpi.exe"
结果 :wall clock time = 7.718792
安装文件自带的程序4进程运行:
C:\Documents and Settings\Administrator>mpiexec -n 4 "C:\Program Files\MPICH2\examples\cpi.exe"
结果 :wall clock time = 1.967235
自己用提供的源代码 编译程序单进程运行:
C:\Documents and Settings\Administrator>mpiexec "C:\Program Files\MPICH2\examples\Release\cpi.exe"
结果 :wall clock time = 29.516858
自己用提供的源代码 编译程序4进程运行:
C:\Documents and Settings\Administrator>mpiexec -n 4 "C:\Program Files\MPICH2\examples\Release\cpi.exe"
结果:wall clock time = 7.417078
编译环境vs8,.net3.5
linux下的自己编译的运行情况更糟糕。
[root@localhost examples]# mpiexec -n 4 ring_c
Enter the number of intervals: (0 quits) 1000000000
pi is approximately 3.1415926535897682, Error is 0.0000000000000249
wall clock time = 10.861825
[root@localhost examples]# mpiexec ring_c
Enter the number of intervals: (0 quits) 1000000000
pi is approximately 3.1415926535899708, Error is 0.0000000000001776
wall clock time = 40.218249
附上mpich2自带的源代码
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2001 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
/* This is an interactive version of cpi */
#include "mpi.h"
#include <stdio.h>
#include <math.h>
double f(double);
double f(double a)
{
return (4.0 / (1.0 + a*a));
}
int main(int argc,char *argv[])
{
int done = 0, n, myid, numprocs, i;
double PI25DT = 3.141592653589793238462643;
double mypi, pi, h, sum, x;
double startwtime = 0.0, endwtime;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Get_processor_name(processor_name,&namelen);
/*
fprintf(stdout,"Process %d of %d is on %s\n",
myid, numprocs, processor_name);
fflush(stdout);
*/
while (!done) {
if (myid == 0) {
fprintf(stdout, "Enter the number of intervals: (0 quits) ");
fflush(stdout);
if (scanf("%d",&n) != 1) {
fprintf( stdout, "No number entered; quitting\n" );
n = 0;
}
startwtime = MPI_Wtime();
}
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (n == 0)
done = 1;
else {
h = 1.0 / (double) n;
sum = 0.0;
for (i = myid + 1; i <= n; i += numprocs) {
x = h * ((double)i - 0.5);
sum += f(x);
}
mypi = h * sum;
MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
if (myid == 0) {
printf("pi is approximately %.16f, Error is %.16f\n",
pi, fabs(pi - PI25DT));
endwtime = MPI_Wtime();
printf("wall clock time = %f\n", endwtime-startwtime);
fflush( stdout );
}
}
}
MPI_Finalize();
return 0;
} |
|