是MPI_Reduce阻止(或自然屏障)吗? [英] Is MPI_Reduce blocking (or a natural barrier)?

查看:139
本文介绍了是MPI_Reduce阻止(或自然屏障)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的C ++代码段,基本上使用经典的蒙特卡洛技术来计算pi.

I have the code snippet below in C++ which basically calculates the pi using classic monte carlo technic.

    srand48((unsigned)time(0) + my_rank);

    for(int i = 0 ; i < part_points; i++)
    {
            double x = drand48();

            double y = drand48();

            if( (pow(x,2)+pow(y,2)) < 1){ ++count; }
    }

    MPI_Reduce(&count, &total_hits, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

    MPI_Barrier(MPI_COMM_WORLD);

    if(my_rank == root)
    {
            pi = 4*(total_hits/(double)total_points);

            cout << "Calculated pi: "  <<  pi << " in " << end_time-start_time <<  endl;
    }

我只是想知道是否需要MPI_Barrier调用. MPI_Reduce是否确保在reduce操作完全完成之前不会执行if语句的主体?希望我很清楚.谢谢

I am just wondering if the MPI_Barrier call is necessary. Does MPI_Reduce make sure that the body of the if statement won't be executed before the reduce operation is completely finished ? Hope I was clear. Thanks

推荐答案

是的,所有集体通信调用(Reduce,Scatter,Gather等)都处于阻塞状态.不需要障碍.

Yes, all collective communication calls (Reduce, Scatter, Gather, etc) are blocking. There's no need for the barrier.

这篇关于是MPI_Reduce阻止(或自然屏障)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆