-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Per the request of @jeffhammond, I am recreating mpiwg-rma/rma-issues/issues/27 here. I initially reported this as an ambiguity in the MPI specification, but @jeffhammond had doubts about what the specification intends to require.
Greetings,
Problem
Recently, I was surprised1 by an error at MPI_Finalize
on Intel's MPI implementation (MPICH-based, I think) with the following code:
program test_window
!! Test whether MPI dies when a window is created but not freed before MPI_Finalize
use mpi_f08
use, intrinsic :: iso_fortran_env
use, intrinsic :: iso_c_binding
integer, dimension(10) :: window_array
integer :: myrank, numproc
type(MPI_Win) :: created_window
call MPI_Init()
call MPI_Comm_size(MPI_COMM_WORLD,numproc)
call MPI_Comm_Rank(MPI_COMM_WORLD,myrank)
write(0,'("Rank ",I0,"/",I0," initialized")') myrank+1, numproc
call MPI_Win_Create(window_array, int(10,kind=MPI_ADDRESS_KIND), &
1, MPI_INFO_NULL, MPI_COMM_WORLD, created_window)
write(0,'("Rank ",I0," created window")') myrank+1
call MPI_Finalize()
write(0,'(" Rank ",I0," finalized")') myrank+1
end program
The error was evidently mine, for not freeing the MPI_Win
object before the call to MPI_Finalize
. After some long discussion in the above-linked Intel thread, I've convinced myself that the specification does allow implementations to treat this as an error, making the call to MPI_Win_free
obligatory.
However, this requirement does not appear to be obvious. The language around MPI_Finalize
refers to completing communications, and my mental model of an MPI_Win
object was that it was more like a communicator object (which does not need to be explicitly freed) than a request (which must be completed).
Might a future version of the MPI specification highlight this requirement more explicitly?
Proposal
The MPI standard should be more explicit on the interaction between MPI Window objects and the MPI_Finalize
call. If an MPI Window object is "like a communicator," then it should be permissible to leave the window dangling (with further references invalid but not erroneous). If the window object is "like a file," then it should be closed/freed before the call to MPI_Finalize
.
Changes to the Text
Section 12 should include commentary on the intended lifetime of MPI Window objects. If they must be freed before calling MPI_Finalize
, then at minimum MPI_Win_free
should note this requirement.
Impact on Implementations
If calling MPI_Finalize
without MPI_Free
is left explicitly undefined, then no implementation should be required to change.
If the call is obligatory and not calling it is erroneous, it might require implementations that currently passively accept this (Open-MPI) to remark upon the error.
If the call is not obligatory, then other implementations (Intel MPI) that currently error must not.
Impact on Users
If freeing each MPI Window before MPI_Finalize
is obligatory, then users must keep track of the lifetime of window objects and not allow them to go out of scope. This might require introducing garbage collection semantics to otherwise linear codes.
My surprising discovery of this issue (re: Intel MPI) came about because the legacy code I'm working on implicitly assumes it can always exit-with-error by finishing any pending communications (always local to the function or procedure, not long-lived) and calling MPI_Finalize
. My own solution involved attaching a garbage-collection hook to MPI_COMM_SELF
.
Additionally, a new (or newly explicit) requirement to free windows might cause some perverse user problems to have performance problems at exit-time. The call to MPI_Win_free
is collective like a barrier, and user programs can only free one window at a time. If a program creates millions of windows over tens of thousands of processes, the required synchronization might add substantially to process-exit time even if the underlying implementation needs to do nothing to free a window.
References and Pull Requests
Footnotes
Metadata
Metadata
Assignees
Labels
Type
Projects
Status