MPI wrapper contracts ===================== Pointer-returning gather ------------------------ .. f:automodule:: f_gather :members: fmpi_gather_ptr The runnable example tests unequal contributions and every possible root. It runs through ``make check`` with ``run_parallel`` when MPI is enabled. Only the root's result contains gathered data. Every rank frees its returned allocation, including the scratch allocation on a non-root rank. Reductions and element counts ----------------------------- .. f:automodule:: f_allreduce :members: fmpi_allreduce ``mpi_contracts_check`` is an active contract driver, independent of the historical disabled ``mpi_check`` regression. Its named ``reductions`` and ``counts`` groups share kind-aware assertions and rank-aware failure reporting; a failed assertion aborts the communicator so peers cannot hang in a later collective. With no argument it runs all groups through ``make check`` and ``run_parallel``. Groups can also be selected directly:: mpirun -np 3 ./mpi_contracts_check reductions mpirun -np 3 ./mpi_contracts_check counts The reduction group verifies MPI byte type width, scalar/count and array forms, in-place and separate receive storage, unchanged send buffers, canaries, rank-two/rank-three arrays, and nonblocking completion. Bitwise operations on MPI_BYTE are supported by the `MPI predefined reduction rules `_. It also compiles and runs constant scalar operands with ``irecvbuf``; their unspecified intent is required by this valid separate-receive usage. The count group exercises zero, one and seven elements, bounds canaries, blocking and nonblocking transfers, and null requests for empty operations. It also rejects counts above the native limit locally before any payload access. A timeout-bounded initiation test makes a peer wait for a token sent only after another rank returns from posting a nonblocking reduction; an implicit validation collective would deadlock this sequence. Separate local conversion tests run in serial builds too; no boundary test allocates a huge buffer. Count kinds and legacy MPI boundaries ------------------------------------- .. f:automodule:: fmpi_types :members: fmpi_count, fmpi_count_to_mpi, fmpi_count_fits, fmpi_displacement_fits, fmpi_displacements_to_mpi, fmpi_count_to_address ``fmpi_count`` is the public count kind. Configure selects a usable ``MPI_COUNT_KIND`` from ``mpif.h`` when available and otherwise uses Futile's ``f_long``. Missing support prints a notice rather than failing configuration. Serial builds also use ``f_long``. Selection is compile-only and works when cross-compiling. The selected parameter is generated into a small Fortran include; the broadcast, reduction, send/receive and one-sided modules remain ordinary ``.f90`` sources. This kind is not the ``MPI_COUNT`` datatype handle and does not enable native large-count transfers by itself. Explicit element counts and variable-collective count/displacement vectors use ``integer(fmpi_count)`` throughout the public wrapper interfaces. There are no parallel default-integer count overloads. Callers normalize a value at the boundary if its integer kind differs; arithmetic must already have been evaluated in a sufficiently wide kind before conversion. The separate application-size audit records the future ``f_size_t`` producer/type review. Array forms infer sizes through ``f_size`` before checked narrowing; byte capacities use ``f_sizeof`` where appropriate. Character broadcasts count characters, while maxdiff wrappers validate extents before allocation. Rejected numeric maxdiff results use the undefined sentinel. The legacy backend makes checked native-integer copies of vector metadata. Blocking calls release them after the payload operation. Nonblocking variable all-to-all calls retain their native vectors until ``fmpi_wait`` or ``fmpi_waitall`` completes the request. Complete those requests through these Futile wrappers so the retained metadata is released. The wide caller metadata can be a temporary expression or be released after posting; the send/receive payload buffers must remain alive and obey the usual MPI completion rules. Legacy transfer counts must be nonnegative and at most ``huge(0_fmpi_integer)``: usually 2,147,483,647 elements. That is just under 2 GiB for byte payloads, or 16 GiB for eight-byte payloads. Counts measure elements, not bytes. Variable-collective displacements measure datatype extents and may be negative when the operation/buffer permits it; conversion uses the portable symmetric native integer range. Generated displacements and communication totals accumulate in ``fmpi_count`` before narrowing. Positive arithmetic products must remain representable in that kind; local allocation capacities independently obey ``f_size_t``. A conversion failure raises ``ERR_MPI_WRAPPERS``, returns false and zeros its output. It must be followed by a return before communicating. All checks are local integer comparisons: they perform no MPI calls and add no implicit fence, collective or synchronization, including before nonblocking payloads. A locally caught error does not notify other ranks and is not a collective recovery protocol. Applications must arrange consistent recovery before peers enter a payload collective, or use a fatal MPI-aware error handler. The wrapper does not make successful transfers synchronize to support invalid input. Zero-count reductions initialize an optional request to ``FMPI_REQUEST_NULL`` and leave buffers unchanged. MPI handles, ranks, requests and status remain native integers. RMA target displacements and window byte sizes remain ``fmpi_address``; file offsets remain ``fmpi_offset``. ``fmpi_count_to_address`` checks count-times-element-size before multiplying or narrowing a window size, without imposing the smaller legacy transfer-count limit on the window itself. No MPI-4 large-count backend or ``mpi_f08`` dependency is introduced. ASCII character diagnostics and gathers --------------------------------------- When ``fmpi_bcast`` is called with a character buffer and ``maxdiff``, it saves an explicit ASCII-code snapshot before broadcasting. The returned integer is the global maximum absolute ASCII-code difference from that snapshot, rather than a count of mismatched characters. Calls without ``maxdiff`` communicate the original characters without this conversion. Character-to-integer ``fmpi_gather`` overloads explicitly convert one character to one ASCII integer code before communicating. Both ``f_integer`` and ``f_long`` receive buffers are supported. These conversions do not use mixed ``f_memcpy`` dispatch. The existing private character ``mpimaxdiff_c1`` blueprint also uses explicit ASCII conversion; it remains outside the public generic. ``maxdiff_bcast_check`` exercises scalar strings, character arrays, embedded NUL/control characters, zero-length cases and gathers into both integer kinds, in addition to its numeric cases. It has been run with one, two and three MPI ranks. No non-ASCII processor was available; encoding portability is expressed by the IACHAR/ACHAR contract and by fixed ASCII expectations in the tests. Collective algorithm selection ------------------------------ ``fmpi_allgather`` and ``fmpi_alltoall`` accept ``AUTOMATIC_ENUM``, ``NOT_VARIABLE_ENUM``, ``VARIABLE_ENUM`` and ``ONESIDED_ENUM``. Unknown selector IDs raise ``ERR_MPI_WRAPPERS`` and return before communication. Initializing an MPI status to success is insufficient: an unsupported selector must not silently skip the transfer. For all-to-all, an explicitly fixed algorithm requires uniform count arguments; an explicitly variable or one-sided algorithm requires all four count and displacement vectors. A caught incompatibility or insufficient buffer capacity returns before payload communication. The receive buffer remains untouched and an optional request is ``FMPI_REQUEST_NULL``. Providing ``win`` selects the one-sided path as before; its ordinary buffer/metadata requirements still apply. Validation is local and does not add an MPI collective. Catching an error on one rank does not release peers already inside a collective; callers must arrange consistent recovery or use a fatal MPI-aware error handler. The active ``algorithms`` regression checks invalid selectors, both directions of incompatible all-to-all metadata, insufficient buffer capacity, preserved receive canaries and null requests, then verifies fixed and nonblocking variable all-to-all transfers. It is included in the default ``make check`` run:: mpirun -np 3 ./mpi_contracts_check algorithms .. fortranliteral:: tests/wrappers/mpi_contracts_check.f90 :marker: mpi_algorithm_contract Allgather source contract ------------------------- With ``recvbuf`` present, ``fmpi_allgather`` preserves ``sendbuf``; a read-only variable or expression is permitted. The receive storage must not overlap the source. Without ``recvbuf``, ``sendbuf`` is the writable full receive buffer. Its local contribution must already occupy the range described by the receive count and displacement. Source intent is therefore deliberately unspecified in the scalar and array overloads. Counts and displacements retain their MPI element/datatype-extent semantics; this contract introduces no extra synchronization.