﻿# MPI nonblocking sends: keep the original buffer stable until local completion

Track MPI_Isend requests and buffer reuse explicitly, while distinguishing send completion from the receiving application's acceptance of the data.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/mpi-nonblocking-buffer-lifetime/
Language: en

A producer starts a nonblocking send and immediately fills the same array with its next partition. Small tests pass, but larger messages arrive corrupted. The code relied on an incidental early copy. MPI requires the original send buffer to remain stable until that send completes.

## Record the real buffer ownership

Associate every outstanding request with the storage region it references, not merely the Python or application variable name. A view, alias or memory pool can modify the same region through another path. The [MPI_Isend reference](https://docs.open-mpi.org/en/main/man-openmpi/man3/MPI_Isend.3.html) says the runtime may start copying after submission and forbids modifying any part of the send buffer until completion. Keep backing storage alive and prevent mutation through all aliases, including the next producer stage.

## Separate submission from completion

MPI_Isend returns a request handle that can be used to wait or query. Returning from the call does not prove the data has been copied out. The [asynchronous stage ownership guide](/journal/learn-async-shared-copy-pipeline/) explains the related local pipeline principle. Here the ownership interval crosses a communication request: track which specific send has completed before recycling its region. A later unrelated MPI call or a convenient position in the source does not establish that interval's end.

## Match completion to the request

The [MPI_Wait reference](https://docs.open-mpi.org/en/main/man-openmpi/man3/MPI_Wait.3.html) defines completion for the supplied request, while the send reference also names test and multi-request variants. Preserve the mapping when managing several in-flight buffers. Completion of one request does not release another buffer just because both were submitted in the same loop. A pool should move a region back to reusable state only after its own required operations finish, with error outcomes handled under the implementation's supported contract.

## Keep remote acceptance separate

Local send completion establishes the relevant local buffer boundary. It is not an application-level receipt that the remote side validated, used or durably published the partition. If the workflow requires that stronger event, define an explicit acknowledgement associated with input identity and accepted output. The [operation receipt guide](/journal/provider-post-retry-idempotency-ledger/) explains why transport progress and logical acceptance need different evidence, especially when a failure leaves the producer uncertain about a remote external effect.

## Exercise reuse under contrasting message behavior

Use disposable, distinguishable payloads and vary sizes within supported bounds rather than relying on a small-message example. Compare a reference path that completes each send before reuse with the intended overlapped buffer pool. Check payload identities and contents at the receiver. Record request completion and reuse events alongside them. Acceptance requires correct ownership and output under the declared overlap; it does not assert that a passing size reveals a universal eager-copy threshold or a measured speedup.

## Preserve the resource and failure limits

More in-flight sends require more stable storage and request bookkeeping. Bound the pool instead of overwriting old buffers when capacity runs out. A completion error cannot be treated as an ordinary success, and local cancellation has its own completion rules. The useful result is an auditable buffer lifecycle from preparation through submission, completion and reuse. It does not guarantee asynchronous network progress, remote application durability or rollback of a partition whose send or acknowledgement outcome remains uncertain.
