0

我正在尝试测试MPI_Sendwithout的效果MPI_Recv。我有以下程序,我使用 openmpi-1.4.5 和 mvapich2-1.9 编译和运行。我知道这些实现适用于 2 个不同版本的 MPI 标准,但我认为MPI_Send这些MPI_Recv标准是相同的:

#include <mpi.h>
#include <iostream>
#include <assert.h>

using namespace std;

MPI_Comm ping_world;
int mpi_size, mpi_rank;

void* ping(void* args)
{
    int ctr = 0;
    while(1)
    {
            char buff[6] = "PING";
            ++ctr;
            for(int i=0; i<mpi_size; ++i)
            {
                    cout << "[" << ctr << "] Rank " << mpi_rank << " sending " << buff << " to rank " << i << endl;
                    MPI_Send(buff, 6, MPI_CHAR, i, 0, ping_world);
            }
    }
}

int main(int argc, char *argv[])
{
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
assert(provided == MPI_THREAD_MULTIPLE);

MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);
MPI_Comm_size (MPI_COMM_WORLD, &mpi_size);

    {
            MPI_Group orig_group;
            MPI_Comm_group(MPI_COMM_WORLD, &orig_group);
            int ranks[mpi_size];
            for(int i=0; i<mpi_size; ++i)
                    ranks[i] = i;

            MPI_Group new_group;
            MPI_Group_incl(orig_group, mpi_size, ranks, &new_group);
            MPI_Comm_create(MPI_COMM_WORLD, new_group, &ping_world);
    }

pthread_t th_ping;
pthread_create(&th_ping, NULL, ping, (void *) NULL);

pthread_join(th_ping, NULL);

return 0;
}

使用 mvapich2,我总是得到以下输出(仅此而已)。基本上,程序似乎在 3 行之后就挂了:

[1] Rank 0 sending PING to rank 0
[1] Rank 1 sending PING to rank 0
[1] Rank 1 sending PING to rank 1

使用 openmpi,我得到以下输出(无休止):

[1] Rank 1 sending PING to rank 0
[1] Rank 1 sending PING to rank 1
[1] Rank 0 sending PING to rank 0
[1] Rank 0 sending PING to rank 1
[2] Rank 0 sending PING to rank 0
[2] Rank 0 sending PING to rank 1
[3] Rank 0 sending PING to rank 0
[3] Rank 0 sending PING to rank 1
[4] Rank 0 sending PING to rank 0
[4] Rank 0 sending PING to rank 1
[5] Rank 0 sending PING to rank 0
[2] Rank 1 sending PING to rank 0
[2] Rank 1 sending PING to rank 1
[3] Rank 1 sending PING to rank 0
[3] Rank 1 sending PING to rank 1
[4] Rank 1 sending PING to rank 0
[4] Rank 1 sending PING to rank 1
[5] Rank 1 sending PING to rank 0
[5] Rank 1 sending PING to rank 1
[6] Rank 1 sending PING to rank 0

问题:

  1. 为什么会有这样的差异?
  2. 如何使用 mvapich2 实现类似于 openmpi(无休止)的行为?
4

3 回答 3

1

当调用程序可以安全地重用缓冲区时,MPI_Send 可以返回。没有其他保证,但是有许多不同的实现依赖行为。不同的实现可以不同地处理消息的缓冲。Eager 协议还允许将一些更短的(更短的)消息传输到接收等级,而无需发布匹配的 MPI_Recv。

如果您需要 MPI 在阻塞发送返回之前强制接收消息,请查看 MPI_Ssend。

于 2013-09-01T04:42:25.707 回答
0

在 MVAPICH2(和 MPICH)实现中,自阻塞发送被阻塞(不缓冲),直到找到相应的 MPI_Recv。这就是它没有挂在“Rank 1发送PING to rank 0”的原因它只是一个实现选择。

于 2013-09-03T23:40:10.867 回答
0

发送数据而不接收数据是不正确的 MPI 程序。您看到的问题是您的发送与任何接收都不匹配。根据实现,MPI_SEND可能会阻塞,直到另一端实际收到消息。事实上,我所知道的所有实现都会为足够大的消息执行此操作(尽管您的 6 字节消息可能在任何地方都没有达到该阈值)。

如果您想在不阻止的情况下发送消息,则需要使用MPI_ISEND. 然而,即便如此,您最终还是需要调用MPI_TESTMPI_WAIT确保数据是实际发送的,而不是仅仅在本地缓冲。

我不确定为什么 MVAPICH2 挂起而 Open MPI 没有挂起的具体细节,但最终它并不重要。您需要修改您的程序,或者您只是在测试不应该真正使用的案例。

于 2013-08-30T14:50:27.900 回答