免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2680 | 回复: 9
打印 上一主题 下一主题

是什么让编译结果之间差距这么大阿 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-14 21:03 |只看该作者 |倒序浏览

在win下自己编译了mpich2中的例子,单核10位数要29秒多,四核要7秒多。
安装文件自带的程序居然快了4倍。
两个程序分别单核四核执行结果一样。但各自的单核四核结果是不同的。

在linux下的结果还要慢一些。

C:\Documents and Settings\Administrator>mpiexec  "C:\Program Files\MPICH2\exampl
es\cpi.exe"
Enter the number of intervals: (0 quits) 1000000000
pi is approximately 3.1415926535899708, Error is 0.0000000000001776
wall clock time = 7.718792
Enter the number of intervals: (0 quits) 1000000000
pi is approximately 3.1415926535899708, Error is 0.0000000000001776
wall clock time = 7.717777
Enter the number of intervals: (0 quits) 0

C:\Documents and Settings\Administrator>mpiexec -n 4 "C:\Program Files\MPICH2\ex
amples\cpi.exe"
Enter the number of intervals: (0 quits) 1000000000
pi is approximately 3.1415926535897682, Error is 0.0000000000000249
wall clock time = 1.967235
Enter the number of intervals: (0 quits) 1000000000
pi is approximately 3.1415926535897682, Error is 0.0000000000000249
wall clock time = 1.954080
Enter the number of intervals: (0 quits) 1000000000
pi is approximately 3.1415926535897682, Error is 0.0000000000000249
wall clock time = 1.954707
C:\Documents and Settings\Administrator>mpiexec -n 4 "C:\Program Files\MPICH2\ex
amples\Release\cpi.exe"
Enter the number of intervals: (0 quits) 1000000000

1000000000
pi is approximately 3.1415926535897682, Error is 0.0000000000000249
wall clock time = 7.417078
Enter the number of intervals: (0 quits) 0

0

C:\Documents and Settings\Administrator>mpiexec  "C:\Program Files\MPICH2\exampl
es\Release\cpi.exe"
Enter the number of intervals: (0 quits) 1000000000

1000000000
pi is approximately 3.1415926535899708, Error is 0.0000000000001776
wall clock time = 29.516858

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
2 [报告]
发表于 2009-04-14 21:20 |只看该作者
用到浮点数,结果不一样很正常

论坛徽章:
0
3 [报告]
发表于 2009-04-14 23:55 |只看该作者
不具体,没真相。
MPI也分块计算吧,浮点数本来就有精度问题。1个计算拆成8个,精度损失不会和原来相同的,因为每一部分的精度损失和原来相同,但是8部分加起来就会损失更大一些,但是我不觉得是8倍。
其次,还可以怀疑ABI,ABI是由CPU、OS、Comp一起决定的,当然还可以从各种“标准”的角度看待。

论坛徽章:
0
4 [报告]
发表于 2009-04-15 03:58 |只看该作者
谢谢楼上各位,了解了精度的问题。

现在我想了解什么造成这么大的运行时间差别呢 ?

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;
}

论坛徽章:
0
5 [报告]
发表于 2009-04-17 20:12 |只看该作者
回复一个先,过几天看看。
现在没时间。

论坛徽章:
0
6 [报告]
发表于 2009-04-19 01:26 |只看该作者
1. lz 检查一下执行程序的区别.
2. lz 用各种优化选项编译对比一下!

论坛徽章:
0
7 [报告]
发表于 2009-04-20 03:48 |只看该作者

搞了半天,可能是gcc版本低的原因:
gcc 版本 4.1.2 20080704 (Red Hat 4.1.2-44)

用fc9的live-usb编译一下,
gcc  -march=amdfam10 -O3 cpi.c -o cpi
wall clock time = 7.760000
gcc 版本 4.3

如果fc9不用选项-march=amdfam10,结果是12秒,但rhel5.3用选项-march=amdfam10,结果还是12秒。

[ 本帖最后由 长湾 于 2009-4-20 06:52 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2009-04-20 08:19 |只看该作者
原帖由 system888net 于 2009-4-19 01:26 发表
1. lz 检查一下执行程序的区别.
2. lz 用各种优化选项编译对比一下!

专业人士来了。已经看出来lz的水平了。

论坛徽章:
0
9 [报告]
发表于 2009-04-20 13:21 |只看该作者
原帖由 prolj 于 2009-4-20 08:19 发表

专业人士来了。已经看出来lz的水平了。


我接受你的鄙视:em12:

论坛徽章:
0
10 [报告]
发表于 2009-04-20 13:31 |只看该作者
ft。。。。。。。。。。。。。
妒忌你有MPI玩儿还来不及呢,谁BS你来着 888是专业的MPI人士
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP