MPI C ++-排名更改 [英] MPI C++ - Rank changes

查看:68
本文介绍了MPI C ++-排名更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经并行处理了我的代码,其中一部分具有我无法弄清的奇怪行为.这段代码如下:

I have paralleled my code and a part of it has a strange behavior that I can't figure out. The piece of code is as follow:

int SizeEdgeForNewNodes_int;

{ 
    MPI_Request send_request[mpi_size - 1], recv_request;
    MPI_Status send_status[mpi_size - 1], recv_status;
    MPI_Barrier(MPI_COMM_WORLD);

    if (myrank == 0) {
        for (int m = 1; m < mpi_size; ++m){
            int sendTag = m;
            MPI_Isend(&SizeEdgeForNewNodes[m], 1, MPI_INT64_T, m, sendTag, MPI_COMM_WORLD, &send_request[m - 1]);
            cout << myrank << " - SizeEdgeForNewNodes[m] = " << SizeEdgeForNewNodes[m] << endl;
        }
    }
    MPI_Barrier(MPI_COMM_WORLD);    

    if (myrank > 0) {
        int recvTag = myrank;
        cout << "within b4 - myrank = " << myrank << endl;
        MPI_Irecv(&SizeEdgeForNewNodes_int, 1, MPI_INT64_T, 0, recvTag, MPI_COMM_WORLD, &recv_request); // 1st non blocking receive
        cout << "within after - myrank = " << myrank << endl;
    }
    MPI_Barrier(MPI_COMM_WORLD);    

    if (myrank != 0){
        MPI_Wait(&recv_request, &recv_status);
    }       
    MPI_Barrier(MPI_COMM_WORLD);    

    if (myrank == 0){
        MPI_Waitall(mpi_size - 1, send_request, send_status);
    }
    MPI_Barrier(MPI_COMM_WORLD); 
}

在Debug版本中运行代码时,一切都很好,获得的输出为:

When running the code in Debug version everything is fine and the obtained output is:

0 - SizeEdgeForNewNodes[m] = 0
within b4 - myrank = 1
within after - myrank = 1

在Release中运行时,我获得以下输出:

When running in Release, I obtain the following output:

0 - SizeEdgeForNewNodes[m] = 0
within b4 - myrank = 1
within after - myrank = 0

我正在使用intel-15.0编译器,并且MPI实现是mvapich2/2.1. 谢谢您的帮助,

I am using intel-15.0 compiler and the MPI implementation is mvapich2/2.1. Thank you for your help,

JB

推荐答案

您收到一个64位的int,但您的缓冲区分配了32位!因此,接收到的值将覆盖您的局部变量(myrank). 要解决此问题,请更改接收缓冲区的dataType(SizeEdgeForNewNodes_int)

You receive a 64 bit int but your buffer is allocated 32 bit! So the received value would over write on your local variable (myrank). To solve this issue change the dataType of the receive buffer(SizeEdgeForNewNodes_int)

这篇关于MPI C ++-排名更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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