Skip to content

Commit feca796

Browse files
authored
Merge pull request #70 from fverdugo/mpi_abort
Enhanced usage of MPI_abort
2 parents 7f02454 + 99762c9 commit feca796

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

src/MPIBackend.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,33 @@ function prun(driver::Function,b::MPIBackend,nparts)
2424
if !MPI.Initialized()
2525
MPI.Init()
2626
end
27-
try
28-
part = get_part_ids(b,nparts)
29-
driver(part)
30-
catch e
31-
@error "" exception=(e, catch_backtrace())
32-
if MPI.Initialized() && !MPI.Finalized()
33-
MPI.Abort(MPI.COMM_WORLD,0)
27+
if MPI.Comm_size(MPI.COMM_WORLD) == 1
28+
part = get_part_ids(b,nparts)
29+
driver(part)
30+
else
31+
try
32+
part = get_part_ids(b,nparts)
33+
driver(part)
34+
catch e
35+
@error "" exception=(e, catch_backtrace())
36+
if MPI.Initialized() && !MPI.Finalized()
37+
MPI.Abort(MPI.COMM_WORLD,1)
38+
end
3439
end
3540
end
3641
# We are NOT invoking MPI.Finalize() here because we rely on
3742
# MPI.jl, which registers MPI.Finalize() in atexit()
3843
end
3944

45+
#TODO not needed any more. Deprecate.
4046
# Useful to debug an MPI program when executed interactively
4147
# on the REPL, i.e., with a single MPI task
4248
function prun_debug(driver::Function,b::MPIBackend,nparts)
4349
if !MPI.Initialized()
4450
MPI.Init()
4551
end
4652
if (prod(nparts) != 1)
47-
MPI.Abort(MPI.COMM_WORLD,0)
53+
MPI.Abort(MPI.COMM_WORLD,1)
4854
end
4955
part = get_part_ids(b,nparts)
5056
driver(part)

test/mpi/ExceptionTests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
module ExceptionTests
2+
using Test
23

34
include("mpiexec.jl")
4-
run_mpi_driver(procs=8,file="driver_exception.jl")
5+
failed = Ref(false)
6+
try
7+
run_mpi_driver(procs=8,file="driver_exception.jl")
8+
catch e
9+
failed[] = true
10+
end
11+
@test failed[]
512

613
end # module

test/mpi/mpiexec.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ function run_mpi_driver(;procs,file)
1010
else
1111
run(`$cmd -n $procs $(Base.julia_cmd()) --project=$repodir $(joinpath(mpidir,file))`)
1212
end
13-
@test true
13+
# This line will be reached if and only if the command launched by `run` runs without errors.
14+
# Then, if we arrive here, the test has succeeded.
15+
@test true
1416
end
1517
end

test/test_exception.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ using PartitionedArrays
33

44
function throw_assert(parts)
55
nparts=length(parts)
6-
map_parts(parts) do part
7-
@assert rand(1:nparts) != part
6+
p_main = map_parts(parts) do part
7+
if part == MAIN
8+
part_fail = rand(1:nparts)
9+
else
10+
0
11+
end
12+
end
13+
p = emit(p_main)
14+
map_parts(parts,p) do part,part_fail
15+
@assert part_fail != part
816
end
917
end
1018

0 commit comments

Comments
 (0)