MPI-Bsend使用 [英] MPI - Bsend usage

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

问题描述

当我要在异步发送后完全释放资源时,MPI_Bsend是否很好? 请问:

Is MPI_Bsend good when I want to free resources exactly after async Send? Will this :

MPI_Bsend(&array[0],...)
delete[] array;

防止我删除要发送的内存(问题是,当适当的recv将打开时,该阵列可能已被删除)?

prevent me from deleting memory that I want to send ( the problem is, when appropriate recv will be on, the array may be already deleted)?

UPD:

void RectMPIAngleFiller::setglobalFillerbounds1() {

    int_t SIZE = getSolver()->getNumInterpolators() * procnums;
    int_t gridnums = getSolver()->getNumGrids();
    if (layer == 1) {
      if (local_rank == 0) {
    MPI_Isend(&rank_size, 1, MPI_INT, 0, gridnum, MPI_COMM_WORLD);
      }
    } else if (layer == 0) {
      int_t fillernumber = getSolver()->getNumInterpolators();
      int_t local_fillernum = fillernum % fillernumber;
      if (local_rank == 0 && local_fillernum == 0) {
    int_t * incomeSizes = new incomeSizes[gridnums];
    incomeSizes[gridnum] = getSolver()->getNumInterpolators();

    for ( int_t i = 0; i < gridnums; i++) {
      if (i != gridnum)
        MPI_Irecv(&incomeSizes[i], 1, MPI_INT, MPI_ANY_SOURCE, i, MPI_COMM_WORLD, &request);
    }

      }
   }    
}

例如,我现在有一个这样的函数(现在可能不正确),它从许多进程中收集大小,这些大小可能是相同的,但在不同的类实例上运行,这就是为什么所有内容都与Send一起使用的原因.

I have for example now such a function(it may be not correct now), it collects sizes from many processes, which may be the same but running on different class instances, that is why everything is with Send.

此函数在每个实例的外部循环中运行,我希望在整个周期之后完成该功能.

This function runs in outer loop for every instance and I want it to be completed after this whole cycle.

现在它仅接收大小,我不希望这样做,而是要删除一些内部数组,并根据同一函数中接收到的大小调整它们的大小.如果我有非常大的数组,则Isend中的内部缓冲区太小,无法存储所有信息.

Now it only receive sizes, I don't want this and want to delete some inner arrays and resize them according to received sizes in the same function. If I have very large arrays, inner buffer in Isend is too small to store all info.

推荐答案

在MPI中,缓冲发送和非阻塞发送之间的区别有些微妙.实际上,它们都可以用来避免死锁,因为这两个例程都在消息传递之前将控制权返回给用户(或者,它们将始终返回给用户,但此时不能保证消息已经传递).在实践中,这意味着不需要等待匹配的收据就可以发布,这有助于避免死锁.

The distinction between buffered and non-blocking sends is a bit subtle in MPI. In practice they can both be used to avoid deadlock because both routines return control to the user before the message has been delivered (or rather they will always return to the user but at that point there is no guarantee the message has been delivered). In practice this means neither needs to wait for a matching receive to be posted which helps avoid deadlock.

但是,MPI_Bsend 保证已将数据复制到缓冲区.用户有责任确保他们通过MPI_Buffer_attach提供了足够的内存来缓冲所有未完成的消息.这是一条消息还是更多条消息,取决于程序的逻辑.

However, MPI_Bsend guarantees that the data has been copied to a buffer. It is up to the user to ensure that they have provided enough memory, via MPI_Buffer_attach, for all outstanding messages to be buffered. Whether this is one message or many more depends on the logic of your program.

MPI_Isend不能不保证将消息复制到缓冲区.这种思维模式是将发送推迟到以后-您已要求MPI在方便的时候在将来的某个时间发送消息.您必须等待相关的请求,以确保MPI_Send已完成.

MPI_Isend does not guarantee that the message has been copied to a buffer. The mental model is that the send has been deferred until later - you've asked MPI to send the message some time in the future when it is convenient. You have to wait on the associated request to ensure that MPI_Send has completed.

  • 当MPI_Bsend返回时,可以安全地取消分配发送缓冲区 确保已复制到用户提供的缓冲区中.
  • 当MPI_Isend返回时,取消分配发送缓冲区是不安全的.

  • When MPI_Bsend returns it is safe to deallocate the send buffer as it is guaranteed to have been copied to the user-supplied buffer.
  • When MPI_Isend returns it is not safe to deallocate the send buffer.

当MPI_Wait(& request,& status)返回时,可以安全地取消分配 发送缓冲区.这是因为任一数据已被复制到 缓冲区(系统缓冲区,不是不是您通过Buffer_attach提供的缓冲区) ,因为它已安全地传递到匹配的MPI_Recv.

When MPI_Wait(&request, &status) returns it is safe to deallocate the send buffer. This is because either the data has been copied into a buffer (a system buffer, not the one you provide via Buffer_attach) or because it has been safely delivered to a matching MPI_Recv.

MPI可以自由选择是否缓冲MPI_Send.实际上,小消息被缓冲,大消息则不被缓冲.

MPI is free to choose whether or not it buffers MPI_Send. In practice, small messages are buffered but large ones are not.

尽管出于完整性考虑存在MPI_Ibsend,但我无法想到真正的用例.原则上,它可以在将消息复制到用户提供的缓冲区之前返回,因此直到等待之后才能释放发送缓冲区.因此,您可以将用户代码与副本重叠吗?在实践中似乎没有意义.

Although MPI_Ibsend exists for completeness, I can't think of a real use case. In principle, it could return before the message has been copied to the user-supplied buffer so you can't free the send buffer until after the wait. So you could overlap user code with the copy? Seems a bit pointless in practice.

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

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