Skip to content

Commit

Permalink
Throw more informative error if MPI.Init() is called multiple times (#…
Browse files Browse the repository at this point in the history
…310)

Fixes #309.
  • Loading branch information
simonbyrne authored Sep 24, 2019
1 parent 3c97558 commit edab8ef
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/environment.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const REFCOUNT = Threads.Atomic{Int}(1)
const REFCOUNT = Threads.Atomic{Int}(-1)

"""
refcount_inc()
Expand Down Expand Up @@ -34,7 +34,7 @@ end
Initialize MPI in the current process.
All MPI programs must contain exactly one call to `MPI.Init()`.
All MPI programs must contain exactly one call to `MPI.Init()`. In particular, note that it is not valid to call `MPI.Init` again after calling [`MPI.Finalize`](@ref).
The only MPI functions that may be called before `MPI.Init()` are
[`MPI.Initialized`](@ref) and [`MPI.Finalized`](@ref).
Expand All @@ -43,10 +43,9 @@ The only MPI functions that may be called before `MPI.Init()` are
$(_doc_external("MPI_Init"))
"""
function Init()
if REFCOUNT[] != 1
error("MPI REFCOUNT in incorrect state")
end
REFCOUNT[] == -1 || error("MPI.REFCOUNT in incorrect state: MPI may only be initialized once per session.")
@mpichk ccall((:MPI_Init, libmpi), Cint, (Ptr{Cint},Ptr{Cint}), C_NULL, C_NULL)
REFCOUNT[] = 1
atexit(refcount_dec)

for f in mpi_init_hooks
Expand Down

0 comments on commit edab8ef

Please sign in to comment.